move scripts to personal forge
This commit is contained in:
commit
47503b94fb
10 changed files with 202 additions and 0 deletions
13
README.md
Normal file
13
README.md
Normal file
|
@ -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
|
14
background
Executable file
14
background
Executable file
|
@ -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"
|
6
docs
Executable file
6
docs
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
# docs: Browse and create documentation with vim.
|
||||
|
||||
DOCS=~/documentation
|
||||
[ -d $DOCS ] && ${EDITOR:-nvim} "$DOCS"
|
26
mpc_update
Executable file
26
mpc_update
Executable file
|
@ -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"
|
21
note
Executable file
21
note
Executable file
|
@ -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"
|
23
record
Executable file
23
record
Executable file
|
@ -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"
|
24
testzed
Executable file
24
testzed
Executable file
|
@ -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
|
50
tw_publish
Executable file
50
tw_publish
Executable file
|
@ -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/
|
15
tw_start
Executable file
15
tw_start
Executable file
|
@ -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
|
10
weather
Executable file
10
weather
Executable file
|
@ -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
|
Loading…
Reference in a new issue