aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-30 23:26:11 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-30 23:26:11 +1200
commit04a74b42d5c60079fc1912b98aba4a9fe4aa43ed (patch)
treec4c5b37cbcd01015961ff0fb53e578fb1214cd93
parentBe consistent about full-sentence, full-stop (diff)
downloaddotfiles-04a74b42d5c60079fc1912b98aba4a9fe4aa43ed.tar.gz
dotfiles-04a74b42d5c60079fc1912b98aba4a9fe4aa43ed.zip
Rewrite sls(1) in POSIX Awk
-rwxr-xr-xbin/sls49
1 files changed, 15 insertions, 34 deletions
diff --git a/bin/sls b/bin/sls
index eb376cbc..278d79b4 100755
--- a/bin/sls
+++ b/bin/sls
@@ -1,37 +1,18 @@
-#!/usr/bin/env bash
+#!/usr/bin/awk -f
-#
-# sls(1) -- Print all the non-wildcard Host names (first one per line) from
-# an ssh_config(5) file, defaulting to $HOME/.ssh/config.
-#
-# Author: Tom Ryder <tom@sanctum.geek.nz>
-# Copyright: 2014
-# License: Public domain
-#
+# If no arguments, assume the default config files
+BEGIN {
+ if (ARGC == 1) {
+ ARGV[1] = "/etc/ssh/ssh_config"
+ ARGV[2] = ENVIRON["HOME"] "/.ssh/config"
+ ARGC += 2
+ }
+}
-# Start by assuming we should parse all hosts
-declare -i sls
-sls=1
+# Manage the processing flag (starts set)
+NR == 1 || /### sls/ { sls = 1 }
+/### nosls/ { sls = 0 }
-# Iterate through the config
-while read -r option value _ ; do
-
- # "### sls" and "### nosls" toggles parsing
- case $option in
- '###')
- case $value in
- nosls)
- sls=0
- ;;
- sls)
- sls=1
- ;;
- esac
- ;;
- 'Host')
- if ((sls)) && [[ $value != *[^[:alnum:]_-]* ]] ; then
- printf '%s\n' "$value"
- fi
- ;;
- esac
-done < "${1:-$HOME/.ssh/config}"
+# If processing flag set, directive is "Host", and hostname has no wildcards,
+# then print it
+sls && $1 == "Host" && $2 !~ /\*/ { print $2 }