d7b594e5cdf828308474ca22e7ccd336dd0abc5e

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #2045 from jeroenjanssens/master

Add jump plugin, which allows you to easily jump around the file system

Diff

 1diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..a3c5cf8c35a340159515fbc5cefa02e322a85ea2
 4--- /dev/null
 5+++ b/plugins/jump/jump.plugin.zsh
 6@@ -0,0 +1,52 @@
 7+# Easily jump around the file system by manually adding marks
 8+# marks are stored as symbolic links in the directory $MARKPATH (default $HOME/.marks)
 9+#
10+# jump FOO: jump to a mark named FOO
11+# mark FOO: create a mark named FOO
12+# unmark FOO: delete a mark
13+# marks: lists all marks
14+#
15+export MARKPATH=$HOME/.marks
16+
17+jump() {
18+	cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
19+}
20+
21+mark() {
22+	if (( $# == 0 )); then
23+		MARK=$(basename "$(pwd)")
24+	else
25+		MARK="$1"
26+	fi
27+	if read -q \?"Mark $(pwd) as ${MARK}? (y/n) "; then
28+		mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$MARK"
29+	fi
30+}
31+
32+unmark() {
33+	rm -i "$MARKPATH/$1"
34+}
35+
36+autoload colors
37+marks() {
38+	for link in $MARKPATH/*(@); do
39+		local markname="$fg[cyan]${link:t}$reset_color"
40+		local markpath="$fg[blue]$(readlink $link)$reset_color"
41+		printf "%s\t" $markname
42+		printf "-> %s \t\n" $markpath
43+	done
44+}
45+
46+_completemarks() {
47+	reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_\da-zA-Z\-]*):$/\2/g'))
48+}
49+compctl -K _completemarks jump
50+compctl -K _completemarks unmark
51+
52+_mark_expansion() {
53+	setopt extendedglob
54+	autoload -U modify-current-argument
55+	modify-current-argument '$(readlink "$MARKPATH/$ARG")'
56+}
57+zle -N _mark_expansion
58+bindkey "^g" _mark_expansion