mirror of
https://github.com/notwa/rc
synced 2024-11-12 15:59:02 -08:00
first pass over sh: improve compatibility, fix stuff
This commit is contained in:
parent
5eaf74401e
commit
04e890db1b
55 changed files with 246 additions and 100 deletions
8
sh/arith
8
sh/arith
|
@ -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 "$@"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env false
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# NO_DASH
|
||||
|
||||
whoa=(
|
||||
-Wall
|
||||
|
|
2
sh/aur
2
sh/aur
|
@ -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
|
||||
|
||||
|
|
|
@ -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
6
sh/bak
|
@ -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
|
||||
}
|
||||
|
|
5
sh/baks
5
sh/baks
|
@ -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
4
sh/bin
|
@ -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"
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
cdbusiest() {
|
||||
dbusiest | read -r c d
|
||||
[ -z $c ] && return 1
|
||||
<<<"$c $d"
|
||||
printf "%s\n" "$c $d"
|
||||
cd $d
|
||||
}
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/zsh
|
||||
# YES_ZSH
|
||||
# script to make sense of compand's parameters
|
||||
# YES_ZSH
|
||||
|
||||
compandy() {
|
||||
if [ $# -eq 0 ]; then
|
||||
|
|
87
sh/compile
87
sh/compile
|
@ -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
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# NO_DASH
|
||||
|
||||
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||
confirm() {
|
||||
|
|
|
@ -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}'
|
||||
|
|
2
sh/cutv
2
sh/cutv
|
@ -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; }
|
||||
|
|
4
sh/days
4
sh/days
|
@ -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; }
|
||||
|
|
|
@ -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
2
sh/dfu
|
@ -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; }
|
||||
|
|
6
sh/disf
6
sh/disf
|
@ -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
2
sh/e
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env zsh
|
||||
# YES_ZSH
|
||||
# NO_BASH
|
||||
# NO_DASH
|
||||
|
||||
e() {
|
||||
local editor=(${=EDITOR})
|
||||
|
|
4
sh/ea
4
sh/ea
|
@ -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"
|
||||
|
|
2
sh/echo2
2
sh/echo2
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
|
||||
echo2() {
|
||||
local IFS=" "
|
||||
|
|
|
@ -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
2
sh/ff
|
@ -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
2
sh/has
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
|
||||
has() {
|
||||
if [ -n "$ZSH_VERSION" ]; then
|
||||
|
|
5
sh/hex
5
sh/hex
|
@ -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
2
sh/ify
|
@ -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; }
|
||||
|
|
|
@ -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.
|
||||
|
|
4
sh/isup
4
sh/isup
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/zsh
|
||||
# YES_ZSH
|
||||
# NO_BASH
|
||||
# NO_DASH
|
||||
|
||||
# TODO: damned substrings. rewrite to be semi-portable.
|
||||
|
||||
isup() {
|
||||
local c
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
2
sh/note
2
sh/note
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
|
||||
note() {
|
||||
local IFS=" "
|
||||
|
|
10
sh/now
10
sh/now
|
@ -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}"
|
||||
}
|
||||
|
|
2
sh/pacbm
2
sh/pacbm
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
|
||||
pacbm() {
|
||||
expac -s '%m %n' | awk '
|
||||
|
|
8
sh/pause
8
sh/pause
|
@ -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 "$@"
|
||||
|
|
4
sh/pegg
4
sh/pegg
|
@ -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; }
|
||||
|
|
2
sh/pippy
2
sh/pippy
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env
|
||||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
|
||||
#. ~/sh/maybesudo
|
||||
|
|
4
sh/pre
4
sh/pre
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
|
||||
pre() {
|
||||
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||
|
|
3
sh/psbm
3
sh/psbm
|
@ -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)}
|
||||
|
|
|
@ -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 "$@"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
|
||||
refresh() {
|
||||
hash -r
|
||||
|
|
6
sh/sc
6
sh/sc
|
@ -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 "$@"
|
||||
|
|
|
@ -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' \
|
||||
|
|
10
sh/scropt
10
sh/scropt
|
@ -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 "$@"
|
||||
|
|
|
@ -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
11
sh/slit
|
@ -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 "$@"
|
||||
|
|
15
sh/slitt
15
sh/slitt
|
@ -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
2
sh/sum
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
|
||||
sum() {
|
||||
local sum=0
|
||||
|
|
5
sh/sv
5
sh/sv
|
@ -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]}
|
||||
'
|
||||
|
|
9
sh/tpad
9
sh/tpad
|
@ -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
|
||||
}
|
||||
|
||||
|
|
2
sh/trash
2
sh/trash
|
@ -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; }
|
||||
|
|
5
sh/trunc
5
sh/trunc
|
@ -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}'
|
||||
}
|
||||
|
|
|
@ -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
2
sh/wat
|
@ -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
14
sh/wipe
|
@ -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 "$@"
|
||||
|
|
Loading…
Reference in a new issue