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 2)
This commit is contained in:
parent
9f6b2e9bb8
commit
c4d041c82a
21 changed files with 27 additions and 23 deletions
|
@ -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
4
sh/dfu
|
@ -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
2
sh/e
|
@ -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
2
sh/ea
|
@ -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
|
||||
|
|
2
sh/echo2
2
sh/echo2
|
@ -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.
|
||||
|
|
2
sh/feud
2
sh/feud
|
@ -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
2
sh/ff
|
@ -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
|
||||
|
|
2
sh/ghmd
2
sh/ghmd
|
@ -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.
|
||||
|
|
3
sh/glug
3
sh/glug
|
@ -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.
|
||||
|
|
3
sh/grab
3
sh/grab
|
@ -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
|
||||
|
|
4
sh/grop
4
sh/grop
|
@ -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
|
||||
|
|
4
sh/grop4
4
sh/grop4
|
@ -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
2
sh/has
|
@ -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
|
||||
|
|
2
sh/have
2
sh/have
|
@ -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
2
sh/hex
|
@ -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
2
sh/ify
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
2
sh/isup
2
sh/isup
|
@ -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.
|
||||
|
|
2
sh/join2
2
sh/join2
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue