]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Initial bash completion code (#2)
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 11 Jul 2013 20:32:29 +0000 (17:32 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 11 Jul 2013 20:32:29 +0000 (17:32 -0300)
lib/keyringer/completions/bash [new file with mode: 0644]

diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash
new file mode 100644 (file)
index 0000000..6de93bb
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# Keyringer bash completion
+#
+
+_keyringer() {
+  local cur prev opts
+  COMPREPLY=()
+  cur="${COMP_WORDS[COMP_CWORD]}"
+  prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+  # Initial options
+  opts="`ls $HOME/.keyringer | sed -e 's/config//'`"
+
+  # Available keyrings
+  keyrings="`echo $opts | sed -e 's/ /|/'`"
+
+  # The current keyring
+  keyring="${COMP_WORDS[1]}"
+
+  # Command completions
+  if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$keyrings]"; then
+    opts="`keyringer $keyring commands`"
+  else
+    case "${prev}" in
+      ls)
+        opts="`keyringer $keyring ls ${cur}`"
+        ;;
+      *)
+        ;;
+    esac
+  fi
+
+  # Return the available options
+  COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+  return 0
+}
+
+complete -F _keyringer keyringer