add stuffz

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

100
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')"
case $command in if printf '%s\n' "$dot" | grep ',' >/dev/null 2>&1
"c")
clear
;;
"d")
printf "%s: d: Command not implemented.\n" "$argv0"
;;
"i")
printf "%s: i: Command not implemented.\n" "$argv0"
;;
"p")
printf "%s\n" "$content"
;;
"q")
if test -n "$(printf "%s\n" "$content" | diff "$1" -)"
then then
printf "%s: %s: Unsaved changes in the buffer. Quit anyway? [y/N] " \ dot_start="$(printf '%s\n' "$dot" | cut -d ',' -f 1)"
"$argv0" \ dot_end="$(printf '%s\n' "$dot" | cut -d ',' -f 2)"
"$1"
read quit
if [ "$quit" = "y" ]; then
break
else else
continue dot_start="$dot"
dot_end="$dot"
fi fi
else
break command="$(printf '%s\n' "$line" | sed s/"$dot"//)"
fi case "$command" in
;; # argless
"s") a* | d* | i* | p* | q*)
content="$(printf "%s" "$content" | sed "$args")" ! test "$(len "$command")" = 1 \
;; && printf "%s: Extraneous input.\n" "$(printf '%s\n' "$command" | head -c 1)" \
"w") && continue
printf "%s\n" "$content" > "$1" case "$command" in
;; a*)
sed -i "$f" "$dot_end"a\
"$(ingest)" ;;
d*) sed -i "$f" "$dot_start,$dot_end"d ;;
i*) sed -i "$f" "$dot_start"i\
"$(ingest)" ;;
p*) <"$f" sed "$dot_start,$dot_end"p ;;
q*) return 0 ;;
esac
# argful
s*) printf "%s: Command not implemented.\n" s ;;
w*) printf "%s: Command not implemented.\n" w ;;
*) printf "?\n" ;;
esac esac
done done
}
shift test -n "$1" \
done || en
while test -n "$1"
do file="$1" en && shift || break
done