1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-09-19 14:24:07 -07:00

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

This commit is contained in:
Connor Olding 2024-07-22 06:54:25 -07:00
parent f31911ffd6
commit 9f6b2e9bb8
16 changed files with 20 additions and 18 deletions

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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`.

2
sh/bak
View file

@ -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.

View file

@ -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)
### ```

View file

@ -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,

2
sh/bin
View file

@ -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.

View file

@ -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
(: </dev/udp/localhost/0) 2>&- && net=y || net=
[ $'' ] && r=$(printf \\r) || r=$'\r'

View file

@ -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,

View file

@ -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.

View file

@ -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; }

View file

@ -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.

View file

@ -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

View file

@ -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 ))
}

View file

@ -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