2013-08-15 16:32:01 +02: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 15:34:27 +02:00
|
|
|
|
2024-01-25 10:19:01 +01:00
|
|
|
|
2013-09-06 15:40:44 +02:00
|
|
|
jump() {
|
2024-01-25 10:19:01 +01:00
|
|
|
local markpath="$(readlink $MARKPATH/$1)" || {echo "No such mark: $1"; return 1}
|
|
|
|
builtin cd "$markpath" 2>/dev/null || {echo "Destination does not exist for mark [$1]: $markpath"; return 2}
|
2013-08-15 16:32:01 +02:00
|
|
|
}
|
2013-09-06 15:34:27 +02:00
|
|
|
|
2013-09-06 15:40:44 +02:00
|
|
|
mark() {
|
2020-02-11 19:35:17 +01:00
|
|
|
if [[ $# -eq 0 || "$1" = "." ]]; then
|
|
|
|
MARK=${PWD:t}
|
2013-09-06 15:55:43 +02:00
|
|
|
else
|
2013-09-06 21:29:14 +02:00
|
|
|
MARK="$1"
|
2013-09-06 15:55:43 +02:00
|
|
|
fi
|
2020-02-11 19:35:17 +01:00
|
|
|
if read -q "?Mark $PWD as ${MARK}? (y/n) "; then
|
|
|
|
command mkdir -p "$MARKPATH"
|
|
|
|
command ln -sfn "$PWD" "$MARKPATH/$MARK"
|
2013-09-06 15:55:43 +02:00
|
|
|
fi
|
2013-08-15 16:32:01 +02:00
|
|
|
}
|
2013-09-06 15:34:27 +02:00
|
|
|
|
2013-09-06 15:40:44 +02:00
|
|
|
unmark() {
|
2020-02-11 19:35:17 +01:00
|
|
|
LANG= command rm -i "$MARKPATH/$1"
|
2013-08-15 16:32:01 +02:00
|
|
|
}
|
2013-09-06 15:34:27 +02:00
|
|
|
|
2013-09-06 15:40:44 +02:00
|
|
|
marks() {
|
2015-11-27 12:29:15 +01:00
|
|
|
local link max=0
|
2020-02-11 20:12:01 +01:00
|
|
|
for link in $MARKPATH/{,.}*(@N); do
|
2018-12-31 20:15:14 +01:00
|
|
|
if [[ ${#link:t} -gt $max ]]; then
|
|
|
|
max=${#link:t}
|
|
|
|
fi
|
|
|
|
done
|
2023-04-07 13:35:12 +02:00
|
|
|
local printf_markname_template="$(printf -- "%%%us" "$max")"
|
2020-02-11 20:12:01 +01:00
|
|
|
for link in $MARKPATH/{,.}*(@N); do
|
2023-04-07 13:35:12 +02:00
|
|
|
local markname="$fg[cyan]$(printf -- "$printf_markname_template" "${link:t}")$reset_color"
|
2013-09-06 15:40:44 +02:00
|
|
|
local markpath="$fg[blue]$(readlink $link)$reset_color"
|
2023-04-07 13:35:12 +02:00
|
|
|
printf -- "%s -> %s\n" "$markname" "$markpath"
|
2013-09-06 15:40:44 +02:00
|
|
|
done
|
2013-08-15 16:32:01 +02:00
|
|
|
}
|
2013-08-18 20:16:26 +02:00
|
|
|
|
2013-09-06 15:40:44 +02:00
|
|
|
_completemarks() {
|
2015-11-27 12:29:15 +01:00
|
|
|
reply=("${MARKPATH}"/{,.}*(@N:t))
|
2013-08-18 20:16:26 +02:00
|
|
|
}
|
|
|
|
compctl -K _completemarks jump
|
|
|
|
compctl -K _completemarks unmark
|
2013-09-06 15:34:27 +02:00
|
|
|
|
|
|
|
_mark_expansion() {
|
2015-11-27 12:29:15 +01:00
|
|
|
setopt localoptions extendedglob
|
2013-09-06 15:34:27 +02:00
|
|
|
autoload -U modify-current-argument
|
2020-02-11 20:12:01 +01:00
|
|
|
modify-current-argument '$(readlink "$MARKPATH/$ARG" || echo "$ARG")'
|
2013-09-06 15:34:27 +02:00
|
|
|
}
|
|
|
|
zle -N _mark_expansion
|
|
|
|
bindkey "^g" _mark_expansion
|