mirror of
https://github.com/notwa/rc
synced 2024-11-05 02:29:06 -08:00
add compatibility flags for a bunch of scripts (part 3)
This commit is contained in:
parent
c4d041c82a
commit
7c9482c02c
17 changed files with 25 additions and 26 deletions
|
@ -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;;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 "$@"
|
||||
|
|
2
sh/note
2
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.
|
||||
|
|
8
sh/now
8
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=
|
||||
|
|
2
sh/oshi
2
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)
|
||||
|
|
2
sh/oxo
2
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)
|
||||
|
|
2
sh/pause
2
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)
|
||||
|
|
2
sh/pegg
2
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,
|
||||
|
|
|
@ -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
|
||||
|
|
2
sh/pippy
2
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,
|
||||
|
|
2
sh/pre
2
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.
|
||||
|
|
4
sh/psbm
4
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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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 "$@"; }
|
||||
|
|
2
sh/rot13
2
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.
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue