From fd83d41ab2e8415ca198047df4a7f08892f24d93 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Fri, 30 Jul 2021 17:57:08 -0700 Subject: [PATCH] add and restore some docstrings --- home/-shrc | 92 +++++++++++++++++++++++++++------------------------ home/bashrc | 3 +- home/zshrc | 38 +++++++++++++++------ sh/arith | 3 +- sh/aur | 5 ++- sh/autosync | 4 ++- sh/cdbusiest | 3 +- sh/colors | 4 ++- sh/compandy | 4 ++- sh/compile | 17 ++++++++-- sh/confirm | 11 ++++++ sh/days | 8 ++++- sh/dbusiest | 3 +- sh/dfu | 5 ++- sh/disf | 3 +- sh/document | 6 ++-- sh/e | 9 ++++- sh/has | 5 ++- sh/hex | 3 +- sh/ify | 11 +++++- sh/is_empty | 3 +- sh/isup | 3 +- sh/minutemaid | 12 +++++-- sh/monitor | 3 +- sh/noccom | 3 +- sh/now | 13 +++++++- sh/pacbm | 9 ++++- sh/pause | 9 ++++- sh/pre | 5 ++- sh/randir | 8 ++++- sh/rs | 6 ++-- sh/sc | 5 ++- sh/scramble | 5 ++- sh/screeny | 3 +- sh/scropt | 9 +++-- sh/slit | 3 +- sh/slitt | 5 +-- sh/sram | 3 +- sh/streamcrap | 33 ++++++++++++------ sh/sv | 12 ++++++- sh/tpad | 4 ++- sh/trunc | 3 +- sh/unscreen | 3 +- sh/wipe | 8 +++-- 44 files changed, 292 insertions(+), 115 deletions(-) diff --git a/home/-shrc b/home/-shrc index 644df83..16b24d9 100644 --- a/home/-shrc +++ b/home/-shrc @@ -5,7 +5,7 @@ # {{{1 utilities if [ -z "$ZSH_VERSION" ]; then - has() { # hardcode this function from ~/sh/has for convenience + has() { ### @- hardcoded here for convenience. which "$1" >/dev/null 2>&1 && which "$1" } fi @@ -21,7 +21,8 @@ else alias maybesudo="maybesudo_ " # allows aliases within the alias fi -ADDPATH() { +ADDPATH() { ### @ ADDPATH + ### append a directory to `$PATH` if it isn't already present. new="$(readlink -f "$1")" if [ ! -d "$new" ]; then echo -E "ADDPATH: path doesn't exist: $1" >&2 @@ -109,38 +110,38 @@ alias lr="lr -G" export LESS='-SRQ' alias db="dropbox_uploader" -alias fils="du -bahd1" -alias lsa="ls -A --group-directories-first" -alias perlu='perl -Mopen=locale -Mutf8' -alias rgn="rg --no-ignore" -alias cms="cryptominisat5 --verb 0" -alias curls="curl -sS" +alias fils="du -bahd1" ### @- (GNU du) display human-friendly filesizes for the files in a directory. +alias lsa="ls -A --group-directories-first" ### @- (GNU ls) list files with directories and dotfiles ordered first. +alias perlu='perl -Mopen=locale -Mutf8' ### @- invoke perl expecting files with UTF-8 encoding. +alias rgn="rg --no-ignore" ### @- invoke ripgrep without respecting `.gitignore` files. +alias cms="cryptominisat5 --verb 0" ### @- invoke cryptominisat5 with less noise. +alias curls="curl -sS" ### @- invoke curl with less noise. # git {{{2 -alias get="git clone --single-branch --depth 1" -alias gs='git status' # rip ghostscript -alias gd='git diff -U2' -alias gds='git --no-pager diff --stat' -alias gl='git log --oneline' -alias glo='git log --graph --decorate --pretty=oneline --abbrev-commit --all' -alias g1='git log --pretty=oneline --abbrev-commit --color=always | head -1' -alias gr='git remote -v' -alias gb='git --no-pager branch' +alias get="git clone --single-branch --depth 1" ### @- retrieve the most recent files from the default branch of a git repository, and not much else. +alias gs='git status' ### @- invoke git's status subcommand. +alias gd='git diff -U2' ### @- invoke git's diff subcommand with fewer lines of context. +alias gds='git --no-pager diff --stat' ### @- display difference stats from git. +alias gl='git log --oneline' ### @- invoke git's log subcommand with a single line per commit. +alias glo='git log --graph --decorate --pretty=oneline --abbrev-commit --all' ### @- navigate git's commit tree succinctly. +alias g1='git log --pretty=oneline --abbrev-commit --color=always | head -1' ### @- display the most recent git commit. +alias gr='git remote -v' ### @- display remote git repositories verbosely. +alias gb='git --no-pager branch' ### @- display the current git branch. # being specific {{{2 [ -e "$HOME/python3" ] && alias py="~/python3" || alias py="python3" alias pip="maybesudo -H pip3" -alias revend='objcopy -I binary -O binary --reverse-bytes=4' +alias revend='objcopy -I binary -O binary --reverse-bytes=4' ### @- reverse the 4-byte endianness of a single file. *this is an in-place operation!* alias aur="BUILDDIR=$HOME/src $HOME/sh/aur -jj" -alias clone='maybesudo rsync -aHA --info=progress2 --no-i-r' -alias aligntabs="column -t -s$'\t'" -alias crawla='ssh joshua@crawl.akrasiac.org -i ~/.ssh/crawl' -alias crawlz='ssh crawl@crawl.develz.org -i ~/.ssh/crawl' +alias clone='maybesudo rsync -aHA --info=progress2 --no-i-r' ### @- invoke rsync suitably for creating virtually indistinguishable copies of files. +alias aligntabs="column -t -s$'\t'" ### @- align tab-delimited fields in stdin. +alias crawla='ssh joshua@crawl.akrasiac.org -i ~/.ssh/crawl' ### @- play Dungeon Crawl: Stone Soup through ssh on the akrasiac server. +alias crawlz='ssh crawl@crawl.develz.org -i ~/.ssh/crawl' ### @- play Dungeon Crawl: Stone Soup through ssh on the develz server. alias ll="lol" # workaround for a strange issue with bash -lol() { +lol() { ### @ ll - list files verbosely, fancily, ordered, but not recursively. { lr -1lshGG -o tev -t 'name~~".*"||type==d' "$@" \ && lr -1lshGG -o tev -t 'name!~~".*"&&type!=d' "$@" \ || ls -lAX --group-directories-first --color=force "$@"; } | less @@ -148,28 +149,31 @@ lol() { # providing extra functionality {{{2 -alias diff="git diff --color=auto --no-ext-diff --no-index --no-prefix" -alias gc="git column --mode=dense --padding=2" -alias counts='find . | wc -l' -alias exts="find -type f | grep -o '\\.[^/.]*$' | sort | uniq -c | sort -n" -alias nocom='grep -Ev --line-buffered --color=never "^[[:space:]]*(//|#)"' -alias sortip="sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n" -alias jrep='grep -aPo "[\x{20}-\x{7E}\x{4E00}-\x{9FFF}\x{3040}-\x{30FF}]+"' -alias bomb='uconv -f utf-8 -t utf-8 --add-signature' -alias cleanse='tr -cd "\11\12\15\40-\176"' -alias rot13='tr "A-Za-z0-9" "N-ZA-Mn-za-m5-90-4"' -alias unwrap='awk '\''BEGIN{RS="\n\n";FS="\n"}{for(i=1;i<=NF;i++)printf "%s ",$i;print "\n"}'\' -alias double='awk "{print;print}"' -alias join2='paste -d" " - -' -alias katagana='perlu -MUnicode::Normalize -pe'"'"'$_=NFKD($_)=~y/ァ-ヶ /ぁ-ゖ /r'"'" -alias picky='{ pacman -Qgq base base-devel xorg xorg-drivers xfce4 | double; pacman -Qeq; } | sort | uniq -u' -alias unused='{ pacman -Qtq; pacman -Qeq | double; } | sort | uniq -u' -alias makepkgf='makepkg -Af --skipchecksums --skippgpcheck' -alias rakef='rake && gem build *.gemspec && gem install *.gem' +alias diff="git diff --color=auto --no-ext-diff --no-index --no-prefix" ### @- use git's diff subcommand for general diffing. +alias gc="git column --mode=dense --padding=2" ### @- columnize text by using git's column subcommand. +alias counts='find . | wc -l' ### @- count files in the current directory, including files found recursively. +alias exts="find -type f | grep -o '\\.[^/.]*$' | sort | uniq -c | sort -n" ### @- count and sort file extensions in the current directory, including files found recursively. +alias nocom='grep -Ev --line-buffered --color=never "^[[:space:]]*(//|#)"' ### @- strip single-line C-like and shell-like comments. +alias sortip="sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n" ### @- sort numerically by IPv4 segments. +alias jrep='grep -aPo "[\x{20}-\x{7E}\x{4E00}-\x{9FFF}\x{3040}-\x{30FF}]+"' ### @- extract strings comprised of basic ASCII or Japanese codepoints. +alias bomb='uconv -f utf-8 -t utf-8 --add-signature' ### @- add a Byte-Order Mark to a file. +alias cleanse='tr -cd "\11\12\15\40-\176"' ### @- strip unprintable and non-ASCII characters. +alias rot13='tr "A-Za-z0-9" "N-ZA-Mn-za-m5-90-4"' ### @- rot13 with numbers rotated as well. +alias unwrap='awk '\''BEGIN{RS="\n\n";FS="\n"}{for(i=1;i<=NF;i++)printf "%s ",$i;print "\n"}'\' ### @- join paragraphs into one line each. +alias double='awk "{print;print}"' ### @- print every line twice.
print every line twice. +alias join2='paste -d" " - -' ### @- join every other line. +alias katagana='perlu -MUnicode::Normalize -pe'"'"'$_=NFKD($_)=~y/ァ-ヶ /ぁ-ゖ /r'"'" ### @- convert katakana codepoints to their equivalent hiragana. +### useful for translating [debug text from ancient games.](https://tcrf.net/) +alias picky='{ pacman -Qgq base base-devel xorg xorg-drivers xfce4 | double; pacman -Qeq; } | sort | uniq -u' ### @- TODO +alias unused='{ pacman -Qtq; pacman -Qeq | double; } | sort | uniq -u' ### @- TODO +alias makepkgf='makepkg -Af --skipchecksums --skippgpcheck' ### @- make the freakin' package! +alias rakef='rake && gem build *.gemspec && gem install *.gem' ### @- make the freakin' gem! -eashare() { - # NOTE: this only works on MSYS2 for now. - # NOTE: i lied, this doesn't work anymore. idk +eashare() { ### @- upload a file and copy its URL to the clipboard. + ### + ### **NOTE:** this only works on MSYS2 for now. + ### + ### **NOTE:** i lied, this doesn't work at all. local dest="${1##*/}" eaput "$1" || return 1 printf "%s" "$_REMOTE_DOMAIN/$_REMOTE_DIR/$dest" >> /dev/clipboard diff --git a/home/bashrc b/home/bashrc index e2d13e6..cba4164 100644 --- a/home/bashrc +++ b/home/bashrc @@ -46,5 +46,4 @@ ADDPATH "$HOME/sh" . ~/.sh-bash : $((SOURCING-=1)) -# TODO: respect initctl like in .zshrc. -alias reload='cd; exec bash' +alias reload='cd; exec bash' ### @- **TODO:** respect initctl like in `.zshrc`. diff --git a/home/zshrc b/home/zshrc index 7d7272f..9288854 100644 --- a/home/zshrc +++ b/home/zshrc @@ -68,22 +68,30 @@ function { local fuzzy=`has fzy || print` -dirprev() { +dirprev() { ### @ dirprev + ### rotate and change to the previous directory in the directory stack + ### without consuming the prompt. pushd -q +1 zle reset-prompt precmd } -dirnext() { +dirnext() { ### @ dirnext + ### rotate and change to the next directory in the directory stack + ### without consuming the prompt. pushd -q -0 zle reset-prompt precmd } -dirup() { +dirup() { ### @ dirup + ### change to the parent directory of the current working directory + ### without consuming the prompt. cd .. zle reset-prompt precmd } -dirview() { +dirview() { ### @ dirview + ### use a fuzzy finder to select a recent directory in the directory stack + ### and change to it without consuming the prompt. print if [ -n "$fuzzy" ]; then local d="$(dirs -pl | awk '!seen[$0]++' | "$fuzzy")" @@ -155,21 +163,26 @@ bindkey '^Xe' edit-command-line # ctrl+x -> e . ~/.-shrc -alias -g OMFG="1>/dev/null" -alias -g STFU="2>/dev/null" -alias -g WHOA='${whoa[@]}' -alias -g WELP='${welp[@]}' +alias -g OMFG="1>/dev/null" ### @ OMFG - silence stdout. +alias -g STFU="2>/dev/null" ### @ STFU - silence stderr. +alias -g WHOA='${whoa[@]}' ### @ WHOA - expand to several C/C++ flags to ease development. +alias -g WELP='${welp[@]}' ### @ WELP - expand to C++ flags to enable a C++-as-C facade. alias sc="~/sh/sc" # only runs in bash (for now), so be explicit with path -alias pl="print -l" # not in -shrc because this only makes sense with zsh +# not in -shrc because this only makes sense with zsh: +alias pl="print -l" ### @ pl - print each argument on its own line. -function tw() { # needs the "function" keyword or else zsh complains +# needs the "function" keyword or else zsh complains: +function tw() { ### @ tw + ### invoke `twitch` as a job with both stdout and stderr silenced. twitch "$@" OMFG STFU & } local host="${(L)HOST}" function { + # initialize prompts. + local t="${TERM%%-*}" if [ "$t" = xterm ] || [ "$t" = screen ] || [ "$t" = tmux ]; then # set window title @@ -204,7 +217,9 @@ function { PROMPT="%{$reset${s}%(?.${good}.${bad})${e}${s}97${e}%}%#%{$reset%} " } -reload() { +reload() { ### @ reload + ### reload zsh by wiping temp files, recompiling rc files, + ### and replacing the current process with a new zsh process. # initctl has a "reload" symlink, but i'm already too used to typing this. # to remedy this, when args are passed, invoke initctl instead. if [ $# -gt 0 ]; then @@ -229,6 +244,7 @@ reload() { # generated by dircolors with https://github.com/isene/LS_COLORS function { + # initialize colors for ls. local lsc= line= < ~/.ls_colors | tr -d $'\r' | while read -r line; do lsc+="$line:" diff --git a/sh/arith b/sh/arith index 340a8ba..9748827 100755 --- a/sh/arith +++ b/sh/arith @@ -6,7 +6,8 @@ # though technically compatible with other shells, # extra functionality is through zsh's extended arithmetic functions. -arith() { +arith() { ### @- + ### perform arithmetic using the shell and display the result. # <<<"$(($@))" printf "%s\n" "$(($@))" } diff --git a/sh/aur b/sh/aur index f3803ff..b1889fd 100755 --- a/sh/aur +++ b/sh/aur @@ -4,7 +4,10 @@ # TODO: check compatibility with bash and dash. -aur() { +aur() { ### @- + ### download, edit, make, and install packages from the + ### [AUR.](https://aur.archlinux.org/) + ### it's a little broken. trap 'exit 1' SIGINT SIGTERM local bd="${BUILDDIR:-$PWD}" diff --git a/sh/autosync b/sh/autosync index d6c8fd0..9b49a0a 100755 --- a/sh/autosync +++ b/sh/autosync @@ -5,7 +5,9 @@ # TODO: portable way of dodging aliases to allow other shell support? -autosync() { +autosync() { ### @- + ### combine `inotifywait` and `rsync`. + ### this is sometimes nicer than `ssh`-ing into a server and running `vim` remotely. target="$1" shift # as a reminder not to get the argument order mixed up: diff --git a/sh/cdbusiest b/sh/cdbusiest index 484a05b..f8d669b 100755 --- a/sh/cdbusiest +++ b/sh/cdbusiest @@ -1,7 +1,8 @@ #!/usr/bin/env zsh # YES_ZSH -cdbusiest() { +cdbusiest() { ### @- + ### cd to the directory with the most files in it, counted recursively. dbusiest | read -r c d [ -z $c ] && return 1 printf "%s\n" "$c $d" diff --git a/sh/colors b/sh/colors index 98fbf45..be713cf 100755 --- a/sh/colors +++ b/sh/colors @@ -3,7 +3,9 @@ # YES_BASH # NO_DASH -colors() { +colors() { ### @- + ### print out all the foreground and background terminal color combinations. + ### excluding boilerplate, this script is a mere a 76-characters long! [ $# -eq 0 ] || { printf "%s\n" "$0: does not take arguments" >&2; return 1; } printf "\e[%dm$(printf " \e[%dm mV \e[40m" {4,10}{0..7})\e[0m\n" {3,9}{0..7} } diff --git a/sh/compandy b/sh/compandy index 9a4aa75..c362783 100755 --- a/sh/compandy +++ b/sh/compandy @@ -2,7 +2,9 @@ # script to make sense of compand's parameters # YES_ZSH -compandy() { +compandy() { ### @- + ### generate compand arguments for ffmpeg audio filters. + ### this is kinda pointless now that acompressor is wildly supported. if [ $# -eq 0 ]; then echo -E "usage: $0 {threshold} {ratio} [attack] [release] [knee] [gain] [delay]" return 1 diff --git a/sh/compile b/sh/compile index 69477c6..b6248c7 100755 --- a/sh/compile +++ b/sh/compile @@ -4,7 +4,7 @@ # NO_DASH # I'll just leave this here... -__setup_clang_ubuntu() { +__setup_clang_ubuntu() { ### @- local site="http://apt.llvm.org" local name="$(lsb_release -c | cut -f2)" local version=10 # NOTE: no longer decimal-based @@ -26,7 +26,20 @@ deb $site/$name/ llvm-toolchain-$name-$version main\n\ echo update-alternatives --install /usr/bin/llvm-symbolizer llvm-symbolizer /usr/bin/llvm-symbolizer-$version $priority } -compile() { +compile() { ### @- + ### compile single-file C and C++ programs, messily. + ### + ### supports gcc and clang on \*nix, and mingw64 gcc, msvc clang, + ### and regular msvc on Windows. tested on x86\_64 and on ARMv7 as well. + ### does not support MacOS, maybe someday… + ### + ### defaults to gnu11 and gnu++1z as C and C++ standards respectively. + ### defaults to clang, gcc, and msvc in that order. + ### + ### `compile` attempts to guess the most sane switches for any program, so that compilation may reduce to: + ### + ### **TODO:** restore examples. + # FIXME: compile gcc portrend.c -lsdl # this causes mayhem! diff --git a/sh/confirm b/sh/confirm index 7a4f61b..5172cdf 100755 --- a/sh/confirm +++ b/sh/confirm @@ -3,6 +3,17 @@ # YES_BASH # NO_DASH +### @ confirm +### display a simple yes-or-no prompt and return 0-or-1 respectively. +### +### ``` +### $ confirm && echo yay || echo nay +### Continue? [y/N] y +### yay +### $ confirm && echo yay || echo nay +### Continue? [y/N] n +### nay +### ``` if [ -n "$ZSH_VERSION" ]; then confirm() { [ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; } diff --git a/sh/days b/sh/days index 268dac7..577f07e 100755 --- a/sh/days +++ b/sh/days @@ -3,7 +3,13 @@ # YES_BASH # YES_DASH -days() { +days() { ### @- + ### compute days since a given date. + ### + ### ``` + ### $ days 'January 1 1970' + ### 18838 + ### ``` [ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; } echo $(( ($(date +%s) - $(date -d "$1" +%s)) / 60 / 60 / 24 )) } diff --git a/sh/dbusiest b/sh/dbusiest index 5f745b6..95e50fc 100755 --- a/sh/dbusiest +++ b/sh/dbusiest @@ -3,7 +3,8 @@ # NO_BASH # NO_DASH -dbusiest() { +dbusiest() { ### @- + ### display the directory with the most files in it, counted recursively. [ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; } local c d for d in *(FDN); do diff --git a/sh/dfu b/sh/dfu index 250be7a..d03bc3f 100755 --- a/sh/dfu +++ b/sh/dfu @@ -3,7 +3,10 @@ # YES_BASH # YES_DASH -dfu() { +dfu() { ### @- + ### pretty-print `df` in GiB. + ### + ### **TODO:** restore examples. [ $# -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"} diff --git a/sh/disf b/sh/disf index c0daae9..40a52bb 100755 --- a/sh/disf +++ b/sh/disf @@ -6,7 +6,8 @@ # TODO: actually test that this works with dash. -function disf() { +function disf() { ### @- + ### disassemble a single function from an unstripped executable, unreliably. [ $# -le 2 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; } local exe="${1:?first argument should be an unstripped executable}" local symbol="${2:?second argument should be a function name}" diff --git a/sh/document b/sh/document index fe0030e..69d690b 100644 --- a/sh/document +++ b/sh/document @@ -64,13 +64,15 @@ document2() { if [ "$n" = "$e" ]; then printf '\n### [%s](%s)\n\n' "$n" "$url" >> rc/README.md~ || return 5 else - printf '\n### [%s](%s)\n\n' "$n.${f#.}" "$url" >> rc/README.md~ || return 5 + printf '\n### [%s](%s)\n\n' "$n (${f#.})" "$url" >> rc/README.md~ || return 5 #printf '\n### %s\n\n* defined in [%s](%s)\n\n' "$n" "$f" "$url" >> rc/README.md~ || return 5 fi fi if [ "$s" != ' ' ]; then - printf '%s\n' "$s" >> rc/README.md~ || return 5 + if [ -z "$n" -o -n "$s" ]; then + printf '%s\n' "$s" >> rc/README.md~ || return 5 + fi fi done < "$f" || return 4 } diff --git a/sh/e b/sh/e index 946808d..994a9bc 100755 --- a/sh/e +++ b/sh/e @@ -3,7 +3,14 @@ # NO_BASH # NO_DASH -e() { +e() { ### @- + ### wrap around `$EDITOR` to run it as root if necessary. + ### this still needs some work to detect root-owned directories. + ### + ### ``` + ### $ e /etc/sudoers + ### [sudo] password for notwa: + ### ``` local editor=(${=EDITOR}) local running=0 diff --git a/sh/has b/sh/has index cbdabe4..4ed1123 100644 --- a/sh/has +++ b/sh/has @@ -3,7 +3,10 @@ # YES_BASH # YES_DASH -has() { +has() { ### @- + ### print the result of `which` if the program is found, else simply return 1. + ### + ### `export CC="$(has clang || has clang-3.8 || has gcc)"` if [ -n "$ZSH_VERSION" ]; then whence -p "$1" else diff --git a/sh/hex b/sh/hex index 8e5cff2..97aa375 100755 --- a/sh/hex +++ b/sh/hex @@ -6,7 +6,8 @@ # though technically compatible with other shells, # extra functionality is through zsh's extended arithmetic functions. -hex() { +hex() { ### @- + ### perform arithmetic using the shell and display the result as an unsigned 32-bit integer in hexadecimal. printf "%08X\n" "$(($@))" } diff --git a/sh/ify b/sh/ify index ffc3783..29b3166 100644 --- a/sh/ify +++ b/sh/ify @@ -3,7 +3,16 @@ # YES_BASH # YES_DASH -ify() { +ify() { ### @- + ### pipe one command through another, so you can still pass arguments to the former. + ### + ### this is mainly useful for aliases. 99% of the time you'll use this with `less`. + ### + ### ``` + ### $ alias ll="ify less ls -ACX --group-directories-first --color=force" + ### $ ll /etc + ### ``` + [ $# -ge 2 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; } local ex="$1" shift diff --git a/sh/is_empty b/sh/is_empty index ea9407e..3a9faa3 100755 --- a/sh/is_empty +++ b/sh/is_empty @@ -3,7 +3,8 @@ # YES_BASH # NO_DASH -is_empty() { +is_empty() { ### @- + ### return 0 if the directory given by argument is empty. while read -r f; do [ ! -d "$f" ] && [ -s "$f" ] && return 1 done < <(find ${1:-.}) diff --git a/sh/isup b/sh/isup index df73677..cfcbb1d 100755 --- a/sh/isup +++ b/sh/isup @@ -5,7 +5,8 @@ # TODO: damned substrings. rewrite to be semi-portable. -isup() { +isup() { ### @- + ### return 0 if a given website returns a 2xx HTTP code. local c curl -sLI -w '%{http_code}' -o /dev/null "$1" | read -r c [ "${c:0:1}" -eq 2 ] diff --git a/sh/minutemaid b/sh/minutemaid index 00a9cf5..aeac63b 100755 --- a/sh/minutemaid +++ b/sh/minutemaid @@ -1,11 +1,17 @@ #!/usr/bin/env dash -# crontab usage: -#* * * * * minutemaid 9 ~/work/do_my_bidding # runs every nine minutes # YES_ZSH # YES_BASH # YES_DASH -minutemaid() { +minutemaid() { ### @- + ### return 0 if the current minute is divisible by a number. + ### note that a minute is relative to the seconds since the epoch, not the minute of the hour. + ### + ### ``` + ### # crontab usage: + ### * * * * * minutemaid 9 ~/work/do_my_bidding # runs every nine minutes + ### ``` + local offset=0 name while getopts 'o:h' name; do case $name in diff --git a/sh/monitor b/sh/monitor index c7014e9..615659e 100755 --- a/sh/monitor +++ b/sh/monitor @@ -1,7 +1,8 @@ #!/usr/bin/env zsh # YES_ZSH -monitor() { +monitor() { ### @- + ### this is `watch` loosely reimplemented as a shell script. local bottom=0 strip=0 interval=2 opt= while getopts 'fsn:h' opt; do case $opt in diff --git a/sh/noccom b/sh/noccom index 70f49cc..3abcb5c 100644 --- a/sh/noccom +++ b/sh/noccom @@ -7,7 +7,8 @@ # TODO: what's the minimum version of perl required for this? -noccom() { +noccom() { ### @- + ### strip C-like comments; both multi-line and single-line. [ -s ~/opt/local/bin/noccom ] || cat > ~/opt/local/bin/noccom <&2; return 1; } local dt local fmt='+%F_%T_%N' diff --git a/sh/pacbm b/sh/pacbm index b0f53f6..ca28b13 100755 --- a/sh/pacbm +++ b/sh/pacbm @@ -3,7 +3,14 @@ # YES_BASH # YES_DASH -pacbm() { +pacbm() { ### @- + ### list installed pacman packages by their filesize, and the sum, ascending. requires `expac`. + ### + ### ``` + ### $ pacbm | head -n -1 | tail -2 + ### 204.78M clang + ### 235.44M linux-firmware + ### ``` expac -s '%m %n' | awk ' {t+=$1;printf("%8.2fM %s\n",$1/(1024*1024),$2)} END{printf("%8.2fM\n",t/(1024*1024))} diff --git a/sh/pause b/sh/pause index 8412604..a655a88 100755 --- a/sh/pause +++ b/sh/pause @@ -3,7 +3,14 @@ # YES_BASH # NO_DASH -pause() { +pause() { ### @- + ### pause — the companion script of `confirm`. + ### + ### ``` + ### $ pause + ### Press any key to continue + ### $ + ### ``` [ -n "${ZSH_VERSION:-}" ] \ && read -sk '?Press any key to continue ' || read -n1 -u 1 -sp 'Press any key to continue diff --git a/sh/pre b/sh/pre index 96c779c..5ca462a 100755 --- a/sh/pre +++ b/sh/pre @@ -3,7 +3,10 @@ # YES_BASH # YES_DASH -pre() { +pre() { ### @- + ### dump all the `#define`s that `$CC $CPPFLAGS $CFLAGS $LDFLAGS` would result in. + ### + ### **TODO:** restore examples. if [ -n "${ZSH_VERSION:-}" ]; then ${CC:-gcc} -dM -E - $=CPPFLAGS $=CFLAGS $=LDFLAGS < /dev/null else diff --git a/sh/randir b/sh/randir index deb4cf7..ed7e111 100755 --- a/sh/randir +++ b/sh/randir @@ -3,7 +3,13 @@ # YES_BASH # YES_DASH -randir() { +randir() { ### @- + ### display a random directory in the current working directory. + ### + ### ``` + ### $ randir + ### ./sh + ### ``` find -maxdepth 1 -type d \( -path '/root' -prune -o -print \) | tail -n+2 | shuf | head -n1 } diff --git a/sh/rs b/sh/rs index 30de4b7..a2d755f 100644 --- a/sh/rs +++ b/sh/rs @@ -1,8 +1,10 @@ #!/usr/bin/env zsh -# rs: record screen # YES_ZSH -rs() { +rs() { ### @- + ### record screen. does not record audio. + ### currently only works on Windows (gdigrab). + ### i'm sure there's something equivalent for Linux. set -e local o_overwrite= o_rate=30 o_duration=0 diff --git a/sh/sc b/sh/sc index 0cac932..78622fb 100755 --- a/sh/sc +++ b/sh/sc @@ -37,7 +37,10 @@ copy_tmp() { return 0 } -sc() { +sc() { ### @- + ### upload given files to a webserver and return a direct link for sharing them. + ### you'll want to tweak this if you use it yourself. + ### this contains some extra logic for screenshots created by `scropt`. if [ -n "${ZSH_VERSION:-}" ]; then # syntax is too different to bother tbh echo "please run with bash" diff --git a/sh/scramble b/sh/scramble index bc721a3..148597d 100755 --- a/sh/scramble +++ b/sh/scramble @@ -3,7 +3,10 @@ # YES_BASH # YES_DASH -scramble() { +scramble() { ### @- + ### scrambles text in a predictable way using regex. + ### + ### sacbremls ttex in a pdrceailtbe way unsig reegx. [ $# -eq 0 ] || { printf "%s\n" "$0: does not take arguments" >&2; return 1; } local eggs='s/@\(\w\)\(\w\)\(\w\)/@\3\1@\2/g' sed \ diff --git a/sh/screeny b/sh/screeny index ed3ffa8..67f61d9 100755 --- a/sh/screeny +++ b/sh/screeny @@ -1,7 +1,8 @@ #!/usr/bin/env zsh # YES_ZSH -screeny() { +screeny() { ### @- + ### i don't use this anymore~ local user="${1:?needs arg for user name}" shift home="/home/$user" diff --git a/sh/scropt b/sh/scropt index 6bac083..89e1ff7 100755 --- a/sh/scropt +++ b/sh/scropt @@ -1,11 +1,14 @@ #!/usr/bin/env bash # YES_ZSH -: $((SOURCING+=1)) +#: $((SOURCING+=1)) #. ~/sh/now # FIXME: don't do this? -: $((SOURCING-=1)) +#: $((SOURCING-=1)) -scropt() { +scropt() { ### @- + ### run `scrot` through `optipng` and save the result to `~/play/$(now).png`. + ### + ### `$ ~/sh/sc $(~/sh/scropt -s -d0.5)` local now=$(now) [ $? -eq 0 ] || return $? local fn="$HOME/play/$now.png" diff --git a/sh/slit b/sh/slit index f39001e..e320980 100755 --- a/sh/slit +++ b/sh/slit @@ -3,7 +3,8 @@ # YES_BASH # YES_DASH -slit() { +slit() { ### @- + ### view specific columns of text. [ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; } awk "{ print $(printf ',$%s' $@ | cut -b2-) }" diff --git a/sh/slitt b/sh/slitt index 2ea45ae..7f860ee 100644 --- a/sh/slitt +++ b/sh/slitt @@ -1,10 +1,11 @@ #!/usr/bin/env dash -# this version of slit uses tabs for input/output field separators. # YES_ZSH # YES_BASH # YES_DASH -slitt() { +slitt() { ### @- + ### view specific columns of text. + ### this version of `slit` uses tabs for its field separators. [ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; } #echo "$@" | awk '{for(i=1;i&2 exit 1 diff --git a/sh/streamcrap b/sh/streamcrap index 00ead0b..ee82c4e 100644 --- a/sh/streamcrap +++ b/sh/streamcrap @@ -54,7 +54,8 @@ fi unset _nn -mpv_watch() { +mpv_watch() { ### @- + ### watch something in mpv with a bunch of extra audio filtering crap. pushd ~/play >/dev/null local url="$1"; shift mpv \ @@ -65,7 +66,8 @@ mpv_watch() { popd >/dev/null } -mpv_stream() { +mpv_stream() { ### @- + ### watch a stream in mpv with a bunch of extra audio filtering crap. pushd ~/play >/dev/null local url="$1"; shift if [ -n "$ZSH_VERSION" ]; then @@ -77,12 +79,18 @@ mpv_stream() { popd >/dev/null } -twitch() { +twitch() { ### @- + ### watch a twitch stream in mpv with a bunch of extra audio filtering crap. local user="$1"; shift mpv_stream "http://twitch.tv/$user" "$@" } -yt() { +yt() { ### @- + ### watch a youtube video in mpv with a bunch of extra audio filtering crap. + ### this can be given a full URL or just a video ID. + ### remaining arguments are passed to mpv. + ### + ### there exist several variants for more specific use cases. local vid="$1"; shift if [[ ! -e "$vid" && "$(expr substr "$vid" 1 4)" != "http" ]]; then vid="ytdl://$vid" @@ -90,26 +98,31 @@ yt() { mpv_watch "$vid" "$@" } -ytg() { +ytg() { ### @- + ### watch a youtube video. like `yt`, but with a preference for different formats. local vid="$1"; shift yt "$vid" --ytdl-format=22/95/300/best "$@" } -ytll() { +ytll() { ### @- + ### watch a stream on youtube in mpv, etcetera etcetera. + ### this is the low latency version that does not support seeking. youtube-dl -q -f best "$1" -o - | mpv_stream - --no-ytdl } -ytgll() { +ytgll() { ### @- + ### watch a stream on youtube in mpv. like `ytll`, but with a preference for different formats. youtube-dl -q -f 22/95/300/best "$1" -o - | mpv_stream - --no-ytdl } -ai() { - # hai domo +ai() { # @- + # hai domo! yt "$@" --slang=en --sub-font='Tekton Pro' --sub-bold=yes \ --sub-font-size=60 --sub-border-color='#DD6180' --sub-margin-y=52 } -asmr() { +asmr() { # @- + # for your aural pleasure. _M_PROCESS="acompressor=threshold=0.001:ratio=1.33:attack=900:release=6000:makeup=6:knee=8:mix=0.9,alimiter" \ yt "$@" --volume=90 --ytdl-format=251/300/best } diff --git a/sh/sv b/sh/sv index a99687e..01e9ec0 100755 --- a/sh/sv +++ b/sh/sv @@ -3,7 +3,17 @@ # YES_BASH # YES_DASH -sv() { +sv() { ### @- + ### collect the lastmost value of every key. + ### the field separator can be given as its sole argument. + ### + ### ``` + ### echo "this=that\nthem=those\nthis=cat" | sv = + ### this=cat + ### them=those + ### ``` + ### + ### **TODO:** add multi-file grep example. [ $# -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]} diff --git a/sh/tpad b/sh/tpad index d06d25b..2aee5ca 100755 --- a/sh/tpad +++ b/sh/tpad @@ -3,7 +3,9 @@ # YES_BASH # YES_DASH -tpad() { +tpad() { ### @- + ### add a 1px transparent border around an image to prevent twitter from mangling it into a jpg. + ### sadly, this trick doesn't work anymore. for f; do gm convert -bordercolor "#000000FF" -border 1x1 "$f" "${f%.png}.tt.png" done diff --git a/sh/trunc b/sh/trunc index d94b17a..2d4cb85 100755 --- a/sh/trunc +++ b/sh/trunc @@ -3,7 +3,8 @@ # YES_BASH # YES_DASH -trunc() { +trunc() { ### @- + ### truncate text to fit within your terminal using the unicode character `…`. [ $# -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}' diff --git a/sh/unscreen b/sh/unscreen index 99cdf08..4aae7d7 100755 --- a/sh/unscreen +++ b/sh/unscreen @@ -3,7 +3,8 @@ # NO_BASH # NO_DASH -unscreen() { +unscreen() { ### @- + ### i don't use this anymore~ local pids="$(screen -ls | fgrep "$1" | cut -d. -f1)" for pid in $=pids; do local ppid="$(ps h --ppid "$pid" -o pid)" diff --git a/sh/wipe b/sh/wipe index f7f7ba4..edc0052 100644 --- a/sh/wipe +++ b/sh/wipe @@ -3,8 +3,12 @@ # YES_BASH # YES_DASH -wipe() { - # TODO: rename because wipe(1) already exists. +wipe() { ### @- + ### clear the screen and its scrollback, then print a high-contrast horizontal line. + ### using this, you'll know with absolute certainty that you're looking at the top of your history, + ### and that your terminal's scrollback didn't cap out and eat text. + ### + ### **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