aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-01-15 12:31:26 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-01-15 12:31:26 +1300
commit99c655cd11cd9000a496bde9c9fced98308c6454 (patch)
treedfec0895cc9448af3c8eb6ffb7eac0b662315456 /bin
parentMerge branch 'hotfix/v0.22.1' (diff)
parentBump version number to 0.23.0 (diff)
downloaddotfiles-99c655cd11cd9000a496bde9c9fced98308c6454.tar.gz
dotfiles-99c655cd11cd9000a496bde9c9fced98308c6454.zip
Merge branch 'release/v0.23.0'v0.23.0
* release/v0.23.0: Bump version number to 0.23.0 Remove unused `self` var from clog(1df) Change double-quote printf pattern to single-quote Move ShellCheck line to correct place in sra(1df) Quote EDITOR/VISUAL assignments for clarity Explicitly ignore uninteresting tree(1) opts Refactor clog(1df), allow args and non-term stdin Reimplement bl(1df) in Awk Separate ax(1df) manpage args from command Make newline explicit for ax(1df) Make first ax(1df) arg safer, warn on second arg Correct monospaced blocks in Vim plugin docs
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"