Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
pw/extras/pw.bash_completion
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (40 sloc)
1.27 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # bash completion for pw -*- shell-script -*- | |
| _pw() | |
| { | |
| local cur prev words cword | |
| _init_completion || return | |
| local db_dir=${XDG_DATA_HOME:-$HOME/.local/share/pw}/ | |
| case $prev in | |
| -h|--help) | |
| return 0 | |
| ;; | |
| -d|--db) | |
| local dbs opts local_path_re | |
| local_path_re='^(/|\.|~)' | |
| if [[ "${cur}" =~ $local_path_re ]] ; then | |
| opts="-f" | |
| dbs="*" | |
| else | |
| dbs=$( find $db_dir -type f -print ) | |
| dbs=${dbs//$db_dir/} | |
| fi | |
| local IFS=$'\n' | |
| compopt -o filenames | |
| COMPREPLY=( $( compgen $opts -W "$dbs" -- "$cur" ) ) | |
| return 0 | |
| ;; | |
| esac | |
| if [[ "$cur" == -* ]]; then | |
| local helpopts=$( _parse_help "$1" ) | |
| COMPREPLY=( $( compgen -W "${helpopts//#/}" -- "$cur" ) ) | |
| return 0 | |
| fi | |
| local db labels ids | |
| db='passwords' # FIXME: support for -d DB | |
| labels=$( cat "$db_dir/$db" | cut -d : -f 2 ) | |
| ids=$( cat "$db_dir/$db" | cut -d : -f 4 ) | |
| local IFS=$'\n' | |
| COMPREPLY=( $( compgen -W "$labels$IFS$ids" -- "$cur" ) ) | |
| } && | |
| complete -F _pw pw-autotype pw-diff pw-edit pw-insert pw-show | |
| # ex: ts=4 sw=4 et filetype=sh |