-
Notifications
You must be signed in to change notification settings - Fork 1
/
zsh-pins.plugin.zsh
39 lines (34 loc) · 941 Bytes
/
zsh-pins.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
pinfile=${XDG_DATA_HOME:-$HOME}/pins
alias pl='if [ -f $pinfile ]; then
while read -r pin; do
key=`awk -F "\t" '"'"'{print $1}'"'"' <<< $pin`
folder=`awk -F "\t" '"'"'{print $2}'"'"' <<< $pin`
echo -e "$key:-- $folder"
done < $pinfile | column -t -s :
fi'
pa() {
if [ "$1" != "" ] && ([ ! -f "$pinfile" ] || ! grep -Pq "^$1\t" "$pinfile"); then
touch "$pinfile"
echo -e "$1\t$PWD" >> "$pinfile"
sort -o "$pinfile" "$pinfile"
pl
fi
}
pd() {
if [ "$1" != "" ] && grep -Pq "^$1\t" "$pinfile"; then
sed -i --follow-symlinks "/^$1\t/d" "$pinfile"
pl
fi
}
pe() {
if [ "$1" != "" ] && grep -Pq "^$1\t" "$pinfile"; then
sed -i --follow-symlinks "s~^$1\t.*~$1\t$PWD~" "$pinfile"
pl
fi
}
pg() {
if [ "$1" != "" ] && grep -Pq "^$1\t" "$pinfile"; then
cd "$(sed "s/^$1\t\(.*\)$/\1/;t;d" "$pinfile")" || exit
ls
fi
}