From 9f6b2e9bb85665c25ffe8c088ea3185ce3c23e9f Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Mon, 22 Jul 2024 06:54:25 -0700 Subject: [PATCH] add compatibility flags for a bunch of scripts (part 1) --- sh/argc | 2 +- sh/arith | 2 +- sh/askey | 2 +- sh/autosync | 3 ++- sh/bak | 2 +- sh/baknow | 2 +- sh/baks | 2 +- sh/bin | 2 +- sh/burl | 4 +++- sh/busiest | 2 +- sh/colors | 2 +- sh/colors2 | 2 +- sh/confirm | 2 +- sh/dated | 2 +- sh/days | 3 ++- sh/decently | 4 +--- 16 files changed, 20 insertions(+), 18 deletions(-) diff --git a/sh/argc b/sh/argc index c528f9e..0c3bc65 100755 --- a/sh/argc +++ b/sh/argc @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash +hush -ksh +mksh -oksh +osh +posh +yash +zsh argc() { ### @- validate the number of arguments in a function. ### ```sh diff --git a/sh/arith b/sh/arith index 77bf4eb..e3a7de1 100755 --- a/sh/arith +++ b/sh/arith @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh # though technically compatible with other shells, # extra functionality is through zsh's extended arithmetic functions. diff --git a/sh/askey b/sh/askey index e7bc849..35b8b77 100755 --- a/sh/askey +++ b/sh/askey @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh askey() { printf '\033[100m 00 \033[m \033[100m 01 \033[m \033[100m 02 \033[m \033[100m 03 \033[m \033[100m 04 \033[m \033[100m 05 \033[m \033[100m 06 \033[m \033[100m 07 \033[m \033[100m 08 \033[m \033[100m 09 \033[m \033[100m 0A \033[m \033[100m 0B \033[m \033[100m 0C \033[m \033[100m 0D \033[m \033[100m 0E \033[m \033[100m 0F \033[m diff --git a/sh/autosync b/sh/autosync index d4996bf..5478381 100755 --- a/sh/autosync +++ b/sh/autosync @@ -1,7 +1,8 @@ #!/usr/bin/env zsh -# compat: -ash -bash -dash +zsh +# compat: -ash -bash -dash -hush -ksh -mksh -oksh -osh -posh -yash +zsh # TODO: portable way of dodging aliases to allow other shell support? +# TODO: rewrite to use entr instead of inotifywait. autosync() { ### @- ### combine `inotifywait` and `rsync`. diff --git a/sh/bak b/sh/bak index 6b971f1..5822dc2 100755 --- a/sh/bak +++ b/sh/bak @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh bak() { ### @- ### backup files by creating copies and appending ".bak" to their names. diff --git a/sh/baknow b/sh/baknow index ac1e451..4ba0347 100755 --- a/sh/baknow +++ b/sh/baknow @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: -ash +bash +dash -hush -ksh +mksh -oksh +osh +posh +yash +zsh baknow() { ### @- backup files by appending their timestamps given by [`now`.](#now) ### ``` diff --git a/sh/baks b/sh/baks index d428d44..921e12e 100755 --- a/sh/baks +++ b/sh/baks @@ -1,6 +1,6 @@ #!/usr/bin/env sh # backup, timestamped -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash -hush -ksh +mksh +oksh +osh +posh +yash +zsh baks() { ### @- ### backup files by copying each and appending *the current* date-time, diff --git a/sh/bin b/sh/bin index 2cdaf1c..e137e6f 100755 --- a/sh/bin +++ b/sh/bin @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh # though technically compatible with other shells, # extra functionality is through zsh's extended arithmetic functions. diff --git a/sh/burl b/sh/burl index c67b8b0..274ad28 100755 --- a/sh/burl +++ b/sh/burl @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash -hush +ksh +mksh +oksh +osh +posh +yash +zsh burl() ( ### @- ### turn bash into a makeshift HTTP client. @@ -31,6 +31,8 @@ burl() ( ### @- ### } ### ``` + # shells with /dev/tcp and /dev/udp support: bash, ksh, yash. + ! (set -o pipefail) 2>&- || set -o pipefail (: &- && net=y || net= [ $'' ] && r=$(printf \\r) || r=$'\r' diff --git a/sh/busiest b/sh/busiest index b230e79..ede572c 100755 --- a/sh/busiest +++ b/sh/busiest @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# compat: -ash -bash -dash +zsh +# compat: -ash -bash -dash -hush -ksh -mksh -oksh -osh -posh -yash +zsh busiest() { ### @- ### list directories in descending order by the number of files in them, diff --git a/sh/colors b/sh/colors index e979bc6..8d539a1 100755 --- a/sh/colors +++ b/sh/colors @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# compat: -ash +bash -dash +zsh +# compat: -ash +bash -dash -hush +ksh -mksh -oksh +osh -posh -yash +zsh colors() { ### @- ### display all combinations of foreground and background terminal colors. diff --git a/sh/colors2 b/sh/colors2 index 7a9e9e4..879c2c0 100755 --- a/sh/colors2 +++ b/sh/colors2 @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh colors2() { [ $# -eq 0 ] || { printf "%s\n" "$0: does not take arguments" >&2; return 1; } diff --git a/sh/confirm b/sh/confirm index 56de0c7..f991087 100755 --- a/sh/confirm +++ b/sh/confirm @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh ### @ confirm ### display a simple yes-or-no prompt and return 0-or-1 respectively. diff --git a/sh/dated b/sh/dated index afab5d5..8a2bbc0 100755 --- a/sh/dated +++ b/sh/dated @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh dated() { local ts= u=0 diff --git a/sh/days b/sh/days index 18ada23..4928eaf 100755 --- a/sh/days +++ b/sh/days @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: -ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh days() { ### @- ### compute the number of days since a given date. @@ -8,6 +8,7 @@ days() { ### @- ### $ days 'January 1 1970' ### 18838 ### ``` + # FIXME: this doesn't always work in busybox because its `date` is too simple. [ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; } echo $(( ($(date +%s) - $(date -d "$1" +%s)) / 60 / 60 / 24 )) } diff --git a/sh/decently b/sh/decently index 389101a..3c6175c 100755 --- a/sh/decently +++ b/sh/decently @@ -1,7 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh - -# TODO: check if this is compatible with busybox. +# compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh decently() ( ### @- ### given a list of directories, update the last-modified timestamp