diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2019-07-08 23:35:30 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2019-07-08 23:35:30 +0530 |
commit | 427c4b2429942f518970a5c5ff019a05a218c009 (patch) | |
tree | ca239139345c1238952b1fa829f2433eed4300f2 /misc/auto-completion | |
parent | b0a60cfe64866cbe013792ba76d4c5ce4f2486ed (diff) | |
download | nnn-427c4b2429942f518970a5c5ff019a05a218c009.tar.gz |
Bash auto-complete enhancements
Diffstat (limited to 'misc/auto-completion')
-rw-r--r-- | misc/auto-completion/bash/nnn-completion.bash | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/misc/auto-completion/bash/nnn-completion.bash b/misc/auto-completion/bash/nnn-completion.bash index 4c81e77..a0dcd30 100644 --- a/misc/auto-completion/bash/nnn-completion.bash +++ b/misc/auto-completion/bash/nnn-completion.bash @@ -9,7 +9,7 @@ _nnn () { COMPREPLY=() local IFS=$' \n' local cur=$2 prev=$3 - local -a opts opts_with_args + local -a opts opts=( -b -d @@ -23,22 +23,16 @@ _nnn () { -v -w ) - opts_with_arg=( - -b - -p - ) - - # Do not complete non option names - [[ $cur == -* ]] || return 1 - - # Do not complete when the previous arg is an option expecting an argument - for opt in "${opts_with_arg[@]}"; do - [[ $opt == $prev ]] && return 1 - done - - # Complete option names - COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") ) - return 0 + if [[ $prev == -b ]]; then + local bookmarks=$(echo $NNN_BMS | awk -F: -v RS=\; '{print $1}') + COMPREPLY=( $(compgen -W "$bookmarks" -- "$cur") ) + elif [[ $prev == -p ]]; then + COMPREPLY=( $(compgen -f -d -- "$cur") ) + elif [[ $cur == -* ]]; then + COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") ) + else + COMPREPLY=( $(compgen -f -d -- "$cur") ) + fi } -complete -F _nnn nnn +complete -o filenames -F _nnn nnn |