jump.plugin.zsh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Easily jump around the file system by manually adding marks
  2. # marks are stored as symbolic links in the directory $MARKPATH (default $HOME/.marks)
  3. #
  4. # jump FOO: jump to a mark named FOO
  5. # mark FOO: create a mark named FOO
  6. # unmark FOO: delete a mark
  7. # marks: lists all marks
  8. #
  9. export MARKPATH=$HOME/.marks
  10. jump() {
  11. cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
  12. }
  13. mark() {
  14. if (( $# == 0 )); then
  15. MARK=$(basename "$(pwd)")
  16. else
  17. MARK="$1"
  18. fi
  19. if read -q \?"Mark $(pwd) as ${MARK}? (y/n) "; then
  20. mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$MARK"
  21. fi
  22. }
  23. unmark() {
  24. rm -i "$MARKPATH/$1"
  25. }
  26. autoload colors
  27. marks() {
  28. for link in $MARKPATH/*(@); do
  29. local markname="$fg[cyan]${link:t}$reset_color"
  30. local markpath="$fg[blue]$(readlink $link)$reset_color"
  31. printf "%s\t" $markname
  32. printf "-> %s \t\n" $markpath
  33. done
  34. }
  35. _completemarks() {
  36. if [[ $(ls "${MARKPATH}" | wc -l) -gt 1 ]]; then
  37. reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_a-zA-Z0-9\.\-]*):$/\2/g'))
  38. else
  39. if readlink -e "${MARKPATH}"/* &>/dev/null; then
  40. reply=($(ls "${MARKPATH}"))
  41. fi
  42. fi
  43. }
  44. compctl -K _completemarks jump
  45. compctl -K _completemarks unmark
  46. _mark_expansion() {
  47. setopt extendedglob
  48. autoload -U modify-current-argument
  49. modify-current-argument '$(readlink "$MARKPATH/$ARG")'
  50. }
  51. zle -N _mark_expansion
  52. bindkey "^g" _mark_expansion