mirror of
https://github.com/notwa/rc
synced 2024-12-21 21:49:40 -08:00
add compatibility flags for a bunch of scripts (part 1)
This commit is contained in:
parent
f31911ffd6
commit
9f6b2e9bb8
16 changed files with 20 additions and 18 deletions
2
sh/argc
2
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
|
||||
|
|
2
sh/arith
2
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.
|
||||
|
|
2
sh/askey
2
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
|
||||
|
|
|
@ -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
2
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.
|
||||
|
|
|
@ -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)
|
||||
### ```
|
||||
|
|
2
sh/baks
2
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,
|
||||
|
|
2
sh/bin
2
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.
|
||||
|
|
4
sh/burl
4
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
|
||||
(: </dev/udp/localhost/0) 2>&- && net=y || net=
|
||||
[ $'' ] && r=$(printf \\r) || r=$'\r'
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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.
|
||||
|
|
2
sh/dated
2
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
|
||||
|
|
3
sh/days
3
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 ))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue