commit 47503b94fb9b8122ecfc7dd86605e6bfe5e16dda Author: tdback Date: Tue Nov 12 19:39:05 2024 -0500 move scripts to personal forge diff --git a/README.md b/README.md new file mode 100644 index 0000000..c2bfa15 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Scripts +A collection of scripts that help make life easier in the terminal. + +## Requirements +Some scripts require the following to be installed and in your system path: +- curl +- feh +- ffmpeg (with Xcb support) +- fzf +- neovim +- tiddlywiki (node.js package) +- zpool +- $EDITOR environment variable set diff --git a/background b/background new file mode 100755 index 0000000..6729237 --- /dev/null +++ b/background @@ -0,0 +1,14 @@ +#!/bin/sh + +# background: Set the background using `feh`. + +IMAGES="$HOME/.local/backgrounds" + +if [ "$1" = "-r" ]; then + feh --bg-scale --randomize "$IMAGES" + exit +fi + +SELECTED=$(find "$IMAGES" -type f -printf '%f\n' | fzf) + +[ -n "$SELECTED" ] && feh --bg-scale "$IMAGES/$SELECTED" diff --git a/docs b/docs new file mode 100755 index 0000000..8ca9087 --- /dev/null +++ b/docs @@ -0,0 +1,6 @@ +#!/bin/sh + +# docs: Browse and create documentation with vim. + +DOCS=~/documentation +[ -d $DOCS ] && ${EDITOR:-nvim} "$DOCS" diff --git a/mpc_update b/mpc_update new file mode 100755 index 0000000..53adf2b --- /dev/null +++ b/mpc_update @@ -0,0 +1,26 @@ +#!/bin/sh + +# mpc_update: Update an mpd playlist to include new songs in the music +# directory. + +yell() { echo "$0: $*" >&2; } +die() { yell "$*"; exit 111; } +try() { "$@" || die "cannot $*"; } + +[ "$#" -ne 2 ] && echo "usage: mpc_update " >&2 + +PLAYLIST="$1" +MUSIC_DIR="$2" + +[ -d "$MUSIC_DIR" ] && cd "$MUSIC_DIR" || + die "music directory '$MUSIC_DIR' does not exist!" + +# Clear the current playlist to prevent song duplication in mpd. +[ -e "$HOME/.local/share/mpd/playlists/${PLAYLIST}.m3u" ] && + try mpc clear >/dev/null && + try mpc rm "$PLAYLIST" + +# Add every song in the music directory. +try mpc add -- * + +try mpc save "$PLAYLIST" diff --git a/note b/note new file mode 100755 index 0000000..3d492df --- /dev/null +++ b/note @@ -0,0 +1,21 @@ +#!/bin/sh + +# note: Create a new note for the day, or add to an existing one. + +DATE=$(date '+%F') +TIME=$(date '+%T') +NOTES_DIR="$HOME/documents/notes" +NOTE="$NOTES_DIR/${DATE}.md" + +[ ! -d "$NOTES_DIR" ] && mkdir -p "$NOTES_DIR" + +# Create a new note if it doesn't already exist, otherwise append to it. +if [ ! -f "$NOTE" ]; then + printf "# %s\n## %s\n\n" "$DATE" "$TIME" > "$NOTE" +else + printf "\n## %s\n\n" "$TIME" >> "$NOTE" +fi + +# Open up the note with the cursor positioned at the bottom to easily allow +# additions to a new section. +${EDITOR:-vi} + "$NOTE" diff --git a/record b/record new file mode 100755 index 0000000..051765d --- /dev/null +++ b/record @@ -0,0 +1,23 @@ +#!/bin/sh + +# record: Record an mp4 video using ffmpeg. By default it will output the +# video to './out.mp4'. Requires ffmpeg to be built with Xcb support on NixOS. +# Screen resolution can be specified, but defaults to 1080p. + +die() { echo "$0: $*" >&2; exit 1; } +try() { "$@" || die "cannot $*"; } + +while getopts ":r:h" args; do + case "$args" in + r) RESOLUTION="$OPTARG" ;; + h) die "record [-r RESOLUTION] FILE" ;; + *) die "-$OPTARG is not an option." ;; + esac +done +shift $((OPTIND - 1)) + +FILE="${1:-out}" +: "${RESOLUTION:=1920x1080}" + +try ffmpeg -y -f x11grab -s "$RESOLUTION" -framerate 60 -i :0.0 -f alsa \ + -i default -nostats -hide_banner -loglevel quiet "${FILE}.mp4" diff --git a/testzed b/testzed new file mode 100755 index 0000000..b20110c --- /dev/null +++ b/testzed @@ -0,0 +1,24 @@ +#!/bin/sh + +# testzed: A useful utility for testing ZFS ZED configurations. + +if [ "$(id -u)" -ne 0 ]; then + echo "script requires root privileges" >&2 + exit 1 +fi + +FILE=/tmp/sparse_file +POOL="test" + +# Create throwaway pool. +dd if=/dev/zero of=$FILE bs=1 count=0 seek=512M +zpool create $POOL $FILE + +# Scrub the pool (which will finish instantly) to send out a notification. +# Ensure that ZED is configured with the option `ZED_NOTIFY_VERBOSE=1` to +# receive an email even if no errors occurred. +zpool scrub $POOL + +# Clean up after ourselves. +zpool export $POOL +rm $FILE diff --git a/tw_publish b/tw_publish new file mode 100755 index 0000000..6d1acbb --- /dev/null +++ b/tw_publish @@ -0,0 +1,50 @@ +#!/bin/sh + +# tw_publish: Build a single index.html file in the tiddlywiki's 'output/' +# directory, and then move it to the wiki's root directory. + +yell() { echo "$0: $*" >&2; } +die() { yell "$*"; exit 111; } +try() { "$@" || die "cannot $*"; } + +while getopts ":v" args; do + case "$args" in + v) set -x ;; + *) die "invalid option -$OPTARG... quitting;" ;; + esac +done +shift $((OPTIND-1)) # Shift args so wiki-name becomes $1 + +if ! command -v tiddlywiki >/dev/null; then + die "package 'tiddlywiki' can not be found... quitting;" +fi + +DOMAIN="tdback.net/" +TITLE="tdback's blog" +DESC="Posts about things I'm working on" +WIKI="$HOME/wikis/$1" + +[ "$#" -eq 0 ] && die "please specify a tiddlywiki... quitting;" + +[ ! -e "$WIKI" ] && die "tiddlywiki '$WIKI' does not exist... quitting;" + +# Build our initial index.html file containing the entire tiddlywiki. +try tiddlywiki "$WIKI" --build index >/dev/null + +# Now we need to "patch" the html file so it can pass the webring audit. +# See: https://codeberg.org/SystemCrafters/craftering/pulls/15 +head -n -2 "$WIKI"/output/index.html | try sed '$a \ +
\ + \ + craftering\ + \ +
\ +\ +' >"$WIKI"/index.html + +# Generate the RSS feed. +try tw_rss -wiki "$WIKI" -title "$TITLE" -domain "$DOMAIN" -desc "$DESC" -tls + +# Clean up output directory. +rm "$WIKI"/output/* +rmdir "$WIKI"/output/ diff --git a/tw_start b/tw_start new file mode 100755 index 0000000..4140040 --- /dev/null +++ b/tw_start @@ -0,0 +1,15 @@ +#!/bin/sh + +# tw_start: Start a specified tiddlywiki on port 8080. + +yell() { echo "$0: $*" >&2; } +die() { yell "$*"; exit 111; } +try() { "$@" || die "cannot $*"; } + +WIKI="$HOME/wikis/$1" + +[ "$#" -eq 0 ] && die "Please specify a tiddlywiki... quitting;" + +[ ! -e "$WIKI" ] && die "Tiddlywiki '$WIKI' does not exist... quitting;" + +try tiddlywiki "$WIKI" --listen diff --git a/weather b/weather new file mode 100755 index 0000000..c49e3ae --- /dev/null +++ b/weather @@ -0,0 +1,10 @@ +#!/bin/sh + +# weather: Quickly check the weather forecast. + +DEFAULT="grand+rapids" + +CITY=$(echo "$1" | tr ' ' '+') +: "${CITY:=$DEFAULT}" + +curl -s "https://wttr.in/$CITY" | head -n -2