2013-08-15 14:32:01 +00:00
|
|
|
# Easily jump around the file system by manually adding marks
|
|
|
|
# marks are stored as symbolic links in the directory $MARKPATH (default $HOME/.marks)
|
|
|
|
#
|
|
|
|
# jump FOO: jump to a mark named FOO
|
|
|
|
# mark FOO: create a mark named FOO
|
|
|
|
# unmark FOO: delete a mark
|
|
|
|
# marks: lists all marks
|
|
|
|
#
|
|
|
|
export MARKPATH=$HOME/.marks
|
2013-09-06 13:34:27 +00:00
|
|
|
|
2013-09-06 13:40:44 +00:00
|
|
|
jump() {
|
2020-02-11 18:35:17 +00:00
|
|
|
builtin cd -P "$MARKPATH/$1" 2>/dev/null || {echo "No such mark: $1"; return 1}
|
2013-08-15 14:32:01 +00:00
|
|
|
}
|
2013-09-06 13:34:27 +00:00
|
|
|
|
2013-09-06 13:40:44 +00:00
|
|
|
mark() {
|
2020-02-11 18:35:17 +00:00
|
|
|
if [[ $# -eq 0 || "$1" = "." ]]; then
|
|
|
|
MARK=${PWD:t}
|
2013-09-06 13:55:43 +00:00
|
|
|
else
|
2013-09-06 19:29:14 +00:00
|
|
|
MARK="$1"
|
2013-09-06 13:55:43 +00:00
|
|
|
fi
|
2020-02-11 18:35:17 +00:00
|
|
|
if read -q "?Mark $PWD as ${MARK}? (y/n) "; then
|
|
|
|
command mkdir -p "$MARKPATH"
|
|
|
|
command ln -sfn "$PWD" "$MARKPATH/$MARK"
|
2013-09-06 13:55:43 +00:00
|
|
|
fi
|
2013-08-15 14:32:01 +00:00
|
|
|
}
|
2013-09-06 13:34:27 +00:00
|
|
|
|
2013-09-06 13:40:44 +00:00
|
|
|
unmark() {
|
2020-02-11 18:35:17 +00:00
|
|
|
LANG= command rm -i "$MARKPATH/$1"
|
2013-08-15 14:32:01 +00:00
|
|
|
}
|
2013-09-06 13:34:27 +00:00
|
|
|
|
2013-09-06 13:40:44 +00:00
|
|
|
marks() {
|
2018-12-31 19:15:14 +00:00
|
|
|
local max=0
|
|
|
|
for link in $MARKPATH/*(@); do
|
|
|
|
if [[ ${#link:t} -gt $max ]]; then
|
|
|
|
max=${#link:t}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
local printf_markname_template="$(printf -- "%%%us " "$max")"
|
2013-09-06 13:40:44 +00:00
|
|
|
for link in $MARKPATH/*(@); do
|
|
|
|
local markname="$fg[cyan]${link:t}$reset_color"
|
|
|
|
local markpath="$fg[blue]$(readlink $link)$reset_color"
|
2018-12-31 19:15:14 +00:00
|
|
|
printf -- "$printf_markname_template" "$markname"
|
|
|
|
printf -- "-> %s\n" "$markpath"
|
2013-09-06 13:40:44 +00:00
|
|
|
done
|
2013-08-15 14:32:01 +00:00
|
|
|
}
|
2013-08-18 18:16:26 +00:00
|
|
|
|
2013-09-06 13:40:44 +00:00
|
|
|
_completemarks() {
|
2020-02-11 18:35:17 +00:00
|
|
|
reply=("${MARKPATH}"/*(N:t))
|
2013-08-18 18:16:26 +00:00
|
|
|
}
|
|
|
|
compctl -K _completemarks jump
|
|
|
|
compctl -K _completemarks unmark
|
2013-09-06 13:34:27 +00:00
|
|
|
|
|
|
|
_mark_expansion() {
|
|
|
|
setopt extendedglob
|
|
|
|
autoload -U modify-current-argument
|
|
|
|
modify-current-argument '$(readlink "$MARKPATH/$ARG")'
|
|
|
|
}
|
|
|
|
zle -N _mark_expansion
|
|
|
|
bindkey "^g" _mark_expansion
|