diff options
author | George Abbott <george@gabbott.dev> | 2025-01-26 11:37:22 +0000 |
---|---|---|
committer | George Abbott <george@gabbott.dev> | 2025-01-26 11:37:22 +0000 |
commit | 82abadcecc7534b4847238ee2a977f33256b0439 (patch) | |
tree | ad8752c1dc9914829e80bc2f3f1a45dfec8f4b4a | |
parent | bac748dbe8c28cf1ed3b387b24f89ffe5a58ffc9 (diff) |
sh
-rwxr-xr-x | scripts/sh/100DaysToOffload | 3 | ||||
-rwxr-xr-x | scripts/sh/battery | 4 | ||||
-rwxr-xr-x | scripts/sh/blog | 62 | ||||
-rwxr-xr-x | scripts/sh/cdabbr | 14 | ||||
-rwxr-xr-x | scripts/sh/cfg | 9 | ||||
-rwxr-xr-x | scripts/sh/dlm | 8 | ||||
-rwxr-xr-x | scripts/sh/gt | 5 | ||||
-rwxr-xr-x | scripts/sh/kblayout | 3 | ||||
-rwxr-xr-x | scripts/sh/local-srv | 6 | ||||
-rwxr-xr-x | scripts/sh/poem | 63 | ||||
-rwxr-xr-x | scripts/sh/prose | 63 | ||||
-rwxr-xr-x | scripts/sh/rd | 3 | ||||
-rwxr-xr-x | scripts/sh/repl | 8 | ||||
-rwxr-xr-x | scripts/sh/scr | 17 | ||||
-rwxr-xr-x | scripts/sh/spr | 50 | ||||
-rwxr-xr-x | scripts/sh/swap-session | 12 | ||||
-rwxr-xr-x | scripts/sh/thousands | 9 | ||||
-rwxr-xr-x | scripts/sh/update | 17 | ||||
-rwxr-xr-x | scripts/sh/volumedown | 4 | ||||
-rwxr-xr-x | scripts/sh/volumeup | 3 | ||||
-rwxr-xr-x | scripts/sh/wallpaper | 22 | ||||
-rwxr-xr-x | scripts/sh/weeknotes | 3 | ||||
-rwxr-xr-x | scripts/sh/wp | 18 | ||||
-rwxr-xr-x | scripts/sh/wr | 50 | ||||
-rwxr-xr-x | scripts/sh/wrf | 4 | ||||
-rwxr-xr-x | scripts/sh/wrt | 4 | ||||
-rwxr-xr-x | scripts/sh/wsctl | 64 | ||||
-rwxr-xr-x | scripts/sh/wv | 100 | ||||
-rwxr-xr-x | scripts/sh/wv-wc | 2 |
29 files changed, 630 insertions, 0 deletions
diff --git a/scripts/sh/100DaysToOffload b/scripts/sh/100DaysToOffload new file mode 100755 index 0000000..f5b2d1c --- /dev/null +++ b/scripts/sh/100DaysToOffload @@ -0,0 +1,3 @@ +#!/bin/sh + +$EDITOR $WWW_DEFAULT_PATH/src/100DaysToOffload diff --git a/scripts/sh/battery b/scripts/sh/battery new file mode 100755 index 0000000..b253445 --- /dev/null +++ b/scripts/sh/battery @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "First:" "$(cat /sys/class/power_supply/BAT0/capacity)%" +echo "Second:" "$(cat /sys/class/power_supply/BAT1/capacity)%" diff --git a/scripts/sh/blog b/scripts/sh/blog new file mode 100755 index 0000000..59de435 --- /dev/null +++ b/scripts/sh/blog @@ -0,0 +1,62 @@ +#!/bin/sh +# blog: write a blog entry + +begins_with() { # haystack prefix + value=$1 + prefix=$2 + + case "$value" in + "$prefix"*) return 0 + esac + + return 1 +} + +usage() { + echo "blog [help | ls | ls-html | NAME]" +} + +fuzzy() { + FILE="$(find "$WWW_DEFAULT_PATH/src/blog" -type f | $FUZZY -l 1000)" + [ -z "$FILE" ] && exit 0 + if ! begins_with "$FILE" "$WWW_DEFAULT_PATH/src/blog" ; then + FILE="$WWW_DEFAULT_PATH/src/blog/$FILE" + fi + + mkdir "$(dirname "$FILE")" -p + $EDITOR "$FILE" +} + +list() { + header="Date\tTitle\n" + for f in $(find $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do + out="$out$(sed -n 2p $f) $(sed -n 1p $f)\n" + done + out="$header$(printf "$out" | sort -rk 1)\n" + printf "$out" +} + +list_html() { + header="<table>\n<tr><th>Date</th>\t<th>Title</th></tr>\n" + for f in $(find $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do + out="$out\t<tr><td>$(sed -n 2p $f)</td><td><a href=\"/blog/$(basename "$f")\">$(sed -n 1p $f)</a></td></tr>\n" + done + out="$header$(printf "$out" | sort -rk 1)\n</table>\n" + printf "$out" +} + +[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 +[ -z "$EDITOR" ] && echo "EDITOR not set" && exit +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit +[ "$1" = "help" ] && usage && exit 0 +[ "$1" = "ls" ] && list && exit 0 +[ "$1" = "ls-html" ] && list_html && exit 0 + +if [ -z "$1" ] || [ "$1" = "fuzzy" ] ; +then + fuzzy + exit 0 +fi + +mkdir -p "$WWW_DEFAULT_PATH/src/blog" +$EDITOR "$WWW_DEFAULT_PATH/src/blog/$1" diff --git a/scripts/sh/cdabbr b/scripts/sh/cdabbr new file mode 100755 index 0000000..de5dadd --- /dev/null +++ b/scripts/sh/cdabbr @@ -0,0 +1,14 @@ +#!/bin/sh +# cdabbr :: opens the `cdabbr` document for editing and reloads abbreviations +# cdabbr ls :: cats out the document +# cdabbr :: + +[ -z "$EDITOR" ] && echo "EDITOR not set" && exit + +[ "$1" = "ls" ] && cat "$HOME/cdabbr" && exit 0 + +$EDITOR "$HOME/cdabbr" + +while read a c ; do + alias "cd$a"="cd $c" +done <<< "$(cat "$HOME"/cdabbr)" diff --git a/scripts/sh/cfg b/scripts/sh/cfg new file mode 100755 index 0000000..cb375b5 --- /dev/null +++ b/scripts/sh/cfg @@ -0,0 +1,9 @@ +#!/bin/sh +# Bring up configuration files to edit them. +# TODO: add Git into this. + +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit + +file="$(find "$NEODOT/cfg" -type f | $FUZZY)" +[ -z "$file" ] && exit 0 +nvim "$file" diff --git a/scripts/sh/dlm b/scripts/sh/dlm new file mode 100755 index 0000000..1d9b28f --- /dev/null +++ b/scripts/sh/dlm @@ -0,0 +1,8 @@ +#!/bin/sh +# Download a Youtube song. +# Flag: q - Do not print (as first param only) + +[ "$1" = "q" ] && flag="1>/dev/null" || flag="" +[ "$1" = "q" ] && param="$2" || param="$1" + +yt-dlp -x "$param" -o "$HOME/songs/%(title)s.%(ext)s" $flag diff --git a/scripts/sh/gt b/scripts/sh/gt new file mode 100755 index 0000000..55069bf --- /dev/null +++ b/scripts/sh/gt @@ -0,0 +1,5 @@ +#!/bin/sh + +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit 0 + +cd "$(fd --full-path "$HOME" -t d | $FUZZY)" diff --git a/scripts/sh/kblayout b/scripts/sh/kblayout new file mode 100755 index 0000000..c062755 --- /dev/null +++ b/scripts/sh/kblayout @@ -0,0 +1,3 @@ +#!/bin/sh + +riverctl keyboard-layout -options caps:swapescape $1 diff --git a/scripts/sh/local-srv b/scripts/sh/local-srv new file mode 100755 index 0000000..5eaefa7 --- /dev/null +++ b/scripts/sh/local-srv @@ -0,0 +1,6 @@ +#!/bin/sh +# Spin up a server at the passed in directory. + +[ -z "$2" ] && port=1102 || port="$2" + +python3 -m http.server "$port" -d $1 diff --git a/scripts/sh/poem b/scripts/sh/poem new file mode 100755 index 0000000..9169f1a --- /dev/null +++ b/scripts/sh/poem @@ -0,0 +1,63 @@ +#!/bin/sh +# poem: write a poem + +begins_with() { # haystack prefix + value=$1 + prefix=$2 + + case "$value" in + "$prefix"*) return 0 + esac + + return 1 +} + +usage() { + echo "poem [help | ls | ls-html | NAME]" +} + +fuzzy() { + FILE="$(find "$WWW_DEFAULT_PATH/src/poetry" -type f | $FUZZY)" + [ -z "$FILE" ] && exit 0 + if ! begins_with "$FILE" "$WWW_DEFAULT_PATH/src/poetry" ; then + FILE="$WWW_DEFAULT_PATH/src/poetry/$FILE" + fi + + mkdir "$(dirname "$FILE")" -p + $EDITOR "$FILE" +} + +list() { + header="Date\tTitle\n" + for f in $(find $WWW_DEFAULT_PATH/src/poetry -type f | sort -k 3) ; do + out="$out$(sed -n 2p $f)\t$(sed -n 1p $f)\n" + done + out="$header$(printf "$out" | sort -rk 1)\n" + printf "$out" +} + +list_html() { + header="<table>\n<tr><th>Date</th>\t<th>Title</th></tr>\n" + for f in $(find $WWW_DEFAULT_PATH/src/poetry -type f | sort -k 3) ; do + out="$out\t<tr><td>$(sed -n 2p $f)</td><td><a href=\"/poetry/$(basename "$f")\">$(sed -n 1p $f)</a></td></tr>\n" + done + out="$header$(printf "$out" | sort -rk 1)\n</table>\n" + printf "$out" +} + + +[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 +[ -z "$EDITOR" ] && echo "EDITOR not set" && exit +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit +[ "$1" = "help" ] && usage && exit 0 +[ "$1" = "ls" ] && list && exit 0 +[ "$1" = "ls-html" ] && list_html && exit 0 + +if [ -z "$1" ] || [ "$1" = "fuzzy" ] ; +then + fuzzy + exit 0 +fi + +mkdir -p "$WWW_DEFAULT_PATH/src/poetry" +$EDITOR "$WWW_DEFAULT_PATH/src/poetry/$1" diff --git a/scripts/sh/prose b/scripts/sh/prose new file mode 100755 index 0000000..adc6728 --- /dev/null +++ b/scripts/sh/prose @@ -0,0 +1,63 @@ +#!/bin/sh +# prose: write a prose + +begins_with() { # haystack prefix + value=$1 + prefix=$2 + + case "$value" in + "$prefix"*) return 0 + esac + + return 1 +} + +usage() { + echo "prose [help | ls | ls-html | NAME]" +} + +fuzzy() { + FILE="$(find "$WWW_DEFAULT_PATH/src/prose" -type f | $FUZZY)" + [ -z "$FILE" ] && exit 0 + if ! begins_with "$FILE" "$WWW_DEFAULT_PATH/src/prose" ; then + FILE="$WWW_DEFAULT_PATH/src/prose/$FILE" + fi + + mkdir "$(dirname "$FILE")" -p + $EDITOR "$FILE" +} + +list() { + header="Date\tTitle\n" + for f in $(find $WWW_DEFAULT_PATH/src/prose -type f | sort -k 3) ; do + out="$out$(sed -n 2p $f)\t$(sed -n 1p $f)\n" + done + out="$header$(printf "$out" | sort -rk 1)\n" + printf "$out" +} + +list_html() { + header="<table>\n<tr><th>Date</th>\t<th>Title</th></tr>\n" + for f in $(find $WWW_DEFAULT_PATH/src/prose -type f | sort -k 3) ; do + out="$out\t<tr><td>$(sed -n 2p $f)</td><td><a href=\"/prose/$(basename "$f")\">$(sed -n 1p $f)</a></td></tr>\n" + done + out="$header$(printf "$out" | sort -rk 1)\n</table>\n" + printf "$out" +} + + +[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 +[ -z "$EDITOR" ] && echo "EDITOR not set" && exit +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit +[ "$1" = "help" ] && usage && exit 0 +[ "$1" = "ls" ] && list && exit 0 +[ "$1" = "ls-html" ] && list_html && exit 0 + +if [ -z "$1" ] || [ "$1" = "fuzzy" ] ; +then + fuzzy + exit 0 +fi + +mkdir -p "$WWW_DEFAULT_PATH/src/prose" +$EDITOR "$WWW_DEFAULT_PATH/src/prose/$1" diff --git a/scripts/sh/rd b/scripts/sh/rd new file mode 100755 index 0000000..0e53450 --- /dev/null +++ b/scripts/sh/rd @@ -0,0 +1,3 @@ +#!/bin/sh + +$EDITOR $WWW_DEFAULT_PATH/src/reading diff --git a/scripts/sh/repl b/scripts/sh/repl new file mode 100755 index 0000000..3bd5607 --- /dev/null +++ b/scripts/sh/repl @@ -0,0 +1,8 @@ +#!/bin/sh + +delim_begin="$1" +delim_end="$2" +contents_file="$3" +dest="$4" + +sed -i -ne "/$delim_begin/ {p; r $contents_file" -e ":a; n; /$delim_end/ { p; b}; ba}; p" "$dest" diff --git a/scripts/sh/scr b/scripts/sh/scr new file mode 100755 index 0000000..c0d26c3 --- /dev/null +++ b/scripts/sh/scr @@ -0,0 +1,17 @@ +#!/bin/sh +# Fuzzy finds in the scripts/sh directory. +# Programs in Rust, etc. are not treated in the same way. +# To make a new script, use "scr NAME". + +[ -z "$EDITOR" ] && echo "EDITOR not set" && exit +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit + +if [ -z "$1" ] ; then + FILE="$(find "$HOME/git/neodot/scripts/sh" -type f | $FUZZY)" + [ -z "$FILE" ] && exit 0 + $EDITOR "$FILE" +else + $EDITOR "$HOME/git/neodot/scripts/sh/$1" + chmod +x "$HOME/git/neodot/scripts/sh/$1" + update 2>&1 +fi diff --git a/scripts/sh/spr b/scripts/sh/spr new file mode 100755 index 0000000..93d3e8f --- /dev/null +++ b/scripts/sh/spr @@ -0,0 +1,50 @@ +#!/bin/sh +# Usage (- represents end of arguments) :- +# spr - :: opens the raw directory in vim for navigation (sprf is generally better) +# spr name - :: Opens the file "name" +# (TODO)spr dir/name - :: Creates "dir" if doesnt exist and opens "dir/name" +# spr fuzzy :: opens a fuzzy find list of spr files to edit. Shortcut is "sprf" +# (TODO)spr tree :: opens a tree view of all files. Shortcut is "sprt" + +begins_with() { # haystack prefix + value=$1 + prefix=$2 + + case "$value" in + "$prefix"*) return 0 + esac + + return 1 +} + +[ -z "$EDITOR" ] && echo "EDITOR not set" && exit +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit + +tree() { + eza --tree "$HOME/sporadic" +} + +fuzzy() { + FILE="$(find "$HOME/sporadic" -type f | $FUZZY)" + [ -z "$FILE" ] && exit 0 + if ! begins_with "$FILE" "$HOME/sporadic" ; then + FILE="$HOME/sporadic/$FILE" + fi + + mkdir "$(dirname "$FILE")" -p + $EDITOR "$FILE" +} + +if [ -z "$1" ] || [ "$1" = "fuzzy" ] ; +then + fuzzy + exit 0 +fi + +if [ "$1" = "tree" ] ; then + tree + exit 0 +fi + +mkdir "$HOME/sporadic/$(dirname $1)" -p +$EDITOR "$HOME/sporadic/$1" diff --git a/scripts/sh/swap-session b/scripts/sh/swap-session new file mode 100755 index 0000000..1cccdba --- /dev/null +++ b/scripts/sh/swap-session @@ -0,0 +1,12 @@ +#!/bin/sh +# Swaps between sessions. It does this by running `fzf` over the list of +# sessions, allowing one to be select which is then attached. + +FUZZY="fzf" + +TO_REATTACH="$(tmux ls | $FUZZY)" +# TODO: handle the case when nothing was selected. + +SESSION_ID="$(echo "$TO_REATTACH" | cut -d':' -f1)" + +tmux attach -d -t $SESSION_ID diff --git a/scripts/sh/thousands b/scripts/sh/thousands new file mode 100755 index 0000000..ed361cc --- /dev/null +++ b/scripts/sh/thousands @@ -0,0 +1,9 @@ +#!/bin/sh +# thousands: update the list of thousands +# (any additions to the file also need corresponding changes to the sed script +# in `release` + +[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 +[ -z "$EDITOR" ] && echo "EDITOR not set" && exit + +$EDITOR "$WWW_DEFAULT_PATH/src/thousands" diff --git a/scripts/sh/update b/scripts/sh/update new file mode 100755 index 0000000..5eda0dd --- /dev/null +++ b/scripts/sh/update @@ -0,0 +1,17 @@ +#!/bin/sh +# Updates all executables (i.e. all scripts and binaries here) to be in +# PATH. Upon this script being run, all executables should be able to be found. +# Executables are symlinked to $HOME/.local/bin. + +[ -z "$NEODOT_SCR" ] && echo "NEODOT_SCR not set" && exit +[ -z "$NEODOT_SH" ] && echo "NEODOT_SH not set" && exit +# todo: add $NEODOT_C envvar. + +mkdir -p "$HOME/.local/bin" + +# Update all in sh +find $NEODOT_SH -type f -exec sh -c 'ln -sf "{}" $HOME/.local/bin/$(basename {})' \; + +# Build all executables +odin build $NEODOT_SCR/jezup -out:$NEODOT_SCR/target/jezup +odin build $NEODOT_SCR/dexter -out:$NEODOT_SCR/target/dexter diff --git a/scripts/sh/volumedown b/scripts/sh/volumedown new file mode 100755 index 0000000..ed107ed --- /dev/null +++ b/scripts/sh/volumedown @@ -0,0 +1,4 @@ + +#!/bin/sh + +pactl set-sink-volume @DEFAULT_SINK@ -5% diff --git a/scripts/sh/volumeup b/scripts/sh/volumeup new file mode 100755 index 0000000..e75267c --- /dev/null +++ b/scripts/sh/volumeup @@ -0,0 +1,3 @@ +#!/bin/sh + +pactl set-sink-volume @DEFAULT_SINK@ +5% diff --git a/scripts/sh/wallpaper b/scripts/sh/wallpaper new file mode 100755 index 0000000..ec1fe1a --- /dev/null +++ b/scripts/sh/wallpaper @@ -0,0 +1,22 @@ +#!/bin/sh +# Load background. This is loaded as a random file from $HOME/bg/. +# Run: wallpaper &. +# wallpaper ls :: list all wallpapers. +# wallpaper pick :: select a wallpaper. (do not detach with &) + +list() { + eza -al "$HOME/bg" +} + +pick() { + file="$(find "$HOME/bg" -type f | $FUZZY)" + [ -z "$file" ] && exit 0 + swaybg -i "$file" & # Must detach process here, as process must be owned to select. +} + +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit + +[ "$1" = "ls" ] && list && exit 0 +[ "$1" = "pick" ] && pick && exit 0 + +swaybg -i "$(find "$HOME/bg" -type f | shuf -n 1)" diff --git a/scripts/sh/weeknotes b/scripts/sh/weeknotes new file mode 100755 index 0000000..bf3f048 --- /dev/null +++ b/scripts/sh/weeknotes @@ -0,0 +1,3 @@ +#!/bin/sh + +$EDITOR $WWW_DEFAULT_PATH/src/weeknotes diff --git a/scripts/sh/wp b/scripts/sh/wp new file mode 100755 index 0000000..3ef5aa4 --- /dev/null +++ b/scripts/sh/wp @@ -0,0 +1,18 @@ +#!/bin/sh +# Write Poem +# Format of the poem is in the same way as wv. + +list() { + out="file date title\n" + for f in $(find $WWW_DEFAULT_PATH/src/poetry -type f | sort -k 3) ; do + out="$out$(basename "$f") $(sed -n 2p $f) $(sed -n 1p $f)\n" + done + + printf "$(printf "$out" | column -ts ' ')\n" +} + +[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 +[ -z "$1" ] && echo "You must provide a name" && exit 2 +[ "$1" = "ls" ] && list && exit 0 + +nvim "$WWW_DEFAULT_PATH/src/poetry/$1" diff --git a/scripts/sh/wr b/scripts/sh/wr new file mode 100755 index 0000000..f7b0c6a --- /dev/null +++ b/scripts/sh/wr @@ -0,0 +1,50 @@ +#!/bin/sh +# Usage (- represents end of arguments) :- +# wr - :: opens the raw directory in vim for navigation (wrf is generally better) +# wr name - :: Opens the file "name" +# (TODO)wr dir/name - :: Creates "dir" if doesnt exist and opens "dir/name" +# wr fuzzy :: opens a fuzzy find list of wr files to edit. Shortcut is "wrf" +# (TODO)wr tree :: opens a tree view of all files. Shortcut is "wrt" + +begins_with() { # haystack prefix + value=$1 + prefix=$2 + + case "$value" in + "$prefix"*) return 0 + esac + + return 1 +} + +[ -z "$EDITOR" ] && echo "EDITOR not set" && exit +[ -z "$FUZZY" ] && echo "FUZZY not set" && exit + +tree() { + eza --tree "$HOME/wr" +} + +fuzzy() { + FILE="$(find "$HOME/wr" -type f | $FUZZY)" + [ -z "$FILE" ] && exit 0 + if ! begins_with "$FILE" "$HOME/wr" ; then + FILE="$HOME/wr/$FILE" + fi + + mkdir "$(dirname "$FILE")" -p + $EDITOR "$FILE" +} + +if [ -z "$1" ] || [ "$1" = "fuzzy" ] ; +then + fuzzy + exit 0 +fi + +if [ "$1" = "tree" ] ; then + tree + exit 0 +fi + +mkdir "$HOME/wr/$(dirname $1)" -p +$EDITOR "$HOME/wr/$1" diff --git a/scripts/sh/wrf b/scripts/sh/wrf new file mode 100755 index 0000000..bfc52b2 --- /dev/null +++ b/scripts/sh/wrf @@ -0,0 +1,4 @@ +#!/bin/sh +# Aliases "wr fuzzy" + +wr fuzzy $@ diff --git a/scripts/sh/wrt b/scripts/sh/wrt new file mode 100755 index 0000000..93e07f3 --- /dev/null +++ b/scripts/sh/wrt @@ -0,0 +1,4 @@ +#!/bin/sh +# Alias for "wr tree". + +wr tree $@ diff --git a/scripts/sh/wsctl b/scripts/sh/wsctl new file mode 100755 index 0000000..fde1e93 --- /dev/null +++ b/scripts/sh/wsctl @@ -0,0 +1,64 @@ +#!/bin/sh +# wsctl - scripts for general admin of the website + +usage() { + echo "wsctl [gen-wr-index | gen-wr-index-html | ls | today | week]" +} + +list() { + header="date\ttype\twc\ttitle\n" + for f in $(find $WWW_DEFAULT_PATH/src/wv \ + $WWW_DEFAULT_PATH/src/poetry $WWW_DEFAULT_PATH/src/prose \ + $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do + out="$out$(sed -n 2p $f) $(basename "$(dirname "$f")") $(wc -w "$f" | awk '{print $1}') $(sed -n 1p $f)\n" + done + + out="$header$(printf "$out" | sort -rk 1)\n" + printf "$out" +} + +gen_wr_idx() { + header="date type title\n" + for f in $(find $WWW_DEFAULT_PATH/src/wv \ + $WWW_DEFAULT_PATH/src/poetry $WWW_DEFAULT_PATH/src/prose \ + $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do + out="$out$(sed -n 2p $f) $(basename "$(dirname "$f")") $(sed -n 1p $f)\n" + done + + out="$header$(printf "$out" | sort -rk 1)\n" + + printf "$out" + +} + +gen_wr_idx_html() { + header="<table><tr><th>date</th> <th>type</th> <th>title</th></tr>\n" + for f in $(find $WWW_DEFAULT_PATH/src/wv \ + $WWW_DEFAULT_PATH/src/poetry $WWW_DEFAULT_PATH/src/prose \ + $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do + type="$(basename "$(dirname "$f")")" + out="$out\t<tr><td>$(sed -n 2p $f)</td> <td>$type</td> <td><a href=\"/$type/$(basename "$f")\">$(sed -n 1p $f)</td></a></tr>\n" + done + + out="$header$(printf "$out" | sort -rk 1)\n</table>\n" + + printf "$out" +} + +today() { + list | grep "$(date +%Y-%m-%d)" +} + +week() { + # TODO + echo "" +} + +[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 +[ "$1" = "gen-wr-index" ] && gen_wr_idx && exit 0 +[ "$1" = "gen-wr-index-html" ] && gen_wr_idx_html && exit 0 +[ "$1" = "today" ] && today && exit 0 +[ "$1" = "ls" ] && list && exit 0 +[ "$1" = "help" ] && usage && exit 0 + +echo "No command passed; run wsctl help for info." diff --git a/scripts/sh/wv b/scripts/sh/wv new file mode 100755 index 0000000..83bda1d --- /dev/null +++ b/scripts/sh/wv @@ -0,0 +1,100 @@ +#!/bin/sh +# wv: write a word-vomit. +# TODO: add -w flag for setting website. + +usage() { + echo "wv [-h | ideas | ls | stats | per-day | per-month | NUMBER]" +} + +stats() { + total_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | tail -1)" + total_wc="$(wc -w $WWW_DEFAULT_PATH/src/wv/* | tail -n 1 | awk '{ print $1 }')" + avg_wc="$(($total_wc / $(echo $total_ent | sed 's/^0*//') ))" + + echo "Total entries: $total_ent" + echo "Total wordcount: $total_wc" + echo "Avg wordcount: $avg_wc" +} + +stats_html() { + total_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | tail -1)" + total_wc="$(wc -w $WWW_DEFAULT_PATH/src/wv/* | tail -n 1 | awk '{ print $1 }')" + avg_wc="$(($total_wc / $(echo $total_ent | sed 's/^0*//') ))" + + printf "<ul>\n<li>Total entries: $total_ent</li>\n<li>Total word count: $total_wc</li>\n<li>Average word count: $avg_wc</li>\n</ul>" + +} + +list() { + out="file date wc title\n" + for f in $(find $WWW_DEFAULT_PATH/src/wv -type f | sort -k 3) ; do + out="$out$(basename "$f") $(sed -n 2p $f) $(wc -w "$f" | awk '{print $1}') $(sed -n 1p $f)\n" + done + + printf "$out" +} + +list_html() { + out="<table>\n<tr><th>Index</th>\t<th>Date</th>\t<th>Word count</th>\t<th>Title</th></tr>\n" + for f in $(find $WWW_DEFAULT_PATH/src/wv -type f | sort -rk 3) ; do + out="$out\t<tr><td>$(basename "$f")</td> <td>$(sed -n 2p $f)</td> <td>$(wc -w "$f" | awk '{print $1}')</td> <td><a href=\"/wv/$(basename "$f")\">$(sed -n 1p $f)</a></td></tr>\n" + done + out="$out\n</table>" + printf "$out" +} + + +perday() { + list | awk '{print $2}' | grep -v 'date' | sort | uniq -c | sort -n +} + +permonth() { + for f in $(find $WWW_DEFAULT_PATH/src/wv -type f | sort -k 3) ; do + out="$out$(sed -n 2p $f | cut -c1-7)\n" + done + + printf "$(printf "$out" | uniq -c)\n" +} + +current() { + total_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | tail -1)" + printf "$total_ent\n" | sed 's/^0*//' +} + +latest_entry() { + latest_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | tail -1)" + echo "$(sed -n 2p "$WWW_DEFAULT_PATH/src/wv/$latest_ent")" +} + +first_entry() { + first_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | head -n1)" + echo "$(sed -n 2p "$WWW_DEFAULT_PATH/src/wv/$first_ent")" +} + +[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 +[ "$1" = "-h" ] && usage && exit 0 +[ "$1" = "help" ] && usage && exit 0 +[ "$1" = "ls" ] && list && exit 0 +[ "$1" = "ls-html" ] && list_html && exit 0 +[ "$1" = "ideas" ] && spr "wv-ideas" && exit 0 +[ "$1" = "stats" ] && stats && exit 0 +[ "$1" = "stats-html" ] && stats_html && exit 0 +[ "$1" = "per-day" ] && perday && exit 0 +[ "$1" = "per-month" ] && permonth && exit 0 +[ "$1" = "latest-entry" ] && latest_entry && exit 0 +[ "$1" = "first-entry" ] && first_entry && exit 0 +[ "$1" = "current" ] && current && exit 0 +[ ! -z "$1" ] && nvim "$WWW_DEFAULT_PATH/src/wv/$(printf "%04d" "$1")" && exit 0 + +number="na" +for i in $(seq -w 1 1000) ; do + if [ ! -e "$WWW_DEFAULT_PATH/src/wv/$i" ] ; then + number="$i" + break + fi +done + +[ "$number" = "na" ] && echo "exhausted range" && exit 1 + +nvim "$WWW_DEFAULT_PATH/src/wv/$number" + diff --git a/scripts/sh/wv-wc b/scripts/sh/wv-wc new file mode 100755 index 0000000..e13b27e --- /dev/null +++ b/scripts/sh/wv-wc @@ -0,0 +1,2 @@ +#!/bin/sh +# |