-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnav
executable file
·64 lines (57 loc) · 1.74 KB
/
nav
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
#!/bin/bash
# origin:
# http://github.com/doegox/todo.txt-cli/blob/extras/todo.actions.d/nav
# commit: 2bd8c410fa64ee30374eb6002503165d9b646b5e
action=$1
shift
function usage(){
echo " Navigate to URL:"
echo " nav ITEM#"
echo " Searches for a URL in the todo line and launches a browser."
echo ""
exit
}
[ "$action" = "usage" ] && usage
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
echo "Error! Usage:"
usage
fi
URL=$(sed "$1!d" "$TODO_FILE"|grep -E -o "([a-z]*)://[^ ]+")
if [ "$URL" = "" ]; then
LINE=$(sed "$1!d" "$TODO_FILE")
if [ "$LINE" = "" ]; then
echo "Error, no item #$1 found!"
else
echo "Error, no URL seen in item #$1!"
echo "$LINE"
fi
exit 1
fi
# Trying to be smart...
# on Debian alike:
if $(which x-www-browser >/dev/null 2>&1); then
exec x-www-browser "$URL"
# with freedesktop.org utils:
elif $(which xdg-open >/dev/null 2>&1); then
exec xdg-open "$URL"
# if you have git:
elif [ -x /usr/lib/git-core/git-web--browse ]; then
cd /usr/lib/git-core && ./git-web--browse "$URL"
# last resort, a la mano...
elif $(which firefox >/dev/null 2>&1); then
exec firefox "$URL"
elif $(which konqueror >/dev/null 2>&1); then
exec konqueror "$URL"
elif $(which nautilus >/dev/null 2>&1); then
exec nautilus "$URL"
# Windowsien?
elif [ -x "/cygdrive/c/Program Files/Mozilla Firefox/firefox.exe" ]; then
exec "/cygdrive/c/Program Files/Mozilla Firefox/firefox.exe" "$URL"
# OS X?
elif [ -x "/usr/bin/open" ]; then
exec "/usr/bin/open" "$URL"
else
echo "Sorry I'm giving up, cannot find your browser :-("
echo "Under cygwin, consider creating a shortcut in the path, like"
echo "ln -s \"/cygdrive/c/Program Files/Mozilla Firefox/firefox.exe\" /usr/local/bin/firefox"
fi