From ef9248648a78440bbb14fd9fe35fe451a540352c Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 10 Aug 2016 23:19:53 +0300 Subject: [PATCH] .shellrc: refactor cdremote and git-open completion _cdremote_complete and _git_open are mostly the same - refactor common code. --- .shellrc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 -- 2.39.5