diff options
Diffstat (limited to 'launch')
-rwxr-xr-x | launch/launch | 110 |
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 |