From 7c9482c02c54b84a63d8c32c46f2d3e69b0989da Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Tue, 23 Jul 2024 00:04:57 -0700 Subject: [PATCH] add compatibility flags for a bunch of scripts (part 3) --- sh/minutemaid | 4 ++-- sh/monitor | 2 +- sh/morecolors | 7 +++---- sh/note | 2 +- sh/now | 8 ++++---- sh/oshi | 2 +- sh/oxo | 2 +- sh/pause | 2 +- sh/pegg | 2 +- sh/permit | 2 +- sh/pippy | 2 +- sh/pre | 2 +- sh/psbm | 4 ++-- sh/randir | 2 +- sh/recolor | 2 +- sh/rot13 | 2 +- sh/running | 4 ++-- 17 files changed, 25 insertions(+), 26 deletions(-) diff --git a/sh/minutemaid b/sh/minutemaid index df31c20..2181561 100755 --- a/sh/minutemaid +++ b/sh/minutemaid @@ -1,5 +1,5 @@ #!/usr/bin/env dash -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash -hush -ksh +mksh +oksh +osh +posh +yash +zsh minutemaid() { ### @- ### check if the current minute is divisible by a given number, @@ -32,7 +32,7 @@ minutemaid() { ### @- while getopts 'o:h' name; do case $name in o) offset="$OPTARG";; - ?) local fd=0 + ?) local fd=0 # FIXME: this also matches single-character filenames! [ $name = h ] && fd=1 || fd=2 printf '%s\n' "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd [ $name = h ] && return 0 || return 1;; diff --git a/sh/monitor b/sh/monitor index a553951..0f2bc7e 100755 --- a/sh/monitor +++ b/sh/monitor @@ -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 monitor() { ### @- ### this is [watch(1)](https://www.man7.org/linux/man-pages/man1/watch.1.html) diff --git a/sh/morecolors b/sh/morecolors index 9948e07..9ebaa22 100755 --- a/sh/morecolors +++ b/sh/morecolors @@ -1,9 +1,8 @@ #!/usr/bin/env bash -# compat: -ash +bash -dash +zsh +# compat: -ash +bash -dash -hush +ksh -mksh -oksh +osh -posh -yash +zsh -morecolors() { ### @- print all 256 colors that are available on most terminals. +morecolors() ( ### @- print all 256 colors that are available on most terminals. # borrowed from leah2's dotfiles. - local i= for i in {0..255}; do printf '\e[48;5;%dm\e[38;5;15m %03d ' $i $i printf '\e[33;5;0m\e[38;5;%dm %03d ' $i $i @@ -11,6 +10,6 @@ morecolors() { ### @- print all 256 colors that are available on most terminals. [ "$(( i+1 <= 16 ? (i+1) % 16 : ( (i+1)-16) % 36 ))" = 0 ] && printf '\e[0m\n' done return 0 -} +) [ -n "${preload+-}" ] || morecolors "$@" diff --git a/sh/note b/sh/note index 644f47d..eb867f9 100755 --- a/sh/note +++ b/sh/note @@ -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 note() { ### @- ### act like [`echo2`,](#echo2) but use a bright color to stand out more. diff --git a/sh/now b/sh/now index 1c8a1d6..4d72012 100755 --- a/sh/now +++ b/sh/now @@ -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 now() { ### @- ### print a date-time (UTC) in a sortable format. @@ -17,11 +17,11 @@ now() { ### @- local dt= fmt='+%F_%T_%N' if [ -z "$1" ]; then - dt="$(date -u "$fmt")" + dt="$(exec /usr/bin/env date -u "$fmt")" elif [ -e "$1" ]; then - dt="$(date -u -r "$1" "$fmt")" + dt="$(exec /usr/bin/env date -u -r "$1" "$fmt")" else - dt="$(date -u -d "$1" "$fmt")" + dt="$(exec /usr/bin/env date -u -d "$1" "$fmt")" fi local F= T= N= diff --git a/sh/oshi b/sh/oshi index 70dc62d..82a9f8d 100755 --- a/sh/oshi +++ b/sh/oshi @@ -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 __oshi() { ### @oshi ### upload files (or stdin) to [oshi.at.](https://oshi.at) diff --git a/sh/oxo b/sh/oxo index f55d466..03a6901 100755 --- a/sh/oxo +++ b/sh/oxo @@ -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 # **TL;DR RULES:** # * no executables (for the most part) diff --git a/sh/pause b/sh/pause index 5587405..486d550 100755 --- a/sh/pause +++ b/sh/pause @@ -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 ### @ pause ### pause — the companion script of [`confirm`.](#confirm) diff --git a/sh/pegg b/sh/pegg index 2d04b98..dbdf2d5 100755 --- a/sh/pegg +++ b/sh/pegg @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash -hush +zsh pegg() { ### @- ### download and (pip) install a Python "egg" from a project on GitHub, diff --git a/sh/permit b/sh/permit index 979a016..910e288 100755 --- a/sh/permit +++ b/sh/permit @@ -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 __permit_hex() { if xxd -l 0 2>/dev/null; then diff --git a/sh/pippy b/sh/pippy index 2b0d29c..6922ca4 100755 --- a/sh/pippy +++ b/sh/pippy @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash -hush +zsh pippy() { ### @- ### install Python packages using pip, diff --git a/sh/pre b/sh/pre index fb425ad..164e03f 100755 --- a/sh/pre +++ b/sh/pre @@ -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 pre() { ### @- ### dump all the `#define`s that `$CC $CPPFLAGS $CFLAGS $LDFLAGS` would result in. diff --git a/sh/psbm b/sh/psbm index 5ef8969..f2082f8 100755 --- a/sh/psbm +++ b/sh/psbm @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh YES_BB_AWK +# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh YES_BB_AWK psbm() { ### @- ### display and order processes by their memory usage ascending, and their sum. @@ -10,7 +10,7 @@ psbm() { ### @- ### 199.95M 1060 chromium ### ``` [ -z "$MSYSTEM" ] || { printf "%s\n" "$0: unsupported on MSYS2" >&2; return 1; } - ps axco rss,pid,command | awk ' + /usr/bin/env ps axco rss,pid,command | awk ' NR>1&&$1>0{t+=$1;printf("%8.2fM %7d %s\n",$1/1024,$2,$3)} END{printf("%8.2fM\n",t/1024)} ' | sort -n diff --git a/sh/randir b/sh/randir index 95683b2..c447e89 100755 --- a/sh/randir +++ b/sh/randir @@ -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 # works with busybox. diff --git a/sh/recolor b/sh/recolor index fe1ff0b..3f957f3 100755 --- a/sh/recolor +++ b/sh/recolor @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh +# compat: +ash +bash +dash -hush +zsh __recolor_install() { ForegroundColour() { recolor RAW 10 "$@"; } diff --git a/sh/rot13 b/sh/rot13 index 613b814..04f4688 100755 --- a/sh/rot13 +++ b/sh/rot13 @@ -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 # works with busybox tr. diff --git a/sh/running b/sh/running index 3d6f3a2..e017d85 100755 --- a/sh/running +++ b/sh/running @@ -1,5 +1,5 @@ #!/usr/bin/env sh -# compat: +ash +bash +dash +zsh YES_BB_AWK +# compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh YES_BB_AWK # probably not compatible with busybox ps because its column 2 isn't PID. @@ -21,7 +21,7 @@ running() { ### @- WIP # argumentless flags accepted by coreutils: # a c d e f g h j l m n r s t u v w x A F H L M N P S T V X Z - ps -f | awk -v cmd=$cmd -v pid=$pid ' + /usr/bin/env ps -f | awk -v cmd=$cmd -v pid=$pid ' NR==1{ s=index($0,"COMMAND") s=s?s:index($0,"CMD")