Skip to content

Commit

Permalink
implement tab-completion of field names
Browse files Browse the repository at this point in the history
This uses the new format string infrastructure to display
just fieldnames in a subshell so that the fields in a specific
account can be tab-completed.  In order for lpass to know which
account is being queried, you have to specify account name first,
like:

    lpass show foo --field [tab]

There's a slight annoyance that title cannot go away completely,
so post-process with egrep to drop those.

Signed-off-by: Bob Copeland <[email protected]>
  • Loading branch information
Bob Copeland committed Oct 21, 2016
1 parent 8d67e93 commit 452ea3f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions contrib/lpass_bash_completion
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
__lpass_complete_fieldname()
{
local acct=$1
local cur=$2
local matches

matches=$(lpass show $acct --format='%fn' --title-format=' ' | \
egrep -v '^ $')

local IFS=$'\n'
COMPREPLY=($(compgen -W "$matches" "$cur"))
if [[ ! -z $COMPREPLY ]]; then
COMPREPLY=($(printf "%q\n" "${COMPREPLY[@]}"))
fi
}

__lpass_complete_name()
{
local cur=$1
Expand Down Expand Up @@ -33,6 +49,7 @@ __lpass_complete_opt()
{
local cmd=$1
local cur=$2
local name=$3
opts=""

case "$cmd" in
Expand Down Expand Up @@ -69,6 +86,7 @@ _lpass()
local cur="${COMP_WORDS[COMP_CWORD]}"
local cmd="${COMP_WORDS[1]}"
local subcmd="${COMP_WORDS[2]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local optind=1

for i in `seq 2 $COMP_CWORD`; do
Expand All @@ -78,6 +96,8 @@ _lpass()
fi
done

local name="${COMP_WORDS[$optind]}"

local all_cmds="
login logout passwd show ls mv add edit generate
duplicate rm sync export import share
Expand All @@ -103,6 +123,13 @@ _lpass()

COMPREPLY=()

case "$prev" in
--field)
__lpass_complete_fieldname $name $cur
return
;;
esac

case "$cur" in
-*)
__lpass_complete_opt $cmd $cur
Expand Down

0 comments on commit 452ea3f

Please sign in to comment.