aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/ax.sh17
-rw-r--r--bin/bl.awk5
-rw-r--r--bin/bl.sh10
-rw-r--r--bin/clog.sh24
-rw-r--r--bin/sra.sh3
-rw-r--r--bin/sshi.sh2
6 files changed, 26 insertions, 35 deletions
diff --git a/bin/ax.sh b/bin/ax.sh
index 6ce1e9ea..0007cbed 100644
--- a/bin/ax.sh
+++ b/bin/ax.sh
@@ -3,8 +3,8 @@
# Count arguments
case $# in
- # If one argument, we assume format is %s
- 1) form=%s expr=$1 ;;
+ # If one argument, we assume format is %s\n
+ 1) form='%s\n' expr=$1 ;;
# If two arguments, first is format, second expression
2) form=$1 expr=$2 ;;
@@ -16,12 +16,7 @@ case $# in
;;
esac
-# Form program
-prog=$(printf '
- BEGIN {
- printf "%s\\n", %s
- }
-' "$form" "$expr")
-
-# Run program
-awk "$prog"
+# Important note: there's little stopping the user from putting a fully-fledged
+# Awk program into the expression; don't use this anywhere that code injection
+# could wreck your life. See manual page ax(1df).
+awk -v form="$form" 'BEGIN{printf form,('"$expr"');exit}'
diff --git a/bin/bl.awk b/bin/bl.awk
new file mode 100644
index 00000000..0be2fc6e
--- /dev/null
+++ b/bin/bl.awk
@@ -0,0 +1,5 @@
+# Generate blank lines
+BEGIN {
+ while (ARGV[1]--)
+ print ""
+}
diff --git a/bin/bl.sh b/bin/bl.sh
deleted file mode 100644
index 6dd3d687..00000000
--- a/bin/bl.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-# Generate blank lines
-if [ "$#" -ne 1 ] || [ "$1" -lt 0 ] ; then
- printf >&2 'bl: Non-negative line count needed as sole argument\n'
- exit 2
-fi
-n=0
-while [ "$n" -lt "${1:-0}" ] ; do
- printf '\n'
- n=$((n+1))
-done
diff --git a/bin/clog.sh b/bin/clog.sh
index 1b612d68..3269c508 100644
--- a/bin/clog.sh
+++ b/bin/clog.sh
@@ -1,17 +1,17 @@
# Record a timestamped message to a logfile, defaulting to ~/.clog
-self=clog
-# Ignore arguments
-set --
+# Build the cat(1) command we'll run, wrapping it in rlwrap(1) if available and
+# applicable.
+if [ "$#" -eq 0 ] && [ -t 0 ] && command -v rlwrap >/dev/null 2>&1 ; then
+ set -- rlwrap --history-filename=/dev/null cat -- "${@:--}"
+else
+ set -- cat -- "${@:--}"
+fi
-# If we have rlwrap, quietly use it
-command -v rlwrap >/dev/null 2>&1 &&
- set -- rlwrap --history-filename=/dev/null -C "$self" "$@"
-
-# Write the date, the standard input (rlwrapped if applicable), and two dashes
-# to $CLOG, defaulting to ~/.clog.
+# Write the date, the input, and two dashes to $CLOG, defaulting to ~/.clog.
+clog=${CLOG:-"$HOME"/.clog}
{
date
- "$@" cat -
- printf '%s\n' --
-} >>"${CLOG:-"$HOME"/.clog}"
+ "$@"
+ printf -- '--\n'
+} >> "$clog"
diff --git a/bin/sra.sh b/bin/sra.sh
index f3ed6f71..36a673e1 100644
--- a/bin/sra.sh
+++ b/bin/sra.sh
@@ -3,5 +3,6 @@
exec 3<&0
sls | while read -r hostname ; do
printf 'sra: %s\n' "$hostname"
- ssh -qt -- "$hostname" "$@" <&3 # shellcheck disable=SC2029
+ # shellcheck disable=SC2029
+ ssh -qt -- "$hostname" "$@" <&3
done
diff --git a/bin/sshi.sh b/bin/sshi.sh
index 0d1591f1..4872765d 100644
--- a/bin/sshi.sh
+++ b/bin/sshi.sh
@@ -20,7 +20,7 @@ printf '%s\n' "$SSH_CONNECTION" "${SSH_TTY:-unknown}" |
sh=$(dig -x "$si" +short 2>/dev/null | sed 's/\.$//;1q')
# Print the results in a human-readable format
- printf "%s:%u -> %s:%u (%s)\n" \
+ printf '%s:%u -> %s:%u (%s)\n' \
"${ch:-"$ci"}" "$cp" \
"${sh:-"$si"}" "$sp" \
"$tty"