aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-31 11:53:31 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-31 11:54:55 +1200
commit17f6305e253cc36acec5384c55d8369405645a03 (patch)
tree12aff25cfd17fa3deabbab1b8b42fb46a090f96c
parentRemove poetry games tinkering scripts (diff)
downloaddotfiles-17f6305e253cc36acec5384c55d8369405645a03.tar.gz
dotfiles-17f6305e253cc36acec5384c55d8369405645a03.zip
Split out sls(1) into shell and awk
-rw-r--r--README.markdown3
-rwxr-xr-xbin/sls26
-rwxr-xr-xbin/slsf9
-rw-r--r--man/man1/sls.113
-rw-r--r--man/man1/slsf.119
5 files changed, 45 insertions, 25 deletions
diff --git a/README.markdown b/README.markdown
index 7deddcce..ec06ac4d 100644
--- a/README.markdown
+++ b/README.markdown
@@ -284,7 +284,8 @@ current shell.
Installed by the `install-bin` target:
* Three SSH-related scripts:
- * `sls(1)` prints hostnames read from a `ssh_config(5)` file.
+ * `sls(1)` prints hostnames read from a `ssh_config(5)` file. It uses
+ `slsf(1)` to read each one.
* `sra(1)` runs a command on multiple hosts read from `sls(1)` and prints
output.
* `sta(1)` runs a command on multiple hosts read from `sls(1)` and prints
diff --git a/bin/sls b/bin/sls
index 278d79b4..c5281aa7 100755
--- a/bin/sls
+++ b/bin/sls
@@ -1,18 +1,8 @@
-#!/usr/bin/awk -f
-
-# 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
- }
-}
-
-# Manage the processing flag (starts set)
-NR == 1 || /### sls/ { sls = 1 }
-/### nosls/ { sls = 0 }
-
-# If processing flag set, directive is "Host", and hostname has no wildcards,
-# then print it
-sls && $1 == "Host" && $2 !~ /\*/ { print $2 }
+#!/bin/sh
+if [ "$#" -eq 0 ] ; then
+ for cfg in /etc/ssh_config "$HOME"/.ssh/config ; do
+ [ -e "$cfg" ] || continue
+ set -- "$@" "$cfg"
+ done
+fi
+exec slsf -- "$@"
diff --git a/bin/slsf b/bin/slsf
new file mode 100755
index 00000000..72af8691
--- /dev/null
+++ b/bin/slsf
@@ -0,0 +1,9 @@
+#!/usr/bin/awk -f
+
+# Manage the processing flag (starts set in each file)
+FNR == 1 || /### sls/ { sls = 1 }
+/### nosls/ { sls = 0 }
+
+# If processing flag set, directive is "Host", and hostname has no wildcards,
+# then print it
+sls && $1 == "Host" && $2 !~ /\*/ { print $2 }
diff --git a/man/man1/sls.1 b/man/man1/sls.1
index 691c6abb..d876b976 100644
--- a/man/man1/sls.1
+++ b/man/man1/sls.1
@@ -4,14 +4,15 @@
\- list the first hostname on each line of an ssh_config(5) file
.SH SYNOPSIS
.B sls
-.I [SSH_CONFIG]
+.br
+.B sls
+ssh_config_alt1 ssh_config_alt2
.SH DESCRIPTION
.B sls
-reads an ssh_config(5) file, defaulting to ~/.ssh/config, and returns a
-newline-delimited list of the first of the hostnames on each Host line in the
-file, ignoring all other lines. Suitable for use in batch scripts like
-sra(1).
+runs slsf(1) on the given set of ssh_config(5) files to print the first
+non-wildcard hostname on each "Host" line, defaulting to /etc/ssh/ssh_config
+and ~/.ssh/config if they exist. Suitable for use in batch scripts like sra(1).
.SH SEE ALSO
-sra(1), sta(1), ssh(1), ssh_config(5)
+slsf(1), sra(1), sta(1), ssh(1), ssh_config(5)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/slsf.1 b/man/man1/slsf.1
new file mode 100644
index 00000000..d19e7c96
--- /dev/null
+++ b/man/man1/slsf.1
@@ -0,0 +1,19 @@
+.TH SLSF 1 "July 2016" "Manual page for slsf"
+.SH NAME
+.B slsf
+\- list the first hostname on each line of ssh_config(5) files
+.SH SYNOPSIS
+.B slsf /etc/ssh_config ~/.ssh_config
+.br
+cat ~/.ssh_config |
+.B slsf
+.br
+.SH DESCRIPTION
+.B slsf
+iterates through the ssh_config(5) files given as its input and prints the
+first non-wildcard hostname on each "Host" line. Most users will probably want
+the sls(1) frontend.
+.SH SEE ALSO
+sls(1), sra(1), sta(1), ssh(1), ssh_config(5)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>