mirror of
https://github.com/jarun/nnn.git
synced 2025-03-18 20:39:45 +00:00
Bash auto-complete enhancements
This commit is contained in:
parent
b0a60cfe64
commit
427c4b2429
1 changed files with 12 additions and 18 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue