]> git.phdru.name Git - dotfiles.git/commitdiff
.shellrc: refactor cdremote and git-open completion
authorOleg Broytman <phd@phdru.name>
Wed, 10 Aug 2016 20:19:53 +0000 (23:19 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 10 Aug 2016 20:19:53 +0000 (23:19 +0300)
_cdremote_complete and _git_open are mostly the same -
refactor common code.

.shellrc

index 247a779b6bd35ddcec1ad1f4e83cde7ac2672dbf..9cee28309e4200258628c5406fc220bb11b4eac5 100644 (file)
--- 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