1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2025-02-05 07:43:22 -08:00

add compatibility flags for a bunch of scripts (part 3)

This commit is contained in:
Connor Olding 2024-07-23 00:04:57 -07:00
parent c4d041c82a
commit 7c9482c02c
17 changed files with 25 additions and 26 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env dash #!/usr/bin/env dash
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash -hush -ksh +mksh +oksh +osh +posh +yash +zsh
minutemaid() { ### @- minutemaid() { ### @-
### check if the current minute is divisible by a given number, ### check if the current minute is divisible by a given number,
@ -32,7 +32,7 @@ minutemaid() { ### @-
while getopts 'o:h' name; do while getopts 'o:h' name; do
case $name in case $name in
o) offset="$OPTARG";; o) offset="$OPTARG";;
?) local fd=0 ?) local fd=0 # FIXME: this also matches single-character filenames!
[ $name = h ] && fd=1 || fd=2 [ $name = h ] && fd=1 || fd=2
printf '%s\n' "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd printf '%s\n' "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd
[ $name = h ] && return 0 || return 1;; [ $name = h ] && return 0 || return 1;;

View file

@ -1,5 +1,5 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
# compat: -ash -bash -dash +zsh # compat: -ash -bash -dash -hush -ksh -mksh -oksh -osh -posh -yash +zsh
monitor() { ### @- monitor() { ### @-
### this is [watch(1)](https://www.man7.org/linux/man-pages/man1/watch.1.html) ### this is [watch(1)](https://www.man7.org/linux/man-pages/man1/watch.1.html)

View file

@ -1,9 +1,8 @@
#!/usr/bin/env bash #!/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. # borrowed from leah2's dotfiles.
local i=
for i in {0..255}; do for i in {0..255}; do
printf '\e[48;5;%dm\e[38;5;15m %03d ' $i $i printf '\e[48;5;%dm\e[38;5;15m %03d ' $i $i
printf '\e[33;5;0m\e[38;5;%dm %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' [ "$(( i+1 <= 16 ? (i+1) % 16 : ( (i+1)-16) % 36 ))" = 0 ] && printf '\e[0m\n'
done done
return 0 return 0
} )
[ -n "${preload+-}" ] || morecolors "$@" [ -n "${preload+-}" ] || morecolors "$@"

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh
note() { ### @- note() { ### @-
### act like [`echo2`,](#echo2) but use a bright color to stand out more. ### act like [`echo2`,](#echo2) but use a bright color to stand out more.

8
sh/now
View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh
now() { ### @- now() { ### @-
### print a date-time (UTC) in a sortable format. ### print a date-time (UTC) in a sortable format.
@ -17,11 +17,11 @@ now() { ### @-
local dt= fmt='+%F_%T_%N' local dt= fmt='+%F_%T_%N'
if [ -z "$1" ]; then if [ -z "$1" ]; then
dt="$(date -u "$fmt")" dt="$(exec /usr/bin/env date -u "$fmt")"
elif [ -e "$1" ]; then elif [ -e "$1" ]; then
dt="$(date -u -r "$1" "$fmt")" dt="$(exec /usr/bin/env date -u -r "$1" "$fmt")"
else else
dt="$(date -u -d "$1" "$fmt")" dt="$(exec /usr/bin/env date -u -d "$1" "$fmt")"
fi fi
local F= T= N= local F= T= N=

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash +hush +ksh +mksh +oksh -osh +posh +yash +zsh
__oshi() { ### @oshi __oshi() { ### @oshi
### upload files (or stdin) to [oshi.at.](https://oshi.at) ### upload files (or stdin) to [oshi.at.](https://oshi.at)

2
sh/oxo
View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh
# **TL;DR RULES:** # **TL;DR RULES:**
# * no executables (for the most part) # * no executables (for the most part)

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash -hush +ksh +mksh -oksh -osh +posh +yash +zsh
### @ pause ### @ pause
### pause — the companion script of [`confirm`.](#confirm) ### pause — the companion script of [`confirm`.](#confirm)

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash -hush +zsh
pegg() { ### @- pegg() { ### @-
### download and (pip) install a Python "egg" from a project on GitHub, ### download and (pip) install a Python "egg" from a project on GitHub,

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh
__permit_hex() { __permit_hex() {
if xxd -l 0 2>/dev/null; then if xxd -l 0 2>/dev/null; then

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash -hush +zsh
pippy() { ### @- pippy() { ### @-
### install Python packages using pip, ### install Python packages using pip,

2
sh/pre
View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh
pre() { ### @- pre() { ### @-
### dump all the `#define`s that `$CC $CPPFLAGS $CFLAGS $LDFLAGS` would result in. ### dump all the `#define`s that `$CC $CPPFLAGS $CFLAGS $LDFLAGS` would result in.

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/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() { ### @- psbm() { ### @-
### display and order processes by their memory usage ascending, and their sum. ### display and order processes by their memory usage ascending, and their sum.
@ -10,7 +10,7 @@ psbm() { ### @-
### 199.95M 1060 chromium ### 199.95M 1060 chromium
### ``` ### ```
[ -z "$MSYSTEM" ] || { printf "%s\n" "$0: unsupported on MSYS2" >&2; return 1; } [ -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)} NR>1&&$1>0{t+=$1;printf("%8.2fM %7d %s\n",$1/1024,$2,$3)}
END{printf("%8.2fM\n",t/1024)} END{printf("%8.2fM\n",t/1024)}
' | sort -n ' | sort -n

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh
# works with busybox. # works with busybox.

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# compat: +ash +bash +dash +zsh # compat: +ash +bash +dash -hush +zsh
__recolor_install() { __recolor_install() {
ForegroundColour() { recolor RAW 10 "$@"; } ForegroundColour() { recolor RAW 10 "$@"; }

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/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. # works with busybox tr.

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/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. # probably not compatible with busybox ps because its column 2 isn't PID.
@ -21,7 +21,7 @@ running() { ### @- WIP
# argumentless flags accepted by coreutils: # 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 # 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{ NR==1{
s=index($0,"COMMAND") s=index($0,"COMMAND")
s=s?s:index($0,"CMD") s=s?s:index($0,"CMD")