From 7bc09f76bb74fd75362b9e21bd36d513b5dbf2f6 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Tue, 22 Jun 2021 08:48:13 +0000 Subject: add bash completion --- contrib/completion/lpass-completion.sh | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 contrib/completion/lpass-completion.sh (limited to 'contrib/completion') diff --git a/contrib/completion/lpass-completion.sh b/contrib/completion/lpass-completion.sh new file mode 100755 index 0000000..f83f3c7 --- /dev/null +++ b/contrib/completion/lpass-completion.sh @@ -0,0 +1,66 @@ +# This file is part of LockPassword +# Copyright (C) 2020-2021 Aleksandr D. Goncharov (Joursoir) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +lockpass_dir=~/.lock-password + +__lpass_comp_file() +{ + local cur=$1 tmp + local counter=0 + local path + compopt -o filenames + + for path in $(compgen -f "$lockpass_dir/$cur" -- $cur) + do + tmp="${path#$lockpass_dir/}" + [ -d "$path" ] && tmp+=/ && compopt -o nospace + [ "${tmp:0:1}" = "." ] && continue + + COMPREPLY[counter++]=$tmp + done +} + +__lpass_main() +{ + local cur prev subcommands + local i counter=1 command cmd_func + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + subcommands=" + init insert show edit generate + rm mv help version + " + + while [ $counter -lt $COMP_CWORD ]; do + i="${COMP_WORDS[counter]}" + case "$i" in + -*) ;; + *) command="$i"; break ;; + esac + (( counter++ )) + done + + case "$command" in + insert|show|edit|generate|rm|mv) + __lpass_comp_file $cur + ;; + "") + COMPREPLY=( $(compgen -W "$subcommands" -- $cur) ) + ;; + esac +} + +complete -F __lpass_main lpass -- cgit v1.2.3-18-g5258