aboutsummaryrefslogtreecommitdiff
path: root/jumper.sh
diff options
context:
space:
mode:
Diffstat (limited to 'jumper.sh')
-rwxr-xr-xjumper.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/jumper.sh b/jumper.sh
new file mode 100755
index 0000000..e31b6d3
--- /dev/null
+++ b/jumper.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+# jumper: Plaintext bookmark launcher
+# https://foswret.com
+
+browser=/bin/librewolf
+
+if [ -z "$1" ]; then
+ echo "Error: no bookmark file specifed."
+ exit 1
+fi
+
+filename="$1"
+
+
+# If a position file is specified
+if [ "$2" ]; then
+ position="$2"
+fi
+
+increment=0
+
+# If a specific postion is specified
+if [ "$position" ]; then
+ while IFS=" " read -r field comment; do
+ case $field in
+ # If the line starts with a "#" (comment)
+ \#*)
+ continue
+ ;;
+ *[!\ ]*)
+ increment=$((increment+1))
+ if [ "$position" = "$increment" ]; then
+ $browser "$field"
+ exit 0
+ fi
+ ;;
+ # If $field is only whitespace (blank line)
+ *)
+ continue
+ ;;
+ esac
+done < "$filename"
+echo "Error: position $position unknown."
+exit 1
+fi
+
+while IFS=" " read -r field comment; do
+ case $field in
+ # If the line starts with a "#" (comment)
+ \#*)
+ continue
+ ;;
+
+ *[!\ ]*)
+ increment=$((increment+1))
+ printf "(%d)" "$increment"
+ if [ "$comment" ]; then
+ printf " %s:" "$comment"
+ fi
+ printf " %s" "$field"
+ printf "\n"
+ ;;
+
+ # If $field is only whitespace (blank line)
+ *)
+ continue
+ ;;
+esac
+done < "$filename"
+
+exit 0