-
Notifications
You must be signed in to change notification settings - Fork 1
/
goto.sh
73 lines (69 loc) · 2.04 KB
/
goto.sh
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
#!/usr/bin/env sh
#
# This content is released under the (https://github.com/horttanainen/goto/blob/master/LICENSE) MIT License.
# this script should not be run directly,
# instead you need to source it from your .bashrc (or similar to your shell choice),
# by adding this line:
# . /path/to/your/goto/goto.sh
gotopath=""
export lines="$gotopath/lines"
export linenum="$gotopath/linenum"
export paths="$gotopath/paths"
export tmpfile="$gotopath/tmpfile"
script="$gotopath/subgoto.sh"
goto() {
goto=1
export workdir="$(pwd)"
while getopts ":cr:a:" opt; do
case $opt in
r)
goto=0
if [ $(echo "${#workdir}") = 1 ]; then
file="${workdir}$OPTARG"
else
file="$workdir/$OPTARG"
fi
if [ -e $file ]; then
echo "$file" | cat - "$lines" > $tmpfile && mv $tmpfile "$lines"
break
else
echo "File or folder does not exist!"
break
fi
;;
a)
goto=0
char=$(echo $OPTARG | cut -c 1)
if [ $char = "/" ]; then
:
else
echo "Absolute paths must begin with /"
break
fi
if [ -e $OPTARG ]; then
echo "$OPTARG" | cat - "$lines" > $tmpfile && mv $tmpfile "$lines"
break
else
echo "File or folder does not exist!"
break
fi
;;
c)
goto=0
echo "$workdir" | cat - "$lines" > $tmpfile && mv $tmpfile "$lines"
break
;;
\?)
goto=0
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
shift $((OPTIND-1))
if [ $goto = 0 ]; then
:
else
. $script
subgoto $@
fi
}