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

49 lines
1 KiB
Bash
Raw Normal View History

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