My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

56 lignes
1.5 KiB

  1. #!/usr/bin/env sh
  2. # Description: Use named bookmarks using symlinks
  3. #
  4. # Dependencies: fzf
  5. #
  6. # Usage:
  7. # 1. Create a $BOOKMARKS_DIR directory
  8. # By default, $BOOKMARKS_DIR is set to: ${XDG_CACHE_HOME:-$HOME/.cache}/nnn/bookmarks
  9. #
  10. # 2. Create symlinks to directories
  11. # `cd $BOOKMARKS_DIR`
  12. # `ln -s /path/to/useful/directory bookmark_name`
  13. # `ln -s $XDG_CONFIG_HOME/nnn/plugins nnn_plugins"
  14. # `ln -s /path/to/documents docs`
  15. # `ln -s /path/to/media media`
  16. # `ln -s /path/to/movies movies`
  17. #
  18. # Bonus tip: Add `$BOOKMARKS_DIR` to your `$CDPATH`
  19. # https://linux.101hacks.com/cd-command/cdpath/
  20. #
  21. # TODO:
  22. # 1. Remove `fzf` dependency
  23. #
  24. # Shell: POSIX compliant
  25. # Author: Todd Yamakawa
  26. BOOKMARKS_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nnn/bookmarks"
  27. # Check if NNN_PIPE is set
  28. if [ -z "$NNN_PIPE" ]; then
  29. echo 'ERROR: NNN_PIPE is not set' | ${PAGER:-less}
  30. exit 2
  31. fi
  32. # Get all directory symlinks
  33. get_links() {
  34. for entry in "$1"/*; do
  35. # Skip unless directory symlink
  36. [ -h "$entry" ] || continue
  37. [ -d "$entry" ] || continue
  38. printf "%20s -> %s\n" "$(basename "$entry")" "$(readlink -f "$entry")"
  39. done | fzf | awk 'END { print "'"$BOOKMARKS_DIR"'/"$1 }'
  40. }
  41. # Choose symlink with fzf
  42. cddir="$(get_links "$BOOKMARKS_DIR")"
  43. # Writing result to NNN_PIPE will change nnn's active directory
  44. # https://github.com/jarun/nnn/tree/master/plugins#send-data-to-nnn
  45. context=0
  46. printf "%s" "${context}c$(readlink -f "$cddir")" > "$NNN_PIPE"