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

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

This commit is contained in:
Connor Olding 2024-07-22 17:54:54 -07:00
parent 9f6b2e9bb8
commit c4d041c82a
21 changed files with 27 additions and 23 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
dedupe() ( ### @- copy a directory, but make hard/softlinks for identical files.
# Copyright (C) 2022 Connor Olding

4
sh/dfu
View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh
# compat: +ash +bash +dash +zsh YES_BB_AWK YES_OT_AWK
# compat: -ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh YES_BB_AWK YES_OT_AWK
dfu() { ### @-
### pretty-print `df` in GiB.
@ -11,6 +11,8 @@ dfu() { ### @-
### / 17.20 23.22 6.01 1.27
### ```
# FIXME: -x is not an option in busybox df.
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
df -xtmpfs | awk '
NR==1{printf"%-20s %7s %7s %7s %7s\n","Filesystem","Used","Max","Left","Misc"}

2
sh/e
View file

@ -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
e() { ### @-
### wrap around `$EDITOR` to run it as root if necessary.

2
sh/ea
View file

@ -1,6 +1,6 @@
#!/usr/bin/env sh
# remote file access (http file-sharing shenanigans)
# compat: +ash +bash +dash +zsh
# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh
__ea_curl() {
curl -q --no-progress-meter 127.255.255.255 >/dev/null 2>&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
echo2() { ### @-
### print arguments joined by spaces to stderr without parsing anything.

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
### @feud - parse command-line arguments, mapping short-flags to variable names.
### **NOTE:** the API is still experimental and will undergo major changes.

2
sh/ff
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
ff() { ### @-
### select a file from a given or current directory using

View file

@ -2,7 +2,7 @@
# ghmd - format GitHub markdown
# via: https://leahneukirchen.org/dotfiles/.zshrc
# example: ghmd < README.md > README.html
# compat: +ash +bash +dash +zsh
# compat: +ash +bash +dash +hush -ksh +mksh +oksh +osh +posh +yash +zsh
ghmd() { ### @-
### convert a markdown file to HTML in the style of GitHub.

View file

@ -1,5 +1,6 @@
#!/usr/bin/env dash
# compat: +ash +bash +dash +zsh
# compat: +ash +bash +dash -hush -ksh -mksh -oksh -osh -posh +yash +zsh
# NOTE: many shells work, but some of them fail to restore tty settings.
# fuck termcap, all my homies hate termcap.
glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.

View file

@ -1,5 +1,6 @@
#!/usr/bin/env sh
# compat: +ash +bash +dash +zsh
# compat: -ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh
# FIXME: `find -delete` is not POSIX (fails on busybox).
__grab() { ### @grab - download a file from my site and verify its integrity by its [minisign](https://github.com/jedisct1/minisign/) signature.
[ -z "${ZSH_VERSION}" ] || emulate sh

View file

@ -1,12 +1,12 @@
#!/usr/bin/env sh
# compat: +ash +bash +dash +zsh
# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh
# TODO: check for existence of grep -P; write a perl-based fallback.
grop() { ### @- invoke grep with `-oP`.
### **NOTE:** there also exists a grop(1) program provided by
### the *grop* package that i don't use.
argc $# -ge 1 grop || return
grep -oP -- "$@"
/usr/bin/env grep -oP -- "$@"
}
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2

View file

@ -1,8 +1,8 @@
#!/usr/bin/env sh
# compat: +ash +bash +dash +zsh
# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh
grop4() { ### @- [`grop`](#grop) for IPv4s.
grep -oP -- '(?<=^|[^\d.])((0|1\d\d|2[0-4]\d|25[0-5]|[1-9]\d?)\.((?2))\.((?2))\.((?2)))(?=$|[^\d.])'
/usr/bin/env grep -oP -- '(?<=^|[^\d.])((0|1\d\d|2[0-4]\d|25[0-5]|[1-9]\d?)\.((?2))\.((?2))\.((?2)))(?=$|[^\d.])'
}
[ -n "${preload+-}" ] || grop4 "$@"

2
sh/has
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
has() { ### @- [`have`,](#have) silently.
if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi

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
have() { ### @- print the result of `which` if the program is found, else simply return 1.
### ```

2
sh/hex
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.

2
sh/ify
View file

@ -1,5 +1,5 @@
#!/usr/bin/sh
# compat: +ash +bash +dash +zsh
# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh
ify() { ### @-
### pipe one command through another, so you can still pass arguments to the former.

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
is_empty() { ### @-
### return 0 if the directory given by argument is empty.

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
isup() { ### @-
### return 0 if a given website returns a 2xx HTTP code.

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
join2() { ### @- join every other line.
# TODO: argc, also better interface that allows n file inputs without stdin.

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
lsarchive() { ### @- list the contents of an archive file in one of many formats.
### borrowed from [prezto.](https://github.com/sorin-ionescu/prezto)

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
__maybesudo() { ### @maybesudo
### mimic certain features of `sudo` for systems without it installed.