add stuffz

This commit is contained in:
dtb 2023-07-03 09:02:46 +00:00
parent dadfad0650
commit e7fb0c055e

104
en
View File

@ -1,63 +1,71 @@
#!/bin/sh -e #!/bin/sh -e
# Copyright (c) 2023 Emma Tebibyte # Copyright (c) 2023 Emma Tebibyte, dtb
# SPDX-License-Identifier: FSFAP # SPDX-License-Identifier: FSFAP
# #
# Copying and distribution of this file, with or without modification, are # Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice and this # permitted in any medium without royalty provided the copyright notice and this
# notice are preserved. This file is offered as-is, without any warranty. # notice are preserved. This file is offered as-is, without any warranty.'
#
# dtb forfeits any and all copyright to their respective changes to this document.
argv0="$0" argv0="$0"
exec >&2 </dev/tty
if test -z "$1"; then ingest(){
printf "Usage: %s file...\n" "$argv0" buffer=''
fi while true
do
while test -n "$1"; do line="$(head -n 1)"
content="$(cat "$1")" test "$line" = '.' \
cat "$1" && break
buffer="$(printf '%s%s\n' "$buffer" "$line")"
done
printf '%s' "$buffer"
}
len(){ printf "%s\n" "$1" | wc -c; }
en(){
while true; do while true; do
printf ">> " printf ">> "
read -r command args line="$(head -n 1)"
dot="(printf '%s\n' "$line" | sed 's/[[^[:digit:]]*?$//g')"
if printf '%s\n' "$dot" | grep ',' >/dev/null 2>&1
then
dot_start="$(printf '%s\n' "$dot" | cut -d ',' -f 1)"
dot_end="$(printf '%s\n' "$dot" | cut -d ',' -f 2)"
else
dot_start="$dot"
dot_end="$dot"
fi
case $command in command="$(printf '%s\n' "$line" | sed s/"$dot"//)"
"c") case "$command" in
clear # argless
;; a* | d* | i* | p* | q*)
"d") ! test "$(len "$command")" = 1 \
printf "%s: d: Command not implemented.\n" "$argv0" && printf "%s: Extraneous input.\n" "$(printf '%s\n' "$command" | head -c 1)" \
;; && continue
"i") case "$command" in
printf "%s: i: Command not implemented.\n" "$argv0" a*)
;; sed -i "$f" "$dot_end"a\
"p") "$(ingest)" ;;
printf "%s\n" "$content" d*) sed -i "$f" "$dot_start,$dot_end"d ;;
;; i*) sed -i "$f" "$dot_start"i\
"q") "$(ingest)" ;;
if test -n "$(printf "%s\n" "$content" | diff "$1" -)" p*) <"$f" sed "$dot_start,$dot_end"p ;;
then q*) return 0 ;;
printf "%s: %s: Unsaved changes in the buffer. Quit anyway? [y/N] " \ esac
"$argv0" \ # argful
"$1" s*) printf "%s: Command not implemented.\n" s ;;
read quit w*) printf "%s: Command not implemented.\n" w ;;
if [ "$quit" = "y" ]; then *) printf "?\n" ;;
break
else
continue
fi
else
break
fi
;;
"s")
content="$(printf "%s" "$content" | sed "$args")"
;;
"w")
printf "%s\n" "$content" > "$1"
;;
esac esac
done done
}
shift test -n "$1" \
done || en
while test -n "$1"
do file="$1" en && shift || break
done