my xfce4 dotfiles
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.

59 lines
1.4 KiB

3 years ago
  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. builtin cd -P "$MARKPATH/$1" 2>/dev/null || {echo "No such mark: $1"; return 1}
  12. }
  13. mark() {
  14. if [[ $# -eq 0 || "$1" = "." ]]; then
  15. MARK=${PWD:t}
  16. else
  17. MARK="$1"
  18. fi
  19. if read -q "?Mark $PWD as ${MARK}? (y/n) "; then
  20. command mkdir -p "$MARKPATH"
  21. command ln -sfn "$PWD" "$MARKPATH/$MARK"
  22. fi
  23. }
  24. unmark() {
  25. LANG= command rm -i "$MARKPATH/$1"
  26. }
  27. marks() {
  28. local link max=0
  29. for link in $MARKPATH/{,.}*(@N); do
  30. if [[ ${#link:t} -gt $max ]]; then
  31. max=${#link:t}
  32. fi
  33. done
  34. local printf_markname_template="$(printf -- "%%%us " "$max")"
  35. for link in $MARKPATH/{,.}*(@N); do
  36. local markname="$fg[cyan]${link:t}$reset_color"
  37. local markpath="$fg[blue]$(readlink $link)$reset_color"
  38. printf -- "$printf_markname_template" "$markname"
  39. printf -- "-> %s\n" "$markpath"
  40. done
  41. }
  42. _completemarks() {
  43. reply=("${MARKPATH}"/{,.}*(@N:t))
  44. }
  45. compctl -K _completemarks jump
  46. compctl -K _completemarks unmark
  47. _mark_expansion() {
  48. setopt localoptions extendedglob
  49. autoload -U modify-current-argument
  50. modify-current-argument '$(readlink "$MARKPATH/$ARG" || echo "$ARG")'
  51. }
  52. zle -N _mark_expansion
  53. bindkey "^g" _mark_expansion