diff options
author | Joursoir <chat@joursoir.net> | 2021-06-22 08:48:13 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2021-06-22 08:48:13 +0000 |
commit | 7bc09f76bb74fd75362b9e21bd36d513b5dbf2f6 (patch) | |
tree | 3638bc25e908965a7780b56ff571331735449ee2 /contrib | |
parent | 8380ec44d7c0676ba1aaa6350cf3afa6ade4d07c (diff) | |
download | lock-password-7bc09f76bb74fd75362b9e21bd36d513b5dbf2f6.tar.gz lock-password-7bc09f76bb74fd75362b9e21bd36d513b5dbf2f6.tar.bz2 lock-password-7bc09f76bb74fd75362b9e21bd36d513b5dbf2f6.zip |
add bash completion
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/completion/lpass-completion.sh | 66 |
1 files changed, 66 insertions, 0 deletions
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) <chat@joursoir.net> + +# 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 <https://www.gnu.org/licenses/>. + +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 |