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

53 lines
1 KiB
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>
#
2019-11-22 02:14:25 +05:30
_nnn ()
{
2017-09-02 12:23:19 +05:30
COMPREPLY=()
local IFS=$'\n'
2017-09-02 12:23:19 +05:30
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-11-30 18:14:39 +05:30
-E
2019-12-14 19:00:09 +05:30
-g
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
2019-12-14 23:28:13 +05:30
-Q
-r
2019-12-01 23:00:06 +05:30
-R
-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
-x
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 == -s ]]; then
local sessions_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions
COMPREPLY=( $(cd "$sessions_dir" && compgen -f -d -- "$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