-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoto.fish
104 lines (91 loc) · 2.81 KB
/
goto.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function goto
set -g VERSION "0.3 (fat butt)"
set -g DB "$HOME/.gotostore"
function usage
echo "Usage: goto [OPTION]... [MODIFIERS]... "
echo "Example: goto add pepe '/home/pepe/'"
echo
echo "Options:"
echo "--------"
echo " [key]: Go to the set path."
echo " list | ls | l: List all available jumps."
echo " [remove | rm | d ] [key-name | all]: Delete the specified key or all keys"
#echo " rename | rn | r [old-key] [new-key]: Rename a given key"
echo " add | a: Add a path to the jump list."
echo " Modifiers:"
echo " ----------"
echo " this | . : Add the current path and set the 'jump' "
echo " key to the current directory name."
echo " [this | .] as [key]: Add the current path and specify the 'jump' key."
echo " [key] [path]: Add the desired path with the key."
echo " verion | v: Shows the current version."
echo " help | h: Shows this menu."
end
function validate
grep -P "[A-Za-z-_0-9]*"
end
function prettyPrint
echo "$argv[1]" | sed s/\=\/" => "/ | xargs -I line echo " " line
end
# Application Functions --------------------------------------------------------
function go
set search_key $argv[1]
set dest (grep "^$search_key=" $DB | grep -oP "=\K(.*)" )
cd $dest
end
function addKey
set entry ""
switch $argv[1]
case this .
set current_dir (basename $PWD)
if test $argv[2] = "as"
set entry "$argv[3]=$PWD"
else
set entry "$current_dir=$PWD"
end
case "*"
set entry "$argv1=$argv[2]"
end
if not test entry = ""
echo " Adding: $entry"
echo $entry >> $DB
end
end
function removeKey
set del_key "$argv[1]"
if test $del_key = "all"
echo "" >$DB
echo " The list has been cleaned."
else if not test $del_key = ""
sed -i "/^$del_key=/d" $DB
echo " $del_key was removed."
else
echo " There is no key to remove."
end
end
function listEntries
echo "List of available jumps:"
cat $DB | sed s/\=\/" => "/ | xargs -I line echo " " line
end
# Main Application Loop --------------------------------------------------------
if not test -f $DB
touch "$DB"
end
if test -z $argv[1]
set argv "h"
end
switch $argv[1]
case add a
addKey $argv[2] $argv[3] $argv[4]
case remove rm d
removeKey $argv[2]
case list ls l
listEntries
case version v
echo current ver. $VERSION
case help h
usage
case "*"
go $argv[1]
end
end