nnn/misc/auto-completion/bash/nnn-completion.bash

48 lines
1,022 B
Bash
Raw Normal View History

2017-09-02 12:23:19 +05:30
#
# Rudimentary Bash completion definition for nnn.
#
# Author:
# Arun Prakash Jana <engineerarun@gmail.com>
#
_nnn () {
COMPREPLY=()
local IFS=$' \n'
local cur=$2 prev=$3
2019-07-08 23:35:30 +05:30
local -a opts
2017-09-02 12:23:19 +05:30
opts=(
2019-08-30 20:55:23 +05:30
-a
2018-12-09 08:36:00 +05:30
-b
2019-10-06 18:57:15 +05:30
-c
2019-03-11 20:24:44 +05:30
-d
2019-10-06 18:57:15 +05:30
-f
2019-08-16 23:15:29 +05:30
-H
2017-09-02 12:23:19 +05:30
-i
2019-10-11 20:59:22 +05:30
-K
2019-07-14 23:00:14 +05:30
-n
-o
2018-12-09 08:36:00 +05:30
-p
-r
2019-02-06 00:38:55 +05:30
-s
2017-09-02 12:23:19 +05:30
-S
2019-08-17 00:07:38 +05:30
-t
2017-09-02 12:23:19 +05:30
-v
2019-08-16 23:15:29 +05:30
-h
2017-09-02 12:23:19 +05:30
)
2019-07-08 23:35:30 +05:30
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 [[ $prev == -e ]]; then
local sessions_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions
COMPREPLY=( $(compgen -W "$(ls $sessions_dir)" -- "$cur") )
2019-07-08 23:35:30 +05:30
elif [[ $cur == -* ]]; then
COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
else
COMPREPLY=( $(compgen -f -d -- "$cur") )
fi
2017-09-02 12:23:19 +05:30
}
2019-07-08 23:35:30 +05:30
complete -o filenames -F _nnn nnn