1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-06-24 00:17:11 -07:00

first pass over sh: improve compatibility, fix stuff

This commit is contained in:
Connor Olding 2021-07-29 05:44:12 -07:00
parent 5eaf74401e
commit 04e890db1b
55 changed files with 246 additions and 100 deletions

View File

@ -1,8 +1,14 @@
#!/usr/bin/env zsh
# YES_ZSH
# YES_BASH
# YES_DASH
# though technically compatible with other shells,
# extra functionality is through zsh's extended arithmetic functions.
arith() {
<<<"$(($@))"
# <<<"$(($@))"
printf "%s\n" "$(($@))"
}
[ "${SOURCING:-0}" -gt 0 ] || arith "$@"

View File

@ -1,5 +1,7 @@
#!/usr/bin/env false
# YES_ZSH
# YES_BASH
# NO_DASH
whoa=(
-Wall

2
sh/aur
View File

@ -2,6 +2,8 @@
# http://aur.sh with massive feature creep
# YES_ZSH
# TODO: check compatibility with bash and dash.
aur() {
trap 'exit 1' SIGINT SIGTERM

View File

@ -1,5 +1,9 @@
#!/usr/bin/env zsh
# YES_ZSH
# NO_BASH
# NO_DASH
# TODO: portable way of dodging aliases to allow other shell support?
autosync() {
target="$1"

6
sh/bak
View File

@ -1,14 +1,16 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
bak() {
[ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
local ret=0
for f; do
if [ -s "$f.bak" ]; then
if [ -e "$f.bak" ]; then
bak "$f.bak" || ret=1
fi
cp -p "$f" "$f.bak"
cp -p "$f" "$f.bak" || ret=1
done
return $ret
}

View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
#SOURCING=$((SOURCING+1))
#. ~/sh/note # FIXME: don't do this?
@ -11,7 +13,8 @@ baks() { # backup, timestamped
local now="$(date -u '+%y-%m-%d_%H-%M-%S')"
local bak="$fp.$now.bak"
if [ -s "$bak" ]; then
note "how in the hell?" "$bak" "already exists"
#note "how in the hell?" "$bak" "already exists"
printf "%s %s %s\n" "how in the hell?" "$bak" "already exists"
ret=1
fi
cp -p "$fp" "$bak" || ret=1

4
sh/bin
View File

@ -1,9 +1,11 @@
#!/usr/bin/env zsh
# YES_ZSH
# YES_BASH
# YES_DASH
bin() {
local a="$(($@))"
let 'a=(((((((((((((a + 0x0FFFFF80) & 0x1000007F) + 0x00FFFFC0) & 0x1100003F) + 0x000FFFE0) & 0x1110001F) + 0x0000FFF0) & 0x1111000F) + 0x00000FF8) & 0x11111007) + 0x000000FC) & 0x11111103) + 0x0000000E) & 0x11111111'
a="$(((((((((((((((a + 0x0FFFFF80) & 0x1000007F) + 0x00FFFFC0) & 0x1100003F) + 0x000FFFE0) & 0x1110001F) + 0x0000FFF0) & 0x1111000F) + 0x00000FF8) & 0x11111007) + 0x000000FC) & 0x11111103) + 0x0000000E) & 0x11111111))"
printf "%08X\n" "$a"
}

View File

@ -4,7 +4,7 @@
cdbusiest() {
dbusiest | read -r c d
[ -z $c ] && return 1
<<<"$c $d"
printf "%s\n" "$c $d"
cd $d
}

View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
# YES_ZSH
# YES_BASH
# NO_DASH
colors() {
printf "\e[%dm$(printf " \e[%dm mV \e[40m" {4,10}{0..7})\e[0m\n" {3,9}{0..7}

View File

@ -1,6 +1,6 @@
#!/usr/bin/zsh
# YES_ZSH
# script to make sense of compand's parameters
# YES_ZSH
compandy() {
if [ $# -eq 0 ]; then

View File

@ -1,5 +1,7 @@
#!/usr/bin/env zsh
# YES_ZSH
# NO_BASH
# NO_DASH
# I'll just leave this here...
__setup_clang_ubuntu() {
@ -54,51 +56,54 @@ compile() {
local winkit
printf "%s\n" "/c/Program Files (x86)/Windows Kits/"*(on/N[1]) | read -r winkit
[ -n "$winkit" ] || { echo "failed glob; missing winkit" >&2; return 1 }
printf "%s\n" "$winkit/Lib/"*(On/N[1]) | read -r winkit
[ -n "$winkit" ] || { echo "failed glob; missing winkit" >&2; return 1 }
[ -z "$winkit" ] || printf "%s\n" "$winkit/Lib/"*(On/N[1]) | read -r winkit
# detect MSVC.
local clarch
local arch
local msvc_dig_deep
[ "$MSYSTEM" = MINGW64 ] && clarch="/amd64" || clarch=""
[ "$MSYSTEM" = MINGW64 ] && arch="x64" || arch="x86"
if [ -d "/c/Program Files (x86)/Microsoft Visual Studio" ]; then # 2017+
printf "%s\n" "/c/Program Files (x86)/Microsoft Visual Studio/20"*(On/N[1]) | read vc
printf "%s\n" "$vc"/*/VC | read vc
printf "%s\n" "$vc/Tools/MSVC/"*(On/N[1]) | read vc
msvc_dig_deep="yes"
else # older versions
printf "%s\n" "/c/Program Files (x86)/Microsoft Visual Studio "*(On/N[1]) | read vc
vc="$vc/VC"
fi
if [ -z "$winkit" ]; then
#echo "failed glob; missing winkit" >&2
:
else
# detect MSVC.
local clarch
local arch
local msvc_dig_deep
[ "$MSYSTEM" = MINGW64 ] && clarch="/amd64" || clarch=""
[ "$MSYSTEM" = MINGW64 ] && arch="x64" || arch="x86"
if [ -d "/c/Program Files (x86)/Microsoft Visual Studio" ]; then # 2017+
printf "%s\n" "/c/Program Files (x86)/Microsoft Visual Studio/20"*(On/N[1]) | read vc
printf "%s\n" "$vc"/*/VC | read vc
printf "%s\n" "$vc/Tools/MSVC/"*(On/N[1]) | read vc
msvc_dig_deep="yes"
else # older versions
printf "%s\n" "/c/Program Files (x86)/Microsoft Visual Studio "*(On/N[1]) | read vc
vc="$vc/VC"
fi
# setup MSVC.
if [ -n "$msvc_dig_deep" ] && [ -e "$vc/bin/Host$arch/$arch/cl" ]; then
cl="$vc/bin/Host$arch/$arch/cl"
export PATH="$PATH:$vc/bin/Host$arch/$arch"
export LIB="$(cygpath -w "$vc/lib/$arch")"
export LIBPATH="$(cygpath -w "$vc/lib/$arch")"
elif [ -d "$vc/bin$clarch" ] && [ -e "$vc/bin$clarch/$cl" ]; then
cl="$vc/bin$clarch/cl"
export PATH="$PATH:$vc/bin$clarch"
export LIB="$(cygpath -w "$vc/LIB$clarch")"
export LIBPATH="$(cygpath -w "$vc/LIB$clarch")"
fi
# setup MSVC.
if [ -n "$msvc_dig_deep" ] && [ -e "$vc/bin/Host$arch/$arch/cl" ]; then
cl="$vc/bin/Host$arch/$arch/cl"
export PATH="$PATH:$vc/bin/Host$arch/$arch"
export LIB="$(cygpath -w "$vc/lib/$arch")"
export LIBPATH="$(cygpath -w "$vc/lib/$arch")"
elif [ -d "$vc/bin$clarch" ] && [ -e "$vc/bin$clarch/$cl" ]; then
cl="$vc/bin$clarch/cl"
export PATH="$PATH:$vc/bin$clarch"
export LIB="$(cygpath -w "$vc/LIB$clarch")"
export LIBPATH="$(cygpath -w "$vc/LIB$clarch")"
fi
# finish up.
if [ -n "$cl" ]; then
export INCLUDE="$(cygpath -w "$vc/INCLUDE")"
export INCLUDE="$INCLUDE;$(cygpath -w "${winkit/Lib/Include}/ucrt")"
export LIB="$LIB;$(cygpath -w "$winkit/um/$arch")"
export LIB="$LIB;$(cygpath -w "$winkit/ucrt/$arch")"
# finish up.
if [ -n "$cl" ]; then
export INCLUDE="$(cygpath -w "$vc/INCLUDE")"
export INCLUDE="$INCLUDE;$(cygpath -w "${winkit/Lib/Include}/ucrt")"
export LIB="$LIB;$(cygpath -w "$winkit/um/$arch")"
export LIB="$LIB;$(cygpath -w "$winkit/ucrt/$arch")"
for d in "${(@s/;/)INCLUDE}"; do
clang_flags+=(-I"$d")
done
# ignore MSVC's non-standard deprecation warnings.
clang_flags+=(-D_CRT_SECURE_NO_WARNINGS)
for d in "${(@s/;/)INCLUDE}"; do
clang_flags+=(-I"$d")
done
# ignore MSVC's non-standard deprecation warnings.
clang_flags+=(-D_CRT_SECURE_NO_WARNINGS)
fi
fi
fi

View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
# YES_ZSH
# YES_BASH
# NO_DASH
if [ -n "${ZSH_VERSION:-}" ]; then
confirm() {

View File

@ -1,7 +1,10 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
countdiff() {
[ $# -gt 1 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
[ $# -le 2 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
git --no-pager diff --stat --no-color --no-index "$1" "$2" \
| awk '/changed/{print $4+$6;a=1}END{if(!a)print 0}'

View File

@ -1,5 +1,7 @@
#!/usr/bin/env zsh
# YES_ZSH
# NO_BASH
# NO_DASH
cutv() {
[ $# -le 4 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }

View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
days() {
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }

View File

@ -1,5 +1,7 @@
#!/usr/bin/env zsh
# YES_ZSH
# NO_BASH
# NO_DASH
dbusiest() {
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }

2
sh/dfu
View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
dfu() {
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }

View File

@ -1,6 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# disassembles a function given its symbolic name.
# YES_ZSH
# YES_BASH
# YES_DASH
# TODO: actually test that this works with dash.
function disf() {
[ $# -le 2 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }

2
sh/e
View File

@ -1,5 +1,7 @@
#!/usr/bin/env zsh
# YES_ZSH
# NO_BASH
# NO_DASH
e() {
local editor=(${=EDITOR})

4
sh/ea
View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash
#!/usr/bin/env false
# remote file access (http file-sharing shenanigans)
# YES_ZSH
# YES_BASH
# YES_DASH
_REMOTE_DOMAIN="https://eaguru.guru"
_REMOTE_DIR="t"

View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
echo2() {
local IFS=" "

View File

@ -1,7 +1,10 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
explore() {
[ -n "$MSYSTEM" ] || { printf "%s\n" "$0: only for MSYS2" >&2; return 1; }
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
explorer "$(cygpath -w "${1:-.}")"
}

2
sh/ff
View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
ff() {
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }

2
sh/has
View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
has() {
if [ -n "$ZSH_VERSION" ]; then

5
sh/hex
View File

@ -1,5 +1,10 @@
#!/usr/bin/env zsh
# YES_ZSH
# YES_BASH
# YES_DASH
# though technically compatible with other shells,
# extra functionality is through zsh's extended arithmetic functions.
hex() {
printf "%08X\n" "$(($@))"

2
sh/ify
View File

@ -1,5 +1,7 @@
#!/usr/bin/sh
# YES_ZSH
# YES_BASH
# YES_DASH
ify() {
[ $# -ge 2 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }

View File

@ -1,9 +1,11 @@
#!/usr/bin/env bash
# YES_ZSH
# YES_BASH
# NO_DASH
is_empty() {
while read -r; do
[ ! -d "$REPLY" ] && [ -s "$REPLY" ] && return 1
while read -r f; do
[ ! -d "$f" ] && [ -s "$f" ] && return 1
done < <(find ${1:-.})
# TODO: done < <(find ${1:-.} -type f -print -quit)
# this needs to skip empty files as well.

View File

@ -1,5 +1,9 @@
#!/usr/bin/zsh
# YES_ZSH
# NO_BASH
# NO_DASH
# TODO: damned substrings. rewrite to be semi-portable.
isup() {
local c

View File

@ -1,10 +1,12 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
maybesudo_() {
local name
local env_cleanup=0
while getopts ':AEHKPSVbhiklnsvC:U:g:p:r:t:u:' name; do
while getopts :AEHKPSVbhiklnsvC:U:g:p:r:t:u: name; do
case $name in
K|V|k)
# K: sure kill
@ -122,6 +124,8 @@ maybesudo_() {
else
# run it in a subshell so it won't affect ours.
# TODO: run through env anyway for consistency.
# (`maybesudo export` should fail)
( "$@"; )
fi

View File

@ -1,17 +1,19 @@
#!/usr/bin/env zsh
#!/usr/bin/env dash
# crontab usage:
#* * * * * minutemaid 9 cd repo && git pull # runs every nine minutes
#* * * * * minutemaid 9 ~/work/do_my_bidding # runs every nine minutes
# YES_ZSH
# YES_BASH
# YES_DASH
minutemaid() {
local offset=0 opt=
while getopts 'o:h' opt; do
case $opt in
local offset=0 name
while getopts 'o:h' name; do
case $name in
o) offset="$OPTARG";;
?) local fd=0
[ $opt = h ] && fd=0 || fd=2
echo -E "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd
[ $opt = h ] && return 0 || return 1;;
[ $name = h ] && fd=1 || fd=2
printf "%s\n" "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd
[ $name = h ] && return 0 || return 1;;
esac
done
shift $((OPTIND-1))
@ -20,13 +22,10 @@ minutemaid() {
shift
local sec="$(date +%s)"
let min=sec/60+offset
let mod=min%interval
local min="$((sec/60+offset))"
local mod="$((min%interval))"
if [ $# -gt 0 ]; then
local cmd="${1}"
shift
[ $mod -eq 0 ] && "$cmd" "$@"
[ $mod -ne 0 ] || "$@"
else
[ $mod -eq 0 ] && return 0 || return 1
fi

View File

@ -2,6 +2,10 @@
# the first expression is taken from this FAQ:
# https://perldoc.perl.org/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file%3f
# YES_ZSH
# YES_BASH
# YES_DASH
# TODO: what's the minimum version of perl required for this?
noccom() {
[ -s ~/opt/local/bin/noccom ] || cat > ~/opt/local/bin/noccom <<EOF

View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
note() {
local IFS=" "

10
sh/now
View File

@ -1,5 +1,9 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
# dash compatibility is not fully tested, but it's probably okay.
now() {
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
@ -32,8 +36,8 @@ now() {
M=${M#0*}
S=${S#0*}
local ms=
let 'ms=(H*60*60+M*60+S)*1000+N/1000000'
local ms
ms=$(((H*60*60+M*60+S)*1000+N/1000000))
ms=$(printf '%08i' $ms)
echo "${F}_${ms}"
}

View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
pacbm() {
expac -s '%m %n' | awk '

View File

@ -1,11 +1,13 @@
#!/usr/bin/env bash
# YES_ZSH
# YES_BASH
# NO_DASH
pause() {
[ -n "${ZSH_VERSION:-}" ] \
&& read -sk '?Press any key to continue
' || read -n1 -u 1 -sp 'Press any key to continue
'
&& read -sk '?Press any key to continue
' || read -n1 -u 1 -sp 'Press any key to continue
'
}
[ "${SOURCING:-0}" -gt 0 ] || pause "$@"

View File

@ -1,5 +1,9 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
# TODO: source pippy here? this may affect dash compatibility.
pegg() {
[ $# -ge 2 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }

View File

@ -1,4 +1,4 @@
#!/usr/bin/env
#!/usr/bin/env sh
# YES_ZSH
#. ~/sh/maybesudo

4
sh/pre
View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
pre() {
if [ -n "${ZSH_VERSION:-}" ]; then

View File

@ -1,7 +1,10 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
psbm() {
[ -z "$MSYSTEM" ] || { printf "%s\n" "$0: unsupported on MSYS2" >&2; return 1; }
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)}

View File

@ -1,8 +1,10 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
randir() {
find -maxdepth 1 -type d \( -path '/root' -prune -o -print \) | tail -n+2 | shuf | head -1
find -maxdepth 1 -type d \( -path '/root' -prune -o -print \) | tail -n+2 | shuf | head -n1
}
[ "${SOURCING:-0}" -gt 0 ] || randir "$@"

View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
refresh() {
hash -r

6
sh/sc
View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash
. ~/.ea # FIXME: don't do this? somehow?
SOURCING=$((SOURCING+1))
. ~/sh/ea # FIXME: don't do this? somehow?
SOURCING=$((SOURCING-1))
sc_shorten() {
REPLY="${1:2:2}${1:5:2}${1:8:2}${1:11:12}"
@ -59,4 +61,4 @@ sc() {
return 0
}
sc "$@"
[ "${SOURCING:-0}" -gt 0 ] || sc "$@"

View File

@ -1,7 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
scramble() {
[ $# -eq 0 ] || { printf "%s\n" "$0: does not take arguments" >&2; return 1; }
local eggs='s/@\(\w\)\(\w\)\(\w\)/@\3\1@\2/g'
sed \
-e 's/\b\w/&@/g' \

View File

@ -1,12 +1,16 @@
#!/usr/bin/env bash
# YES_ZSH
#SOURCING=$((SOURCING+1))
#. ~/sh/now # FIXME: don't do this?
#SOURCING=$((SOURCING-1))
scropt() {
local now=
which ~/sh/now 2>/dev/null >/dev/null && now=$(~/sh/now) || now=$(date +%F_%T)
local now=$(now)
[ $? -eq 0 ] || return $?
local fn="$HOME/play/$now.png"
scrot "$fn" -e "optipng -quiet \$f" "$@"
echo "$fn"
[ $? -eq 0 ] && echo "$fn" || return $?
}
[ "${SOURCING:-0}" -gt 0 ] || scropt "$@"

View File

@ -1,7 +1,10 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
similar() {
[ $# -eq 0 ] || { printf "%s\n" "$0: does not take arguments" >&2; return 1; }
awk '
{
i=0

11
sh/slit
View File

@ -1,9 +1,14 @@
#!/usr/bin/env zsh
# from https://github.com/sorin-ionescu/prezto/
#!/usr/bin/env dash
# YES_ZSH
# YES_BASH
# YES_DASH
slit() {
awk "{ print ${(j:,:):-\$${^@}} }"
[ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
awk "{ print $(printf ',$%s' $@ | cut -b2-) }"
# via: https://github.com/sorin-ionescu/prezto/
#awk "{ print ${(j:,:):-\$${^@}} }"
}
[ "${SOURCING:-0}" -gt 0 ] || slit "$@"

View File

@ -1,10 +1,17 @@
#!/usr/bin/env zsh
# via: https://github.com/sorin-ionescu/prezto/
# this version uses tabs for input/output field separators.
#!/usr/bin/env dash
# this version of slit uses tabs for input/output field separators.
# YES_ZSH
# YES_BASH
# YES_DASH
slitt() {
awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print ${(j:,:):-\$${^@}} }"
[ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
#echo "$@" | awk '{for(i=1;i<NF;i++)printf"$%s,",$(i);print"$"$NF}'
local fields="$(printf ',$%s' $@ | cut -b2-)"
awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print $fields }"
# via: https://github.com/sorin-ionescu/prezto/
#awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print ${(j:,:):-\$${^@}} }"
}
[ "${SOURCING:-0}" -gt 0 ] || slitt "$@"

2
sh/sum
View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
sum() {
local sum=0

5
sh/sv
View File

@ -1,7 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
sv() {
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
awk "-F${1:- }" '
NF>1{f[$1]=substr($0,length($1)+1+length(FS))}END{for(k in f)print k FS f[k]}
'

View File

@ -1,10 +1,11 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
tpad() {
while [ $# -gt 0 ]; do
gm convert -bordercolor "#000000FF" -border 1x1 "$1" "${1/.png/}.tt.png";
shift
for f; do
gm convert -bordercolor "#000000FF" -border 1x1 "$f" "${f%.png}.tt.png"
done
}

View File

@ -1,5 +1,7 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
trash() {
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }

View File

@ -1,7 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
trunc() {
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
COLUMNS=${COLUMNS:-$(tput cols)}
awk -vL=${1:-$COLUMNS} '{e=length>L?"…":"";print substr($0,0,L-(e?1:0)) e}'
}

View File

@ -1,5 +1,7 @@
#!/usr/bin/env zsh
# YES_ZSH
# NO_BASH
# NO_DASH
unscreen() {
local pids="$(screen -ls | fgrep "$1" | cut -d. -f1)"

2
sh/wat
View File

@ -1,5 +1,7 @@
#!/usr/bin/env zsh
# YES_ZSH
# NO_BASH
# NO_DASH
# wat - a better and recursive which/whence
# via: https://leahneukirchen.org/dotfiles/tools.html

14
sh/wipe
View File

@ -1,14 +1,20 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
wipe() {
# TODO: rename because wipe(1) already exists.
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
clear
clear # twice because mintty is weird
echo "\033[30m\033[107m"
printf "*%.0s" {1..$COLUMNS}
echo "\033[0m\n"
echo $'\033[30m\033[107m' | tr -d '$'
if [ -n "${ZSH_VERSION:-}" ]; then
printf '*%.0s' {1..$COLUMNS}
else
tput cols | awk '{for(i=0;i<$0;i++)printf "*"}'
fi
echo $'\033[0m\n' | tr -d '$'
}
[ "${SOURCING:-0}" -gt 0 ] || wipe "$@"