forked from todotxt/todo.txt-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcd
executable file
·71 lines (63 loc) · 1.77 KB
/
cd
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
#!/bin/bash
#
action=$1
# now shift the positional parameters to the right, past
# the plug-in action, so that they can be pasted to the
# built-in actions.
#
shift
[ "$action" = "usage" ] && [[ "$1" == "version" ]] && {
sed -e 's/^ //' <<EndVersion
cd Add-on, version 1.0.2.
First release: 9-APR-2009
Author: Dave Hein
License: GPL, http://www.gnu.org/copyleft/gpl.html
EndVersion
exit
}
[ "$action" = "usage" ] && [[ "$1" == "short" ]] && {
sed -e 's/^ //' <<EndUsage
cd [todo|addons|cfg]
EndUsage
exit
}
[ "$action" = "usage" ] && {
sed -e 's/^ //' <<EndUsage
cd [todo|addons|cfg]
Does not actually change the directory, but
does output the command necessary for you to
change the current directory to the directory
holding the todo.txt and done.txt files (todo),
the directory holding the addons (addons),
or the directory holding the todo.cfg file (cfg).
Defaults to the directory holding todo.txt.
You can copy/paste the output and execute it
if you wish to actually change the directory.
EndUsage
exit
}
# see which argument, if any was specified
#
if [ x"$1" == x ] ; then
TODO_CD_TO_="$TODO_DIR"
elif echo "$1" | grep -iq ^todo$ ; then
TODO_CD_TO_="$TODO_DIR"
elif echo "$1" | grep -iq ^addons$ ; then
if [ x"$TODO_ACTIONS_DIR" == x ] ; then
TODO_CD_TO_="$HOME/.todo.actions.d"
else
TODO_CD_TO_="$TODO_ACTIONS_DIR"
fi
elif echo "$1" | grep -iq ^cfg$ ; then
TODO_CD_TO_=$(echo "$TODOTXT_CFG_FILE" | sed 's|\(.*\)/todo.cfg|\1|')
else
echo "'$1' is an invalid argument."
exit
fi
# prefix spaces with backslash
#
TODO_CD_TO_=$(echo "$TODO_CD_TO_" | sed 's|[[:space:]]|\\ |g')
# change to the directory
#
echo "cd $TODO_CD_TO_"
exit