summaryrefslogtreecommitdiff
path: root/launch
diff options
context:
space:
mode:
Diffstat (limited to 'launch')
-rwxr-xr-xlaunch/launch137
1 files changed, 90 insertions, 47 deletions
diff --git a/launch/launch b/launch/launch
index e529438..cb06b1d 100755
--- a/launch/launch
+++ b/launch/launch
@@ -1,51 +1,94 @@
#!/bin/sh
-[ -n "$2" ] && args=`echo "$@" | cut -d' ' -f2-`
+me() { basename "$0"; }
+printhelp() {
+ echo "Usage:\n" \
+ " $(me): [-gh] [COMMAND] [COMMAND ARGS]...\n\n" \
+ "Args:\n" \
+ " -g: Force generate cache\n" \
+ " -h: show this help message\n\n" \
+ "Config Syntax:\n" \
+ " +host [HOSTNAME]\n" \
+ " Add a new host. Hosts can be referenced using their number starting with 1.\n" \
+ " [COMMAND]\n" \
+ " launch [COMMAND] will start the process specified for the specific hostname. Aliases are separated by |.\n" \
+ " [TAB][SHELL]\n" \
+ " Run this shell command when the above [COMMAND] is specified. In order of hostnames. Can be a number to reference to a hostname, a '-' to disregard this command for the specific host, or a '^' to reference the previous command."
+}
+gencache() {
+ awk '
+ BEGIN {
+ print "run=\"$1\"; shift"
+ print "case \"$run\" in"
+ }
+ {
+ sub(/#.*/, "") # Remove comments
+ if (!/^\s*$/) {
+ if (/^\+host/) {
+ sub(/\s*\+host\s*/, "")
+ h++
+ hosts[h] = $0
+ }
+ else {
+ if (!/^\t/) {
+ hostnum = 1
+ o++
+ opts[o] = $0
+ }
+ else {
+ sub(/^\t/, "")
+ if ($0 == "^")
+ $0 = cache
+ else if ($0 ~ /^[0-9]*$/)
+ $0 = cmds[hosts[$0]":"opts[o]]
+ cmds[hosts[hostnum]":"opts[o]] = cache = $0
+ hostnum++
+ }
+ }
+ }
+ }
+ END {
+ for (host in hosts) {
+ if (hosts[host] != "'`hostname`'")
+ continue
+ for (cmd in cmds) {
+ if (cmd ~ hosts[host] && cmds[cmd] && cmds[cmd] != "-") {
+ i = cmd
+ sub(/.*:/, "", cmd)
+ print "\t"cmd") "cmds[i]" \"$@\" ;;"
+ }
+ }
+ print "\t*) exit 1 ;;"
+ print "esac"
+ }
+ }
+ ' $conf > $cache
+}
-launchother() { $@ || echo "Launch: $@: Does not exist or exited with an error"; }
+# Config file setup
+confdir=${XDG_CONFIG_HOME:-~/.config}/launch
+conf=$confdir/config
+if [ ! -e $conf ]; then
+ mkdir -p $confdir
+ echo "#HOSTS\n+host $(hostname)\n\n#OPTS\ntest\n\techo \"Tested!\"" > $conf
+ echo "Config file created at $conf! Exiting"
+ echo
+ printhelp
+ exit 0
+fi
-case "`hostname`" in
- G3N2)
- case "$1" in
- brave) brave-bin $args & xdotool search --all --sync --class "brave-browser" set_window --class "Brave" --urgency 1 ;;
- chromium|chrome) chromium-browser $args & xdotool search --all --sync --class "Chromium-browser-chromium" set_window --class "Chrome" --urgency 1 ;;
- halt|off|poweroff|shutdown) doas poweroff ;;
- sleep|suspend|zzz) doas s2ram ;;
- reboot|res|restart) doas reboot ;;
- snes|snes9x) snes9x -fullscreen -xvideo $args ;;
- *) launchother $@ ;;
- esac
- ;;
- voidx250)
- case "$1" in
- brave) brave-browser-stable $args & xdotool search --all --sync --class "brave-browser" set_window --class "Brave" --urgency 1 ;;
- chromium|chrome) chrome $args & xdotool search --all --sync --class "Chromium-browser" set_window --class "Chrome" --urgency 1 ;;
- halt|off|poweroff|shutdown) doas poweroff ;;
- sleep|suspend|zzz) doas zzz ;;
- reboot|res|restart) doas reboot ;;
- snes|snes9x) snes9x-gtk $args ;;
- *) launchother $@ ;;
- esac
- ;;
- debx230)
- case "$1" in
- brave) brave-browser-stable $args & xdotool search --all --sync --class "brave-browser" set_window --class "Brave" --urgency 1 ;;
- chromium|chrome) chromium $args & xdotool search --all --sync --class "Chromium" set_window --class "Chrome" --urgency 1 ;;
- #halt|off|poweroff|shutdown) doas poweroff ;;
- #sleep|suspend|zzz) doas zzz ;;
- #reboot|res|restart) doas reboot ;;
- #snes|snes9x) snes9x-gtk $args ;;
- *) launchother $@ ;;
- esac
- ;;
- librex60)
- case "$1" in
- firefox|brave) iceweasel -P default-release ;;
- chromium|chrome) iceweasel -P School ;;
- halt|off|poweroff|shutdown) doas poweroff ;;
- #sleep|suspend|zzz) doas zzz ;;
- reboot|res|restart) doas reboot ;;
- *) launchother $@ ;;
- esac
- ;;
- *) echo "Launch: The hostname \"`hostname`\" is not recognized. Please add an entry for it!" ;;
+# Cache file setup
+cachedir=${XDG_CACHE_HOME:-~/.cache}/launch
+cache=$cachedir/cache
+[ ! -e $cache ] && mkdir -p $cachedir && gencache
+[ $conf -nt $cache ] && gencache
+
+# Command line options
+case "$1" in
+ -g) echo "Generating new cache: $cache"; gencache && cat $cache; exit ;;
+ -h) printhelp && exit ;;
+ '') printhelp && exit ;;
esac
+
+# Run
+#sh $cache "$@" || "$@" || echo "$(me): $@: Does not exist or exited with an error" &
+exec $cache "$@"