-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisit.plugin.zsh
55 lines (52 loc) · 1.47 KB
/
visit.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Visit a different directory then jump back to the original one
# Origin and visit locations are stored as a symbolic links in the directory $LOCPATH (default $HOME/.loc)
#
# visit FOO: navigate to FOO directory
# back: return to origin location or back to visit location
# origin: list origin and visit locations
#
export LOCPATH=$HOME/.loc
visit() {
if [[ ( $# == 0 ) ]]; then
echo "USAGE: visit <path>"
else
LOC=$1
if [[ -d "$LOC" ]]; then
if [[ -L "$LOCPATH/origin" ]]; then
rm -rf "$LOCPATH"
fi
mkdir -p "$LOCPATH"
ln -s "$PWD" "$LOCPATH/origin"
cd "$LOC"
ln -s "$PWD" "$LOCPATH/loc"
else
echo "$LOC is not a valid path."
return 1
fi
fi
}
back() {
if [[ -L "$LOCPATH/origin" ]]; then
if [[ $(readlink "$LOCPATH/origin") == "$PWD" ]]; then
echo "Navigating to visit location. Type 'back' again to return to origin location."
cd -P "$LOCPATH/loc"
else
echo "Navigating to origin. Type 'back' again to return to visit location."
rm "$LOCPATH/loc"
ln -s "$PWD" "$LOCPATH/loc"
cd -P "$LOCPATH/origin"
fi
else
echo "No locations have been set."
return 1
fi
}
origin() {
if [[ -L "$LOCPATH/origin" ]]; then
printf "$fg[cyan]origin$reset_color -> $fg[blue]$(readlink $LOCPATH/origin)$reset_color\n"
printf "$fg[cyan]visit$reset_color -> $fg[blue]$(readlink $LOCPATH/loc)$reset_color\n"
else
echo "No locations have been set."
return 1
fi
}