feat(completions/hub): apply upstream changes

This commit is contained in:
Koichi Murase 2024-08-15 22:14:45 +09:00
parent 52987b3d35
commit 47eeec81ab
2 changed files with 38 additions and 10 deletions

View File

@ -1,4 +1,8 @@
#! bash oh-my-bash.module
#
# The current version is based on the following upstream version:
# https://github.com/owenthereal/gh/blob/04a7985fa9a1c1d4d63738f4edb7b07d228bdb12/etc/gh.bash_completion.sh
#------------------------------------------------------------------------------
# hub tab-completion script for bash.
# This script complements the completion script that ships with git.

View File

@ -1,4 +1,8 @@
#! bash oh-my-bash.module
#
# The current version is based on the following upstream version:
# https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/etc/hub.bash_completion.sh
#------------------------------------------------------------------------------
# hub tab-completion script for bash.
# This script complements the completion script that ships with git.
@ -7,8 +11,8 @@ if ! _omb_util_function_exists _git && _omb_util_function_exists _completion_loa
_completion_loader git
fi
# Check that git tab completion is available
if _omb_util_function_exists _git; then
# Check that git tab completion is available and we haven't already set up completion
if _omb_util_function_exists _git && ! _omb_util_function_exists __git_list_all_commands_without_hub ; then
# Duplicate and rename the 'list_all_commands' function
eval "$(declare -f __git_list_all_commands | \
sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')"
@ -18,11 +22,16 @@ if _omb_util_function_exists _git; then
cat <<-EOF
alias
pull-request
pr
issue
release
fork
create
delete
browse
compare
ci-status
sync
EOF
__git_list_all_commands_without_hub
}
@ -115,7 +124,7 @@ EOF
# revision. For example:
# $ hub compare -u upstream
# > https://github.com/USER/REPO/compare/upstream
if __hub_github_repos '\p' | grep -Eqx "^$i(/[^/]+)?"; then
if __hub_github_repos '\p' | command grep -Eqx "^$i(/[^/]+)?"; then
arg_repo=$i
else
rev=$i
@ -214,21 +223,36 @@ EOF
esac
}
# hub fork [--no-remote]
# hub fork [--no-remote] [--remote-name REMOTE] [--org ORGANIZATION]
function _git_fork {
local i c=2 remote=yes
local i c=2 flags="--no-remote --remote-name --org"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
--org)
((c++))
flags=${flags/$i/}
;;
--remote-name)
((c++))
flags=${flags/$i/}
flags=${flags/--no-remote/}
;;
--no-remote)
unset remote
flags=${flags/$i/}
flags=${flags/--remote-name/}
;;
esac
((c++))
done
if [ -n "$remote" ]; then
__gitcomp "--no-remote"
fi
case "$prev" in
--remote-name|--org)
COMPREPLY=()
;;
*)
__gitcomp "$flags"
;;
esac
}
# hub pull-request [-f] [-m <MESSAGE>|-F <FILE>|-i <ISSUE>|<ISSUE-URL>] [-b <BASE>] [-h <HEAD>] [-a <USER>] [-M <MILESTONE>] [-l <LABELS>]
@ -325,7 +349,7 @@ EOF
format=${format//\o/\3}
fi
_omb_prompt_git config --get-regexp 'remote\.[^.]*\.url' |
grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' |
command grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' |
sed -E 's#^remote\.([^.]+)\.url +.+[:/](([^/]+)/[^.]+)(\.git)?$#'"$format"'#'
}