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() {
|
2015-11-27 11:29:15 +00:00
|
|
|
local link max=0
|
2020-02-11 19:12:01 +00:00
|
|
|
for link in $MARKPATH/{,.}*(@N); do
|
2018-12-31 19:15:14 +00:00
|
|
|
if [[ ${#link:t} -gt $max ]]; then
|
|
|
|
max=${#link:t}
|
|
|
|
fi
|
|
|
|
done
|
2023-04-07 11:35:12 +00:00
|
|
|
local printf_markname_template="$(printf -- "%%%us" "$max")"
|
2020-02-11 19:12:01 +00:00
|
|
|
for link in $MARKPATH/{,.}*(@N); do
|
2023-04-07 11:35:12 +00:00
|
|
|
local markname="$fg[cyan]$(printf -- "$printf_markname_template" "${link:t}")$reset_color"
|
2013-09-06 13:40:44 +00:00
|
|
|
local markpath="$fg[blue]$(readlink $link)$reset_color"
|
2023-04-07 11:35:12 +00:00
|
|
|
printf -- "%s -> %s\n" "$markname" "$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() {
|
2015-11-27 11:29:15 +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() {
|
2015-11-27 11:29:15 +00:00
|
|
|
setopt localoptions extendedglob
|
2013-09-06 13:34:27 +00:00
|
|
|
autoload -U modify-current-argument
|
2020-02-11 19:12:01 +00:00
|
|
|
modify-current-argument '$(readlink "$MARKPATH/$ARG" || echo "$ARG")'
|
2013-09-06 13:34:27 +00:00
|
|
|
}
|
|
|
|
zle -N _mark_expansion
|
|
|
|
bindkey "^g" _mark_expansion
|