From e7fb0c055e089565406001ba30fec1080ffafa60 Mon Sep 17 00:00:00 2001 From: dtb Date: Mon, 3 Jul 2023 09:02:46 +0000 Subject: [PATCH] add stuffz --- en | 104 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 48 deletions(-) diff --git a/en b/en index 63ec7ea..ee9d568 100755 --- a/en +++ b/en @@ -1,63 +1,71 @@ #!/bin/sh -e -# Copyright (c) 2023 Emma Tebibyte +# Copyright (c) 2023 Emma Tebibyte, dtb # SPDX-License-Identifier: FSFAP # # Copying and distribution of this file, with or without modification, are # 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" +exec >&2 > " - 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 - "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 - printf "%s: %s: Unsaved changes in the buffer. Quit anyway? [y/N] " \ - "$argv0" \ - "$1" - read quit - if [ "$quit" = "y" ]; then - break - else - continue - fi - else - break - fi - ;; - "s") - content="$(printf "%s" "$content" | sed "$args")" - ;; - "w") - printf "%s\n" "$content" > "$1" - ;; + command="$(printf '%s\n' "$line" | sed s/"$dot"//)" + case "$command" in + # argless + a* | d* | i* | p* | q*) + ! test "$(len "$command")" = 1 \ + && printf "%s: Extraneous input.\n" "$(printf '%s\n' "$command" | head -c 1)" \ + && continue + 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 done +} - shift -done +test -n "$1" \ + || en + +while test -n "$1" + do file="$1" en && shift || break + done -- 2.46.1