#!/bin/sh LC_ALL=en_US.UTF-8 export LC_ALL DIR="${0%/*}" LDIR="${DIR##*/}" ACT="$2" CMD="$1" printf "SUPER COOL GOPHER LINE EDITOR/LIST THINGY:\n\n" print_list() { if ! [ -f "$DIR/001.txt" ]; then printf "Hello World <-- what you can't delete, edit you must!\n" > "$DIR/001.txt" fi for ITEM in "$DIR/"*.txt; do NAME="${ITEM##*/}" NAME_NOEXT="${NAME%%.txt}" while IFS= read -r line do printf '%03g| %s\n' "$NAME_NOEXT" "$line"; done < "$ITEM" done } print_commandline() { printf "\n[7| ADD DEL EDIT |/$LDIR?do|server|port]" printf "\n[1| <- go back |/|server|port]"; } _checknumber() { if [ $NUM -gt 999 ]; then printf "\n\nNope, the number range is 0 - 999.\n\n" print_list; print_commandline; exit; fi } _extract() { DO=; NUM=; TXT=; DO=${CMD%% *} _tmp=${CMD#* } NUM=${_tmp%% *} TXT=${_tmp#* } case $NUM in (*[!0-9]*|'') printf "\nNope, this was not a number.\n\n"; print_list; print_commandline; exit; ;; esac _checknumber NUM=$(printf '%03g' "${_tmp%% *}") } action_add() { if [ -f "$DIR/$NUM.txt" ]; then printf "Nope: Duplicate line number($NUM)\n\n" else printf '%s' "$TXT" | par -w72qie > "$DIR/$NUM.txt" fi } action_del() { if ! [ -f "$DIR/$NUM.txt" ]; then printf "Nope: Line $NUM doesn't exist.\n\n" else rm -f "$DIR/$NUM.txt" fi } action_edit() { printf '%s' "$TXT" | par -w72qie > "$DIR/$NUM.txt" } if [ "$ACT" == "" ]; then print_list print_commandline exit; fi if [ "$ACT" == "do" ]; then _extract case "$DO" in (A|ADD|a|add) action_add; ;; (D|DEL|d|del|rm) action_del; ;; (E|EDIT|e|edit) action_edit; ;; esac print_list print_commandline exit; fi