nnn

mirror of https://github.com/jarun/nnn
Log | Files | Refs | README | LICENSE

nnn-completion.bash (1643B)


      1 #
      2 # Rudimentary Bash completion definition for nnn.
      3 #
      4 # Author:
      5 #   Arun Prakash Jana <engineerarun@gmail.com>
      6 #
      7 
      8 _nnn ()
      9 {
     10     COMPREPLY=()
     11     local IFS=$'\n'
     12     local cur=$2 prev=$3
     13     local -a opts
     14     opts=(
     15         -a
     16         -A
     17         -b
     18         -B
     19         -c
     20         -C
     21         -d
     22         -D
     23         -e
     24         -E
     25         -f
     26         -g
     27         -H
     28         -i
     29         -J
     30         -K
     31         -l
     32         -n
     33         -o
     34         -p
     35         -P
     36         -Q
     37         -r
     38         -R
     39         -s
     40         -S
     41         -t
     42         -T
     43         -u
     44         -U
     45         -V
     46         -x
     47         -z
     48         -0
     49         -h
     50     )
     51     if [[ $prev == -b ]]; then
     52         local bookmarks=$(echo $NNN_BMS | awk -F: -v RS=\; '{print $1}')
     53         COMPREPLY=( $(compgen -W "$bookmarks" -- "$cur") )
     54     elif [[ $prev == -l ]]; then
     55         return 1
     56     elif [[ $prev == -p ]]; then
     57         COMPREPLY=( $(compgen -f -d -- "$cur") )
     58     elif [[ $prev == -P ]]; then
     59         local plugins=$(echo $NNN_PLUG | awk -F: -v RS=\; '{print $1}')
     60         COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
     61     elif [[ $prev == -s ]]; then
     62         local sessions_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions
     63         COMPREPLY=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
     64     elif [[ $prev == -t ]]; then
     65         return 1
     66     elif [[ $prev == -T ]]; then
     67         local keys=$(echo "a d e r s t v" | awk -v RS=' ' '{print $0}')
     68         COMPREPLY=( $(compgen -W "$keys" -- "$cur") )
     69     elif [[ $cur == -* ]]; then
     70         COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
     71     else
     72         COMPREPLY=( $(compgen -f -d -- "$cur") )
     73     fi
     74 }
     75 
     76 complete -o filenames -F _nnn nnn