My build of nnn with minor changes
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

61 lines
1.6 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. if [ -z "$BOOKMARKS_DIR" ]; then
  27. BOOKMARKS_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nnn/bookmarks"
  28. fi
  29. # Check if NNN_PIPE is set
  30. if [ -z "$NNN_PIPE" ]; then
  31. echo 'ERROR: NNN_PIPE is not set' | ${PAGER:-less}
  32. exit 2
  33. fi
  34. # Get all directory symlinks
  35. get_links() {
  36. for entry in "$1"/*; do
  37. # Skip unless directory symlink
  38. [ -h "$entry" ] || continue
  39. [ -d "$entry" ] || continue
  40. printf "%20s -> %s\n" "$(basename "$entry")" "$(readlink -f "$entry")"
  41. done | fzf |
  42. awk 'END {
  43. if (length($1) == 0) { print "'"$PWD"'" }
  44. else { print "'"$BOOKMARKS_DIR"'/"$1 }
  45. }'
  46. }
  47. # Choose symlink with fzf
  48. cddir="$(get_links "$BOOKMARKS_DIR")"
  49. # Writing result to NNN_PIPE will change nnn's active directory
  50. # https://github.com/jarun/nnn/tree/master/plugins#send-data-to-nnn
  51. context=0
  52. printf "%s" "${context}c$(readlink -f "$cddir")" > "$NNN_PIPE"