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