diff options
author | tdback <tyler@tdback.net> | 2024-12-04 18:50:37 -0500 |
---|---|---|
committer | tdback <tyler@tdback.net> | 2024-12-04 18:50:37 -0500 |
commit | 58347fdfe21315ad3ccc0bd7c4703a8ec7aae797 (patch) | |
tree | 393fe8d69962e070c522e889b672ee9e97a88207 |
initial commit to new repo
-rw-r--r-- | README.md | 13 | ||||
-rwxr-xr-x | background | 14 | ||||
-rwxr-xr-x | docs | 6 | ||||
-rwxr-xr-x | fman | 5 | ||||
-rwxr-xr-x | geoip | 24 | ||||
-rwxr-xr-x | mpc_update | 26 | ||||
-rwxr-xr-x | note | 21 | ||||
-rwxr-xr-x | record | 23 | ||||
-rwxr-xr-x | testzed | 24 | ||||
-rwxr-xr-x | tw_publish | 50 | ||||
-rwxr-xr-x | tw_start | 15 | ||||
-rwxr-xr-x | weather | 10 |
12 files changed, 231 insertions, 0 deletions
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" @@ -0,0 +1,6 @@ +#!/bin/sh + +# docs: Browse and create documentation with vim. + +DOCS=~/documentation +[ -d $DOCS ] && ${EDITOR:-nvim} "$DOCS" @@ -0,0 +1,5 @@ +#!/bin/sh + +# fman: Fuzzy find man pages! Requires `fzf`. + +apropos . | fzf --prompt "Select program: " | cut -d" " -f 1 | xargs man @@ -0,0 +1,24 @@ +#!/bin/sh + +# geoip: Locate an IP address in the world. Requires `jq`. + +API="http://ip-api.com/json" + +if [ "$#" -ne 1 ] || echo "$1" | grep -qvxP "(\d{1,3}\.){3}\d{1,3}"; then + echo "please provide a valid IP address" >&2 + exit 1 +fi + +curl -s "$API/$1" | + jq '{ + ip: .query, + isp: .isp, + org: .org, + country: .country, + regionName: .regionName, + city: .city, + zip: .zip, + lat: .lat, + lon: .lon, + timezone: .timezone, + }' 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 <playlist> <music directory>" >&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" @@ -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" @@ -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" @@ -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 \ +<div style="display: none">\ + <a href="https://craftering.systemcrafters.net/@tdback/previous"></a>\ + <a href="https://craftering.systemcrafters.net/">craftering</a>\ + <a href="https://craftering.systemcrafters.net/@tdback/next"></a>\ +</div>\ +</body>\ +</html>' >"$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 @@ -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 |