-
Notifications
You must be signed in to change notification settings - Fork 0
/
fishmarks.fish
80 lines (67 loc) · 1.58 KB
/
fishmarks.fish
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# fishmarks bookmark dirs system
# inspired by Bashmarks (https://github.com/huyng/bashmarks)
# l: list
# j: jump
# p: print
# s: save
set fishmarks_file ~/.config/fish/.fishmarks
if not test -e $fishmarks_file
touch $fishmarks_file
end
function l
if test (count $argv) -ne 0
echo "USAGE: l"
return
end
while read name dir
echo (set_color purple) $name (set_color cyan) $dir
end < $fishmarks_file
end
function _fishmarks_find
if test (count $argv) -ne 2
echo "_fishmarks_find function requires 2 arguments"
return -1
end
set user_input $argv[1]
set cmd $argv[2] # either 'jump' or 'print'
while read name dir
if test $name = $user_input
switch $cmd
case "jump"
# use eval so that tildes are expanded to $HOME
eval "cd $dir"
case "print"
eval "echo $dir"
end
return
end
end < $fishmarks_file
echo "not found"
end
function j
if test (count $argv) -ne 1
echo "USAGE: j <name>"
return
end
_fishmarks_find $argv[1] jump
end
function p
if test (count $argv) -ne 1
echo "USAGE: r <name>"
return
end
_fishmarks_find $argv[1] print
end
function s
if test (count $argv) -ne 1
echo "USAGE: s <name>"
return
end
set name $argv[1]
set dir (pwd)
echo $name $dir >> $fishmarks_file
end
# define auto-completions
complete -c j -c p --description Marks --no-files -a "
(cat $fishmarks_file | cut -f 1 -d ' ')
"