dotfiles/script/ghco

24 lines
479 B
Bash
Executable File

#!/usr/bin/env bash
# Select and checkout a GitHub pull request using the GitHub CLI (required)
set -e
export GH_NO_UPDATE_NOTIFIER=1
unset BROWSER
if [ "$1" = '-a' ]; then
cmd='gh pr list --limit 100'
elif [ -z "$GITHUB_USERNAME" ]; then
# shellcheck disable=SC2016
echo 'set $GITHUB_USERNAME first'
exit 1
else
cmd="gh pr list --author $GITHUB_USERNAME"
fi
prid=$(eval "$cmd" | fzf | awk '{print $1}')
if [ -z "$prid" ]; then
exit 0
fi
gh pr checkout "$prid"