Skip to content

Instantly share code, notes, and snippets.

@ikhoon
Last active October 7, 2019 02:05
Show Gist options
  • Select an option

  • Save ikhoon/4e2818033af1069f225df8805f79b94a to your computer and use it in GitHub Desktop.

Select an option

Save ikhoon/4e2818033af1069f225df8805f79b94a to your computer and use it in GitHub Desktop.
git checkout remote pull request to local branch and track it with FZF-TMUX
# git checkout remote pull request to local branch and track it with FZF-TMUX
# Requirements:
# - hub : https://github.com/github/hub
# - fzf-tmux : https://github.com/junegunn/fzf#fzf-tmux-script
pr() {
local pr_list pr_id origin branch_name
pr_list=$(cat /dev/null | hub pr list -f "%pC%>(8)%i%Creset %t @%au %l%n")
result=$?
if [[ $pr_list == *"github.com username:"* ]]; then
echo "Please run 'hub pr list' to login GitHub"
return
fi
if [ $result -ne 0 ]; then
return
fi
pr_id=$(
echo $pr_list |
fzf-tmux -d 15 --no-hscroll |
sed 's/[^#]*#\([^ ]*\).*/\1/') || return
branch_name=pr.$pr_id
# check the branch exists
if [ $(git branch | grep $branch_name | wc -l) -eq 1 ]; then
git checkout $branch_name
else
origin='origin'
if git remote | grep -qE '^upstream$'; then
origin='upstream'
fi
[[ "$pr_id" =~ ^[0-9]+$ ]] && hub pr checkout $pr_id $branch_name
fi
}
@ikhoon
Copy link
Author

ikhoon commented Oct 7, 2019

스샷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment