From f348c88f07380747149265f319c3c3a97bd4a047 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 21 Aug 2012 14:12:50 -0300 Subject: Initialization fixes --- lib/keyringer/functions | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 6ac8bf8..dc1ce0f 100644 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -340,6 +340,10 @@ function keyringer_action_usage { # Check recipients function keyringer_check_recipients { + if [ "$KEYRINGER_CHECK_RECIPIENTS" == "false" ]; then + return + fi + # Check if recipients file is empty. if [ "`grep -vE "^#|^$" "$RECIPIENTS"/* | wc -l`" == 0 ] && [ "$SUBCOMMAND" != "edit" ]; then echo "Fatal: no recipients configured for this keyring." -- cgit v1.2.3 From b86bc23482b24292a17364b2d23143d4d7b58c89 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 4 Sep 2012 16:47:58 -0300 Subject: Using a more user-friendly message on recipient fingerprint error --- lib/keyringer/functions | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index dc1ce0f..9fea828 100644 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -368,15 +368,19 @@ function keyringer_check_recipients { echo "Fatal: please set the full GPG signature hash for key ID $recipient:" cat <<-EOF -Recipients file can't have 32-bit keyids (e.g. DEADBEEF or DECAF123). These -are trivial to spoof. With a few gigs of disk space and a day of time on -cheap, readily-available hardware, it's possible to build keys to match every -possible 32-bit keyid. The search space just isn't big enough. - -If you're going to specify keys by keyid, they should be specified by full -160-bit OpenPGP fingerprint. It would be very bad if someone spoofed a keyID -and caused another participant in a keyringer instance to reencrypt a secret -store to the spoofed key in addition to your own. +Please provide a full OpenPGP fingerprint, for example: + + john@doe.com ABCD1234ABCD12345678ABCD1234ABCD12345678 + +Short key ids (for example, DEADBEEF or DECAF123) are not allowed in +recipient files because they are easy to spoof. Researchers have proven +that it is possible to build fake keys to match any possible short key +id by using a few gigabytes of disk space, and a day of computation on +common hardware. + +Otherwise, the encryption can be broken, if someone spoofs a short key +id, and causes a participant in a keyringer repository to encrypt +secrets to a fake key. EOF exit 1 else -- cgit v1.2.3 From bbed3216708d64ec475481c008d868d2c10468f1 Mon Sep 17 00:00:00 2001 From: ricola Date: Fri, 19 Oct 2012 23:34:53 +0200 Subject: Load preferences for actions as well --- lib/keyringer/functions | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 9fea828..129ec0e 100644 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -454,5 +454,6 @@ function keyringer_create_new_recipients { # Setup environment if [ "$(basename "$0")" != "keyringer" ]; then + keyringer_config_load_preferences keyringer_set_env $* fi -- cgit v1.2.3 From 67adc630f06c7779937a410f1d5925ad51f6e017 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 26 Feb 2013 12:32:05 -0300 Subject: Check return status (closes #7) --- lib/keyringer/functions | 4 ++++ share/keyringer/append | 6 ++++++ share/keyringer/encrypt | 8 ++++++++ 3 files changed, 18 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 129ec0e..1d29157 100644 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -74,6 +74,10 @@ function keyringer_exec { # Dispatch if keyringer_has_action "$action"; then "$ACTIONS/$action" "$basedir" $* + err="$?" + if [ "$err" != "0" ]; then + exit "$err" + fi fi } diff --git a/share/keyringer/append b/share/keyringer/append index 045ba86..bcc9e5e 100755 --- a/share/keyringer/append +++ b/share/keyringer/append @@ -32,4 +32,10 @@ for element in $(seq 0 $((${#NEW[@]} - 1))); do echo ${NEW[$element]} done | keyringer_exec encrypt-batch $BASEDIR $FILE +err="$?" + +if [ "$err" != "0" ]; then + exit "$err" +fi + IFS="$OLDIFS" diff --git a/share/keyringer/encrypt b/share/keyringer/encrypt index da0941f..3680d0b 100755 --- a/share/keyringer/encrypt +++ b/share/keyringer/encrypt @@ -23,7 +23,15 @@ fi $GPG --use-agent --armor -e -s $(keyringer_recipients "$RECIPIENTS_FILE") - > "$KEYDIR/$FILE" +err="$?" + +if [ "$err" != "0" ]; then + exit "$err" +fi + # Stage if [ -d "$BASEDIR/.git" ]; then keyringer_exec git "$BASEDIR" add "keys/$FILE" fi + +exit "$?" -- cgit v1.2.3 From 8da5023df4b4e3ec55bf52b4377920a8ece941e2 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 11 Jul 2013 16:44:20 -0300 Subject: Better usage handling --- keyringer | 4 +--- lib/keyringer/functions | 12 ++++++++++++ share/keyringer/commands | 10 ++++++++++ share/keyringer/usage | 12 ++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100755 share/keyringer/commands create mode 100755 share/keyringer/usage (limited to 'lib') diff --git a/keyringer b/keyringer index 0f6372c..934f600 100755 --- a/keyringer +++ b/keyringer @@ -141,9 +141,7 @@ source "$LIB" || exit 1 keyringer_config_load if [ -z "$ACTION" ]; then - printf "Usage: %s [arguments]\n" "$BASENAME" - printf "Available commands: \n" - ls $ACTIONS | sed -e 's/^/\t/' + keyringer_usage exit 1 fi diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 1d29157..3fa7170 100644 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -342,6 +342,18 @@ function keyringer_action_usage { fi } +# Return available actions +function keyringer_show_actions { + ls $ACTIONS +} + +# Usage +function keyringer_usage { + printf "Usage: %s [arguments]\n" "$BASENAME" + printf "Available commands: \n" + keyringer_show_actions | sed -e 's/^/\t/' +} + # Check recipients function keyringer_check_recipients { if [ "$KEYRINGER_CHECK_RECIPIENTS" == "false" ]; then diff --git a/share/keyringer/commands b/share/keyringer/commands new file mode 100755 index 0000000..139725a --- /dev/null +++ b/share/keyringer/commands @@ -0,0 +1,10 @@ +#!/bin/bash +# +# Show available commands +# + +# Load functions +LIB="`dirname $0`/../../lib/keyringer/functions" +source "$LIB" || exit 1 + +keyringer_show_actions diff --git a/share/keyringer/usage b/share/keyringer/usage new file mode 100755 index 0000000..54cbea6 --- /dev/null +++ b/share/keyringer/usage @@ -0,0 +1,12 @@ +#!/bin/bash +# +# Show available commands +# + +# Load functions +LIB="`dirname $0`/../../lib/keyringer/functions" +source "$LIB" || exit 1 + +printf "Usage: %s [arguments]\n" "$BASENAME" +printf "Available commands: \n" +ls $ACTIONS | sed -e 's/^/\t/' -- cgit v1.2.3 From e6e48ab8138d8d91943fda4485203a0ebaf25eef Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 11 Jul 2013 17:32:29 -0300 Subject: Initial bash completion code (#2) --- lib/keyringer/completions/bash | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/keyringer/completions/bash (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash new file mode 100644 index 0000000..6de93bb --- /dev/null +++ b/lib/keyringer/completions/bash @@ -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 -- cgit v1.2.3 From 1046b1ebcb3bf0841636d2215faf95ddf1895b47 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 12 Jul 2013 23:56:40 -0300 Subject: More on completion --- lib/keyringer/completions/bash | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 6de93bb..2d6fd29 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -3,27 +3,39 @@ # _keyringer() { - local cur prev opts + # Standard stuff + local cur prev opts config COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" # Initial options - opts="`ls $HOME/.keyringer | sed -e 's/config//'`" + config="$HOME/.keyringer" + opts="`ls $config | sed -e 's/config//'`" - # Available keyrings - keyrings="`echo $opts | sed -e 's/ /|/'`" + # Available instances + instances="`echo $opts | sed -e 's/ /|/'`" - # The current keyring - keyring="${COMP_WORDS[1]}" + # The current instance + instance="${COMP_WORDS[1]}" # Command completions - if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$keyrings]"; then - opts="`keyringer $keyring commands`" - else + if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then + opts="`keyringer $instance commands`" + elif [ "${#COMP_WORDS[@]}" == "4" ]; then + # Process config + source $config/config + case "${prev}" in + options|preferences) + opts="ls edit add" + ;; + recipients) + opts="ls edit" + ;; ls) - opts="`keyringer $keyring ls ${cur}`" + # TODO + opts="`keyringer $instance ls ${cur}`" ;; *) ;; -- cgit v1.2.3 From 267afb70ae6c7d2fcdd6897a18781bb7137f14e7 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 14:15:04 -0300 Subject: Minor enhancement on ls completion --- lib/keyringer/completions/bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 2d6fd29..891b57a 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -25,6 +25,7 @@ _keyringer() { elif [ "${#COMP_WORDS[@]}" == "4" ]; then # Process config source $config/config + path="`eval echo '$'$instance`" case "${prev}" in options|preferences) @@ -35,7 +36,11 @@ _keyringer() { ;; ls) # TODO - opts="`keyringer $instance ls ${cur}`" + if [ -z "${curl}" ]; then + opts="`keyringer $instance ls`" + else + opts="`keyringer $instance ls ${cur}*`" + fi ;; *) ;; -- cgit v1.2.3 From 2301bcf57f803247e0fa9ea7fcc7c0918b355c23 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 14:34:31 -0300 Subject: Minor enhancement on ls completion (2) --- lib/keyringer/completions/bash | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 891b57a..403bb11 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -36,10 +36,13 @@ _keyringer() { ;; ls) # TODO - if [ -z "${curl}" ]; then - opts="`keyringer $instance ls`" + if [ -z "${cur}" ]; then + # List folders with leading slash and remove @ symlink indicator + #opts="`ls --file-type -1 $path/keys | sed -e 's/@$//'`" + opts="`keyringer $instance ls --file-type -1 | sed -e 's/@$//'`" else - opts="`keyringer $instance ls ${cur}*`" + #opts="`ls --file-type -1 -d $path/keys/${cur}* | sed -e 's/@$//'`" + opts="`keyringer $instance ls --file-type -1 -d ${cur}* | sed -e 's/@$//'`" fi ;; *) -- cgit v1.2.3 From d92f6ba94a7012e42b71b675f146efc14a86482a Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 14:35:41 -0300 Subject: Cleaning up ls completion --- lib/keyringer/completions/bash | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 403bb11..dd8b8e9 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -37,12 +37,9 @@ _keyringer() { ls) # TODO if [ -z "${cur}" ]; then - # List folders with leading slash and remove @ symlink indicator - #opts="`ls --file-type -1 $path/keys | sed -e 's/@$//'`" - opts="`keyringer $instance ls --file-type -1 | sed -e 's/@$//'`" + opts="`keyringer $instance ls -p`" else - #opts="`ls --file-type -1 -d $path/keys/${cur}* | sed -e 's/@$//'`" - opts="`keyringer $instance ls --file-type -1 -d ${cur}* | sed -e 's/@$//'`" + opts="`keyringer $instance ls -p -d ${cur}*`" fi ;; *) -- cgit v1.2.3 From 63a75e777b08d8001234055a016f4782b42a3067 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 14:55:35 -0300 Subject: Appending sub folders on completion --- lib/keyringer/completions/bash | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index dd8b8e9..5b2f71d 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -39,7 +39,17 @@ _keyringer() { if [ -z "${cur}" ]; then opts="`keyringer $instance ls -p`" else - opts="`keyringer $instance ls -p -d ${cur}*`" + local append + opts="`keyringer $instance ls -p -d ${cur}* 2> /dev/null`" + + # Append the contents of each folder, one level down + for opt in $opts; do + if echo $opt | grep -qe '/$'; then + append="$append `keyringer $instance ls -d $opt* 2> /dev/null`" + fi + done + + #opts="$opts $append" fi ;; *) -- cgit v1.2.3 From 23b602d41b1d34af87ea790c9e97cb67442e129c Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 14:59:24 -0300 Subject: Cleaning up ls completion --- lib/keyringer/completions/bash | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 5b2f71d..c91a8ef 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -41,15 +41,6 @@ _keyringer() { else local append opts="`keyringer $instance ls -p -d ${cur}* 2> /dev/null`" - - # Append the contents of each folder, one level down - for opt in $opts; do - if echo $opt | grep -qe '/$'; then - append="$append `keyringer $instance ls -d $opt* 2> /dev/null`" - fi - done - - #opts="$opts $append" fi ;; *) @@ -59,6 +50,7 @@ _keyringer() { # Return the available options COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + [[ $COMPREPLY == */ ]] && compopt -o nospace return 0 } -- cgit v1.2.3 From 1c3eb4f63525dcfae0e1861d3df0196f06ef9638 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 16:15:33 -0300 Subject: Turn off pathname expansion so expansion can work properly --- keyringer | 3 +++ lib/keyringer/completions/bash | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/keyringer b/keyringer index 934f600..a2ca1f4 100755 --- a/keyringer +++ b/keyringer @@ -112,6 +112,9 @@ BASENAME="`basename $0`" KEYRING="$1" ACTION="$2" +# Turn off pathname expansion so expansion can work properly +set -f + # Export preferences and version for other scripts export PREFERENCES="`dirname $CONFIG`/$KEYRING" export KEYRINGER_VERSION diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index c91a8ef..f962c6a 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -35,12 +35,10 @@ _keyringer() { opts="ls edit" ;; ls) - # TODO if [ -z "${cur}" ]; then opts="`keyringer $instance ls -p`" else - local append - opts="`keyringer $instance ls -p -d ${cur}* 2> /dev/null`" + opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*")" fi ;; *) -- cgit v1.2.3 From d0be9cff42cbc572fd5965f57e1c4cb6fc243435 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 16:19:13 -0300 Subject: More ls completion cleanup --- lib/keyringer/completions/bash | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index f962c6a..961e1d0 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -35,11 +35,7 @@ _keyringer() { opts="ls edit" ;; ls) - if [ -z "${cur}" ]; then - opts="`keyringer $instance ls -p`" - else - opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*")" - fi + opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; *) ;; -- cgit v1.2.3 From daab958980be4c8cdd1dd2434ba2e45c118989a7 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 16:29:11 -0300 Subject: Completion: avoid annoying bell and extra tab --- lib/keyringer/completions/bash | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 961e1d0..675364e 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -42,6 +42,9 @@ _keyringer() { esac fi + # Avoid annoying bell and extra tab + bind 'set show-all-if-ambiguous on' + # Return the available options COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) [[ $COMPREPLY == */ ]] && compopt -o nospace -- cgit v1.2.3 From f46c0aad2a09362f43312513f77ac4a3c46ffaf8 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 16:42:42 -0300 Subject: Adding completion other encrypt/decrypt/append/edit commands --- lib/keyringer/completions/bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 675364e..a46eaf3 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -34,7 +34,7 @@ _keyringer() { recipients) opts="ls edit" ;; - ls) + ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch) opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; *) -- cgit v1.2.3 From d00afece64d419f904a0f81f7563d446df462a92 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 16:43:45 -0300 Subject: Adding del completion --- lib/keyringer/completions/bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index a46eaf3..a9d7676 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -34,7 +34,7 @@ _keyringer() { recipients) opts="ls edit" ;; - ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch) + ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del) opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; *) -- cgit v1.2.3 From 2aef3d4c8c163a59c67855d88f31d2d723945745 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 16:44:10 -0300 Subject: Adding recrypt completion --- lib/keyringer/completions/bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index a9d7676..03907d4 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -34,7 +34,7 @@ _keyringer() { recipients) opts="ls edit" ;; - ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del) + ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|recrypt) opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; *) -- cgit v1.2.3 From bd51bff19679805a3b5ed6ae8185cd3ee98a0c0f Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 16:47:34 -0300 Subject: Adding initial completion for genpair --- lib/keyringer/completions/bash | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 03907d4..74c5812 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -37,6 +37,9 @@ _keyringer() { ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|recrypt) opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; + genpair) + opts="gpg ssh ssl ssl-self" + ;; *) ;; esac -- cgit v1.2.3 From 441132430b4b45030b0a01603c6a1d3b16122b06 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 16:47:44 -0300 Subject: Completion cleanup --- lib/keyringer/completions/bash | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 74c5812..5c56d47 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -23,10 +23,6 @@ _keyringer() { if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then opts="`keyringer $instance commands`" elif [ "${#COMP_WORDS[@]}" == "4" ]; then - # Process config - source $config/config - path="`eval echo '$'$instance`" - case "${prev}" in options|preferences) opts="ls edit add" -- cgit v1.2.3 From 5e6cad5498cb03a4844ef4e65fba49f1ce3439e1 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Jul 2013 18:11:23 -0300 Subject: More on bash completion --- lib/keyringer/completions/bash | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 5c56d47..b255312 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -8,11 +8,16 @@ _keyringer() { COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" + command="${COMP_WORDS[2]}" # Initial options config="$HOME/.keyringer" opts="`ls $config | sed -e 's/config//'`" + # Process config + source $config/config + path="`eval echo '$'$instance`" + # Available instances instances="`echo $opts | sed -e 's/ /|/'`" @@ -36,9 +41,29 @@ _keyringer() { genpair) opts="gpg ssh ssl ssl-self" ;; + git) + # TODO: This depends on git's bash completion + ;; + *) + ;; + esac + elif [ "${#COMP_WORDS[@]}" == "5" ]; then + case "${command}" in + recipients) + opts="$(cd $path/config/recipients && ls -p ${cur}* 2> /dev/null)" + ;; + genpair) + opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" + ;; + git) + # TODO: This depends on git's bash completion + ;; *) ;; esac + elif [ "${command}" == "git" ]; then + # TODO: This depends on git's bash completion + true fi # Avoid annoying bell and extra tab -- cgit v1.2.3 From cfd43d8dcf3a50ce4855cc0d88dc3244120d3a3e Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 2 Aug 2013 18:46:42 -0300 Subject: Initial git completion code --- lib/keyringer/completions/bash | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index b255312..0edfb1b 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -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 -- cgit v1.2.3 From 4cfb40c605a6df4bf70bc14e2010ad78e4276324 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 2 Aug 2013 18:49:37 -0300 Subject: Fixing initial options on bash completion --- lib/keyringer/completions/bash | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 0edfb1b..3c08293 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -31,20 +31,22 @@ _keyringer() { # Initial options config="$HOME/.keyringer" - opts="`ls $config | sed -e 's/config//'`" + keyrings="`ls $config | sed -e 's/config//'`" # Process config source $config/config path="`eval echo '$'$instance`" # Available instances - instances="`echo $opts | sed -e 's/ /|/'`" + instances="`echo $keyrings | sed -e 's/ /|/'`" # The current instance instance="${COMP_WORDS[1]}" # Command completions - if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then + if [ "${#COMP_WORDS[@]}" == "2" ]; then + opts="$keyrings" + elif [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then opts="`keyringer $instance commands`" elif [ "${#COMP_WORDS[@]}" == "4" ]; then case "${prev}" in -- cgit v1.2.3 From dbad98bef1d7bd9d0178a481ededaa86be7176e4 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 2 Aug 2013 18:58:30 -0300 Subject: More git completion code --- lib/keyringer/completions/bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 3c08293..247b7ff 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -85,7 +85,7 @@ _keyringer() { esac elif [ "${command}" == "git" ]; then # TODO - true + opts="$(_keyringer_git_complete ${COMP_WORDS[@]:3})" fi # Avoid annoying bell and extra tab -- cgit v1.2.3 From 3cf730cd3301b476ef256a88db83b8025b03ded5 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 2 Aug 2013 19:09:13 -0300 Subject: Avoiding duplication on git completion --- lib/keyringer/completions/bash | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index 247b7ff..a8fce92 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -16,6 +16,14 @@ _keyringer_git_complete() { fi _git + + LAST=${COMP_WORDS[COMP_CWORD]} + REPLY=${COMPREPLY[@]} + + if [ "$REPLY" == "$LAST" ]; then + return + fi + echo ${COMPREPLY[@]} ) fi -- cgit v1.2.3 From 08ffd87bc84928ef5ca0792175323d441145f5ce Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 16 Aug 2013 21:45:26 -0300 Subject: Initial code to make zsh-compatible completion --- lib/keyringer/completions/bash | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash index a8fce92..4459b34 100644 --- a/lib/keyringer/completions/bash +++ b/lib/keyringer/completions/bash @@ -1,7 +1,12 @@ +#!bash # # Keyringer bash completion # +if [[ -n ${ZSH_VERSION-} ]]; then + autoload -U +X bashcompinit && bashcompinit +fi + # Completion for git subcommand _keyringer_git_complete() { if [ -e "/etc/bash_completion.d/git" ]; then @@ -97,11 +102,17 @@ _keyringer() { fi # Avoid annoying bell and extra tab - bind 'set show-all-if-ambiguous on' + if [ -z "$ZSH_VERSION" ]; then + bind 'set show-all-if-ambiguous on' + fi # Return the available options COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - [[ $COMPREPLY == */ ]] && compopt -o nospace + + if [ -z "$ZSH_VERSION" ]; then + [[ $COMPREPLY == */ ]] && compopt -o nospace + fi + return 0 } -- cgit v1.2.3 From 26dbb6af9ebf1d55b1543ff4db86f83f2a59307d Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 16 Aug 2013 22:42:46 -0300 Subject: Initial zsh completion --- lib/keyringer/completions/bash | 119 ------------------------------- lib/keyringer/completions/bash/keyringer | 119 +++++++++++++++++++++++++++++++ lib/keyringer/completions/zsh/_keyringer | 30 ++++++++ 3 files changed, 149 insertions(+), 119 deletions(-) delete mode 100644 lib/keyringer/completions/bash create mode 100644 lib/keyringer/completions/bash/keyringer create mode 100644 lib/keyringer/completions/zsh/_keyringer (limited to 'lib') diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash deleted file mode 100644 index 4459b34..0000000 --- a/lib/keyringer/completions/bash +++ /dev/null @@ -1,119 +0,0 @@ -#!bash -# -# Keyringer bash completion -# - -if [[ -n ${ZSH_VERSION-} ]]; then - autoload -U +X bashcompinit && bashcompinit -fi - -# 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 - - LAST=${COMP_WORDS[COMP_CWORD]} - REPLY=${COMPREPLY[@]} - - if [ "$REPLY" == "$LAST" ]; then - return - fi - - echo ${COMPREPLY[@]} - ) - fi -} - -_keyringer() { - # Standard stuff - local cur prev opts config - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - command="${COMP_WORDS[2]}" - - # Initial options - config="$HOME/.keyringer" - keyrings="`ls $config | sed -e 's/config//'`" - - # Process config - source $config/config - path="`eval echo '$'$instance`" - - # Available instances - instances="`echo $keyrings | sed -e 's/ /|/'`" - - # The current instance - instance="${COMP_WORDS[1]}" - - # Command completions - if [ "${#COMP_WORDS[@]}" == "2" ]; then - opts="$keyrings" - elif [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then - opts="`keyringer $instance commands`" - elif [ "${#COMP_WORDS[@]}" == "4" ]; then - case "${prev}" in - options|preferences) - opts="ls edit add" - ;; - recipients) - opts="ls edit" - ;; - ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|recrypt) - opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" - ;; - genpair) - opts="gpg ssh ssl ssl-self" - ;; - git) - opts="$(_keyringer_git_complete ${cur})" - ;; - *) - ;; - esac - elif [ "${#COMP_WORDS[@]}" == "5" ]; then - case "${command}" in - recipients) - opts="$(cd $path/config/recipients && ls -p ${cur}* 2> /dev/null)" - ;; - genpair) - opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" - ;; - git) - # TODO - opts="$(_keyringer_git_complete ${prev} ${cur})" - ;; - *) - ;; - esac - elif [ "${command}" == "git" ]; then - # TODO - opts="$(_keyringer_git_complete ${COMP_WORDS[@]:3})" - fi - - # Avoid annoying bell and extra tab - if [ -z "$ZSH_VERSION" ]; then - bind 'set show-all-if-ambiguous on' - fi - - # Return the available options - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - - if [ -z "$ZSH_VERSION" ]; then - [[ $COMPREPLY == */ ]] && compopt -o nospace - fi - - return 0 -} - -complete -F _keyringer keyringer diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer new file mode 100644 index 0000000..4459b34 --- /dev/null +++ b/lib/keyringer/completions/bash/keyringer @@ -0,0 +1,119 @@ +#!bash +# +# Keyringer bash completion +# + +if [[ -n ${ZSH_VERSION-} ]]; then + autoload -U +X bashcompinit && bashcompinit +fi + +# 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 + + LAST=${COMP_WORDS[COMP_CWORD]} + REPLY=${COMPREPLY[@]} + + if [ "$REPLY" == "$LAST" ]; then + return + fi + + echo ${COMPREPLY[@]} + ) + fi +} + +_keyringer() { + # Standard stuff + local cur prev opts config + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + command="${COMP_WORDS[2]}" + + # Initial options + config="$HOME/.keyringer" + keyrings="`ls $config | sed -e 's/config//'`" + + # Process config + source $config/config + path="`eval echo '$'$instance`" + + # Available instances + instances="`echo $keyrings | sed -e 's/ /|/'`" + + # The current instance + instance="${COMP_WORDS[1]}" + + # Command completions + if [ "${#COMP_WORDS[@]}" == "2" ]; then + opts="$keyrings" + elif [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then + opts="`keyringer $instance commands`" + elif [ "${#COMP_WORDS[@]}" == "4" ]; then + case "${prev}" in + options|preferences) + opts="ls edit add" + ;; + recipients) + opts="ls edit" + ;; + ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|recrypt) + opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" + ;; + genpair) + opts="gpg ssh ssl ssl-self" + ;; + git) + opts="$(_keyringer_git_complete ${cur})" + ;; + *) + ;; + esac + elif [ "${#COMP_WORDS[@]}" == "5" ]; then + case "${command}" in + recipients) + opts="$(cd $path/config/recipients && ls -p ${cur}* 2> /dev/null)" + ;; + genpair) + opts="$(bash -c "set -f && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" + ;; + git) + # TODO + opts="$(_keyringer_git_complete ${prev} ${cur})" + ;; + *) + ;; + esac + elif [ "${command}" == "git" ]; then + # TODO + opts="$(_keyringer_git_complete ${COMP_WORDS[@]:3})" + fi + + # Avoid annoying bell and extra tab + if [ -z "$ZSH_VERSION" ]; then + bind 'set show-all-if-ambiguous on' + fi + + # Return the available options + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + + if [ -z "$ZSH_VERSION" ]; then + [[ $COMPREPLY == */ ]] && compopt -o nospace + fi + + return 0 +} + +complete -F _keyringer keyringer diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer new file mode 100644 index 0000000..1f1c250 --- /dev/null +++ b/lib/keyringer/completions/zsh/_keyringer @@ -0,0 +1,30 @@ +#compdef keyringer + +_keyringer() { + local curcontext="$curcontext" state line + typeset -A opt_args + + # Initial options + local config="$HOME/.keyringer" + local keyrings="`ls $config | sed -e 's/config//'`" + + _arguments \ + '1: :->keyring'\ + '2: :->action'\ + '*: :->options' + + case $state in + keyring) + _arguments "1:Keyrings:($keyrings)" + ;; + action) + compadd "$@" `keyringer $words[2] commands` + ;; + *) + # TODO + true + ;; + esac +} + +_keyringer "$@" -- cgit v1.2.3 From 004f0b0f950d0c8e43e2a4d59638fa152138dc71 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 16 Aug 2013 22:57:43 -0300 Subject: Matching zsh with bash completion --- lib/keyringer/completions/zsh/_keyringer | 82 +++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index 1f1c250..3aba2b3 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -1,5 +1,32 @@ #compdef keyringer +# 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 + + LAST=${COMP_WORDS[COMP_CWORD]} + REPLY=${COMPREPLY[@]} + + if [ "$REPLY" == "$LAST" ]; then + return + fi + + echo ${COMPREPLY[@]} + ) + fi +} + _keyringer() { local curcontext="$curcontext" state line typeset -A opt_args @@ -8,10 +35,12 @@ _keyringer() { local config="$HOME/.keyringer" local keyrings="`ls $config | sed -e 's/config//'`" - _arguments \ - '1: :->keyring'\ - '2: :->action'\ - '*: :->options' + _arguments \ + '1: :->keyring' \ + '2: :->action' \ + '3: :->options' \ + '4: :->misc' \ + '*: :->final' case $state in keyring) @@ -20,9 +49,50 @@ _keyringer() { action) compadd "$@" `keyringer $words[2] commands` ;; + options) + case $words[3] in + options|preferences) + compadd "$@" ls edit add + ;; + recipients) + compadd "$@" ls edit + ;; + ls|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|recrypt) + # TODO: do not rely on bash + compadd "$@" $(bash -c "set -f && keyringer $words[2] ls -p -d $words[4]*" 2> /dev/null) + ;; + genpair) + compadd "$@" gpg ssh ssl ssl-self + ;; + git) + compadd "$@" $(_keyringer_git_complete $words[4]) + ;; + *) + ;; + esac + ;; + misc) + case "$words[3]" in + recipients) + compadd "$@" $(cd $path/config/recipients && ls -p $words[5]* 2> /dev/null) + ;; + genpair) + # TODO: do not rely on bash + compadd "$@" $(bash -c "set -f && keyringer $instance ls -p -d $words[5]*" 2> /dev/null) + ;; + git) + # TODO + compadd "$@" $(_keyringer_git_complete $words[4] $words[5]) + ;; + *) + ;; + esac + ;; *) - # TODO - true + if [ $words[3] == "$git" ]; then + # TODO + true + fi ;; esac } -- cgit v1.2.3 From 48444f3a7b5971f6285d8c891d2bfd27baa772c7 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 16 Aug 2013 23:13:28 -0300 Subject: Check config before completion --- lib/keyringer/completions/bash/keyringer | 7 ++++++- lib/keyringer/completions/zsh/_keyringer | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer index 4459b34..e33977a 100644 --- a/lib/keyringer/completions/bash/keyringer +++ b/lib/keyringer/completions/bash/keyringer @@ -44,11 +44,16 @@ _keyringer() { # Initial options config="$HOME/.keyringer" - keyrings="`ls $config | sed -e 's/config//'`" + + # Check if we have initial configuration + if [ ! -d "$config" ]; then + return + fi # Process config source $config/config path="`eval echo '$'$instance`" + keyrings="`ls $config | sed -e 's/config//'`" # Available instances instances="`echo $keyrings | sed -e 's/ /|/'`" diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index 3aba2b3..b8f9d31 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -33,6 +33,13 @@ _keyringer() { # Initial options local config="$HOME/.keyringer" + + # Check if we have initial configuration + if [ ! -d "$config" ]; then + return + fi + + # Process config local keyrings="`ls $config | sed -e 's/config//'`" _arguments \ -- cgit v1.2.3 From 24b35c4df9275fb945d77a812dbc0f024c629eae Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 16 Aug 2013 23:15:50 -0300 Subject: TODO update --- lib/keyringer/completions/bash/keyringer | 1 + lib/keyringer/completions/zsh/_keyringer | 1 + 2 files changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer index e33977a..8317857 100644 --- a/lib/keyringer/completions/bash/keyringer +++ b/lib/keyringer/completions/bash/keyringer @@ -7,6 +7,7 @@ if [[ -n ${ZSH_VERSION-} ]]; then autoload -U +X bashcompinit && bashcompinit fi +# TODO: this is common completion code # Completion for git subcommand _keyringer_git_complete() { if [ -e "/etc/bash_completion.d/git" ]; then diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index b8f9d31..390a783 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -1,5 +1,6 @@ #compdef keyringer +# TODO: this is common completion code # Completion for git subcommand _keyringer_git_complete() { if [ -e "/etc/bash_completion.d/git" ]; then -- cgit v1.2.3 From e4166898f016fc2eb4e625bd1e95f5736ec6226b Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 22 Aug 2013 23:32:00 -0300 Subject: Use a different _keyringer_git_complete() for zsh --- lib/keyringer/completions/bash/keyringer | 1 - lib/keyringer/completions/zsh/_keyringer | 36 +++++++++----------------------- 2 files changed, 10 insertions(+), 27 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer index 8317857..e33977a 100644 --- a/lib/keyringer/completions/bash/keyringer +++ b/lib/keyringer/completions/bash/keyringer @@ -7,7 +7,6 @@ if [[ -n ${ZSH_VERSION-} ]]; then autoload -U +X bashcompinit && bashcompinit fi -# TODO: this is common completion code # Completion for git subcommand _keyringer_git_complete() { if [ -e "/etc/bash_completion.d/git" ]; then diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index 390a783..dd8775c 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -1,31 +1,13 @@ #compdef keyringer -# TODO: this is common completion code +# TODO: how to call _git() properly? # 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 - - LAST=${COMP_WORDS[COMP_CWORD]} - REPLY=${COMPREPLY[@]} - - if [ "$REPLY" == "$LAST" ]; then - return - fi - - echo ${COMPREPLY[@]} - ) - fi + ( + local CURRENT=1 + local words=($*) + echo `_git` + ) } _keyringer() { @@ -42,6 +24,8 @@ _keyringer() { # Process config local keyrings="`ls $config | sed -e 's/config//'`" + source $config/config + keyring_path="`eval echo '$'$words[2]`" _arguments \ '1: :->keyring' \ @@ -82,11 +66,11 @@ _keyringer() { misc) case "$words[3]" in recipients) - compadd "$@" $(cd $path/config/recipients && ls -p $words[5]* 2> /dev/null) + compadd "$@" $(cd $keyring_path/config/recipients && ls -p $words[5]* 2> /dev/null) ;; genpair) # TODO: do not rely on bash - compadd "$@" $(bash -c "set -f && keyringer $instance ls -p -d $words[5]*" 2> /dev/null) + compadd "$@" $(bash -c "set -f && keyringer $words[2] ls -p -d $words[5]*" 2> /dev/null) ;; git) # TODO -- cgit v1.2.3 From 84a1e7e56ed065cc4dadd8e8021694cf79b7eddd Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 25 Aug 2013 11:35:33 -0300 Subject: Minor cleanup at zsh completion --- lib/keyringer/completions/zsh/_keyringer | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index dd8775c..c8ada9b 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -1,13 +1,9 @@ #compdef keyringer -# TODO: how to call _git() properly? # Completion for git subcommand _keyringer_git_complete() { - ( - local CURRENT=1 - local words=($*) - echo `_git` - ) + # TODO: how to call _git() properly? + return } _keyringer() { @@ -81,7 +77,7 @@ _keyringer() { esac ;; *) - if [ $words[3] == "$git" ]; then + if [ $words[3] == "git" ]; then # TODO true fi -- cgit v1.2.3