aboutsummaryrefslogtreecommitdiff
path: root/bin/sls
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sls')
-rwxr-xr-xbin/sls37
1 files changed, 37 insertions, 0 deletions
diff --git a/bin/sls b/bin/sls
new file mode 100755
index 00000000..eb376cbc
--- /dev/null
+++ b/bin/sls
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+#
+# 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
+#
+
+# Start by assuming we should parse all hosts
+declare -i sls
+sls=1
+
+# 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}"