From: Oleg Broytman Date: Wed, 10 Aug 2016 20:19:53 +0000 (+0300) Subject: .shellrc: refactor cdremote and git-open completion X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=ef9248648a78440bbb14fd9fe35fe451a540352c;p=dotfiles.git .shellrc: refactor cdremote and git-open completion _cdremote_complete and _git_open are mostly the same - refactor common code. --- diff --git a/.shellrc b/.shellrc index 247a779..9cee283 100644 --- a/.shellrc +++ b/.shellrc @@ -223,22 +223,24 @@ if test -x /usr/bin/git >/dev/null 2>&1; then done } - # completion for cdremote - list remotes with directories as URLs - _cdremote_complete() { + # completion for cdremote and git-open - list remotes with a pattern + _list_remotes_completion() { local cur="${COMP_WORDS[COMP_CWORD]}"; - _list_remotes '^\(/\|\.\./\)' # (/ or ../ at the beginning) + _list_remotes "$1" COMPREPLY=(`compgen -W "$GIT_REMOTES" -- "$cur"`) unset GIT_REMOTES } + # completion for cdremote - list remotes with directories as URLs + _cdremote_complete() { + _list_remotes_completion '^\(/\|\.\./\)' # (/ or ../ at the beginning) + } + complete -F _cdremote_complete cdremote # completion for git-open - list remotes with http(s) URLs _git_open() { - local cur="${COMP_WORDS[COMP_CWORD]}"; - _list_remotes '^http\(s\)\?://' - COMPREPLY=(`compgen -W "$GIT_REMOTES" -- "$cur"`) - unset GIT_REMOTES + _list_remotes_completion '^http\(s\)\?://' } complete -F _git_open git-open