about summary refs log tree commit diff stats
path: root/bin/fcard
diff options
context:
space:
mode:
Diffstat (limited to 'bin/fcard')
-rwxr-xr-xbin/fcard45
1 files changed, 45 insertions, 0 deletions
diff --git a/bin/fcard b/bin/fcard
new file mode 100755
index 0000000..e4a851d
--- /dev/null
+++ b/bin/fcard
@@ -0,0 +1,45 @@
+#!/bin/sh
+# flash card substitute
+# usage: fcard dict.tsv section
+# the -z code is extremely wip, don't use it
+
+while getopts z: opt
+do
+	case $opt in
+	z)	RAND="|grabbag" ;;
+	?)	printf '%s\n' "idiot" 1>&2 && exit 2 ;;
+	esac
+done
+shift $((OPTIND - 1))
+
+rand() {
+	tr -cd '[:digit:]'</dev/urandom|fold -w 4|head -1
+}
+grabbag() {
+#	digit urandom % number applicable lines
+	size="$(wc -l)"
+	oldlist="$(cat)"
+	newlist=""
+	a=0
+	while a="$size"; do
+	z="$(($(rand)%a))"
+	newlist="$(cut -d ' ' -f "$z"<<EOF
+$oldlist
+EOF
+) "
+	oldlist="$(cut -d ' ' -f "-$((z-1)),$((z+1))-" <<EOF
+$oldlist
+EOF
+)"
+#	add z to space-delim'd list
+#	remove from input list
+	a=$((a-1))
+	done
+	printf '%s\n' "$newlist"
+}
+for num in $(eval 'grep -n "${2:-.}"\$ "$1"|cut -d : -f 1'"$RAND"); do
+	sed -n "$num"P "$1" | cut -f 1 | tr '\n' '\t'
+	read -r _
+	sed -n "$num"P "$1" | cut -f 2 | sed '/^$/D'
+	printf '\n'
+done