My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nnn-completion.bash 1.0 KiB

4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #
  2. # Rudimentary Bash completion definition for nnn.
  3. #
  4. # Author:
  5. # Arun Prakash Jana <engineerarun@gmail.com>
  6. #
  7. _nnn ()
  8. {
  9. COMPREPLY=()
  10. local IFS=$'\n'
  11. local cur=$2 prev=$3
  12. local -a opts
  13. opts=(
  14. -a
  15. -A
  16. -b
  17. -c
  18. -d
  19. -E
  20. -g
  21. -H
  22. -K
  23. -n
  24. -o
  25. -p
  26. -Q
  27. -r
  28. -R
  29. -s
  30. -S
  31. -v
  32. -V
  33. -x
  34. -h
  35. )
  36. if [[ $prev == -b ]]; then
  37. local bookmarks=$(echo $NNN_BMS | awk -F: -v RS=\; '{print $1}')
  38. COMPREPLY=( $(compgen -W "$bookmarks" -- "$cur") )
  39. elif [[ $prev == -p ]]; then
  40. COMPREPLY=( $(compgen -f -d -- "$cur") )
  41. elif [[ $prev == -s ]]; then
  42. local sessions_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions
  43. COMPREPLY=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
  44. elif [[ $cur == -* ]]; then
  45. COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
  46. else
  47. COMPREPLY=( $(compgen -f -d -- "$cur") )
  48. fi
  49. }
  50. complete -o filenames -F _nnn nnn