summaryrefslogtreecommitdiff
path: root/launch
diff options
context:
space:
mode:
authorTimmy Keller <tjk@tjkeller.xyz>2022-03-16 23:37:09 -0500
committerTimmy Keller <tjk@tjkeller.xyz>2022-03-16 23:37:09 -0500
commit3d3d79a57fb6d0a5728e0070475f05d1699f0818 (patch)
treeb141cba678d6bb9821bb33b0dd7c7f1ca31b2c6a /launch
parentd51fa1bdda79b8589ddf0002fc4b54aac6ce8354 (diff)
downloadscripts-3d3d79a57fb6d0a5728e0070475f05d1699f0818.tar.xz
scripts-3d3d79a57fb6d0a5728e0070475f05d1699f0818.zip
move a lot of scripts around and make a bunch of minor changes. once again i am too lazy to document the changes properly since im never going to read these commit messages anyways
Diffstat (limited to 'launch')
-rwxr-xr-xlaunch/launch110
1 files changed, 58 insertions, 52 deletions
diff --git a/launch/launch b/launch/launch
index 8e4cbd2..b4c1c7a 100755
--- a/launch/launch
+++ b/launch/launch
@@ -1,68 +1,74 @@
#!/bin/sh
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."
+cat << HELPDOC
+Usage:
+ $(me): [-gh] [COMMAND] [COMMAND ARGS]...
+
+Args:
+ -g: Force generate cache
+ -h: show this help message
+
+Config Syntax:
+ +host [HOSTNAME]
+ Add a new host. Hosts can be referenced using their number starting with 1.
+ [COMMAND]
+ launch [COMMAND] will start the process specified for the specific hostname. Aliases are separated by |.
+ [TAB][SHELL]
+ 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.
+HELPDOC
}
+
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
+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 {
- 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++
- }
+ 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]" \"$@\" & ;;"
- }
+ }
+ 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*) command -v \"$run\" >/dev/null && exec \"$run\" \"$@\" || echo \"\\`$run${@:+ $@}\\` Does not exist or exited with an error\" ;;"
- print "esac"
}
+ print "\t*) command -v \"$run\" >/dev/null && exec \"$run\" \"$@\" || echo \"\\`$run${@:+ $@}\\` Does not exist or exited with an error\" ;;"
+ print "esac"
}
- ' $conf > $cache
- chmod +x $cache
+ }
+' $conf > $cache
+chmod +x $cache
}
# Config file setup