Bash auto-complete enhancements

This commit is contained in:
Arun Prakash Jana 2019-07-08 23:35:30 +05:30
parent b0a60cfe64
commit 427c4b2429
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -9,7 +9,7 @@ _nnn () {
COMPREPLY=() COMPREPLY=()
local IFS=$' \n' local IFS=$' \n'
local cur=$2 prev=$3 local cur=$2 prev=$3
local -a opts opts_with_args local -a opts
opts=( opts=(
-b -b
-d -d
@ -23,22 +23,16 @@ _nnn () {
-v -v
-w -w
) )
opts_with_arg=( if [[ $prev == -b ]]; then
-b local bookmarks=$(echo $NNN_BMS | awk -F: -v RS=\; '{print $1}')
-p COMPREPLY=( $(compgen -W "$bookmarks" -- "$cur") )
) elif [[ $prev == -p ]]; then
COMPREPLY=( $(compgen -f -d -- "$cur") )
# Do not complete non option names elif [[ $cur == -* ]]; then
[[ $cur == -* ]] || return 1 COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
else
# Do not complete when the previous arg is an option expecting an argument COMPREPLY=( $(compgen -f -d -- "$cur") )
for opt in "${opts_with_arg[@]}"; do fi
[[ $opt == $prev ]] && return 1
done
# Complete option names
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
return 0
} }
complete -F _nnn nnn complete -o filenames -F _nnn nnn