« get me outta code hell

dotfiles - Miscellaneous configuration files of my personal use
about summary refs log tree commit diff
path: root/scripts/acme/Wikitag
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/acme/Wikitag')
-rwxr-xr-xscripts/acme/Wikitag36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/acme/Wikitag b/scripts/acme/Wikitag
new file mode 100755
index 0000000..645bf1a
--- /dev/null
+++ b/scripts/acme/Wikitag
@@ -0,0 +1,36 @@
+#!/bin/zsh
+
+while getopts ":l" opt; do; case $opt in
+	l) label=1 ;;
+	*) exit 1
+esac; done
+
+cycle=( artist track album group )
+
+src=$(</dev/stdin)
+
+if [[ ! $src =~ '^\[\[.*\]\]$' ]]; then
+	printf '[[%s]]' "$src"; exit 0
+fi
+
+src=$src:s/[[//:s/]]//
+
+if [[ ! $src =~ '^[^ ]+:' ]]; then
+	if [[ -v label ]];
+	then printf '[[%s:%s|%s]]' ${cycle[1]} $(wikebab <<< "$src") "$src"
+	else printf '[[%s:%s]]' ${cycle[1]} $(wikebab <<< "$src")
+	fi; exit 0
+fi
+
+replacer=${src%:*}
+value=${src#*:}
+
+place=${cycle[(ie)$replacer]}
+length=${#cycle}
+if (( place >= length )); then
+	next=1
+else
+	(( next = place + 1 ))
+fi
+
+printf '[[%s:%s]]' ${cycle[$next]} $value
\ No newline at end of file