]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Initial git completion code
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 2 Aug 2013 21:46:42 +0000 (18:46 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 2 Aug 2013 21:46:42 +0000 (18:46 -0300)
lib/keyringer/completions/bash

index b25531248d70b519dda5ba488f40cf81525aa51e..0edfb1b6b63b72878fb021137e141d675746ff0e 100644 (file)
@@ -2,6 +2,25 @@
 # Keyringer bash completion
 #
 
+# Completion for git subcommand
+_keyringer_git_complete() {
+  if [ -e "/etc/bash_completion.d/git" ]; then
+    (
+      source /etc/bash_completion.d/git
+      cd $path
+      COMP_WORDS=(git $*)
+      COMP_CWORD=$((${#COMP_WORDS[*]} - 1))
+
+      if [ "$COMP_CWORD" == "0" ]; then
+        COMP_CWORD=1
+      fi
+
+      _git
+      echo ${COMPREPLY[@]}
+    )
+  fi
+}
+
 _keyringer() {
   # Standard stuff
   local cur prev opts config
@@ -42,7 +61,7 @@ _keyringer() {
         opts="gpg ssh ssl ssl-self"
         ;;
       git)
-        # TODO: This depends on git's bash completion
+        opts="$(_keyringer_git_complete ${cur})"
         ;;
       *)
         ;;
@@ -56,13 +75,14 @@ _keyringer() {
         opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)"
         ;;
       git)
-        # TODO: This depends on git's bash completion
+        # TODO
+        opts="$(_keyringer_git_complete ${prev} ${cur})"
         ;;
       *)
         ;;
     esac
   elif [ "${command}" == "git" ]; then
-    # TODO: This depends on git's bash completion
+    # TODO
     true
   fi