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.

bookmarks 1.6 KiB

il y a 4 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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"