Add git-pr-review command for easy local pr reviewing

main
Ensar Sarajčić 2022-05-09 11:01:42 +02:00
parent f07a720a72
commit d3c792f613
3 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,40 @@
#!/bin/sh
set -e
if [ -z "$1" ]; then
echo "Missing origin branch. Pass in the branch to compare as the first parameter!"
exit 1
fi
ORIGIN_BRANCH="$1"
if [ "${1}" = "${1#origin/}" ]; then
read -p "Origin branch does not seem to be from the 'origin/' remote. Proceed? [y/n]" ANSWER
if [ ! "$ANSWER" = "y" ]; then
exit 2
fi
fi
TARGET_BRANCH="$2"
if [ -z "$2" ]; then
TARGET_BRANCH="origin/main"
echo "Missing target branch. Assuming $TARGET_BRANCH!"
fi
if [ "${TARGET_BRANCH}" = "${TARGET_BRANCH#origin/}" ]; then
read -p "Target branch does not seem to be from the 'origin/' remote. Proceed? [y/n]" ANSWER
if [ ! "$ANSWER" = "y" ]; then
exit 2
fi
fi
if [ ! "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
echo "Not inside a git repository."
exit 128
fi
echo "Updating origin..."
git fetch
git checkout $ORIGIN_BRANCH
echo "You are now checked out to the PR branch. Feel free to build the project and test it out."
git difftool $TARGET_BRANCH

View File

@ -0,0 +1,13 @@
set -l needs_fetch 1
function __fish-git-pr-review-fetch
git fetch &
set -l needs_fetch 0
return 1
end
function __fish-git-pr-review-in-git-repo
git rev-parse --is-inside-work-tree 2>/dev/null
end
complete -c git-pr-review -f
complete -c git-pr-review -n '__fish-git-pr-review-in-git-repo; and __fish-git-pr-review-fetch' -w 'git branch'

View File

@ -0,0 +1,31 @@
set -l commands status link install uninstall
function __fish-lsp-available-servers
lsp status --all | grep 'Server.*:' | awk '{print $2}' | sed 's/[:,]//g' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"
end
function __fish-lsp-installed-servers
lsp status | grep 'Server.*:' | awk '{print $2}' | sed 's/[:,]//g' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"
end
complete -c lsp -x -l help -s h -d "print usage help"
complete -c lsp -x -l verbose -s v -d "verbose output"
complete -c lsp -x -n "__fish_use_subcommand" -a status -d "status of installed servers"
complete -c lsp -x -n "__fish_use_subcommand" -a link -d "link installed server to location in PATH (~/.local/bin)"
complete -c lsp -x -n "__fish_use_subcommand" -a install -d "install a new server"
complete -c lsp -x -n "__fish_use_subcommand" -a uninstall -d "uninstall an installed server"
# Install
complete -c lsp -x -n "__fish_seen_subcommand_from install" -l link -s l -d "link server after installation"
complete -c lsp -x -n "__fish_seen_subcommand_from install" -a '(__fish-lsp-available-servers)'
# Link
complete -c lsp -x -n "__fish_seen_subcommand_from link" -a '(__fish-lsp-installed-servers)'
# Uninstall
complete -c lsp -x -n "__fish_seen_subcommand_from uninstall" -a '(__fish-lsp-installed-servers)'
# Status
complete -c lsp -x -n "__fish_seen_subcommand_from status" -l known-only -s k -d "show only known servers"
complete -c lsp -x -n "__fish_seen_subcommand_from status" -l all -s a -d "show all supported servers"
complete -c lsp -x -n "__fish_seen_subcommand_from status" -a '(__fish-lsp-available-servers)'