made en print to stdout by default

This commit is contained in:
Emma Tebibyte 2024-04-18 10:10:22 -06:00
parent 5bbbd60cfc
commit 4f0788048b
Signed by: emma
GPG Key ID: 06FA419A1698C270

71
en
View File

@ -1,41 +1,37 @@
#!/bin/sh -e #!/bin/sh -e
# Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media> # Copyright (c) 2023-2024 Emma Tebibyte <emma@tebibyte.media>
# 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.
argv0="$0"
exec >&2 </dev/tty
if test -z "$1"; then if test -z "$1"; then
printf "Usage: %s file...\n" "$argv0" 1>&2 printf "Usage: %s file...\n" "$0" 1>&2
exit 64 # sysexits.h(3) EX_USAGE exit 64 # sysexits.h(3) EX_USAGE
fi fi
if ! command -v mktemp >/dev/null 2>&1 if ! command -v mktemp >/dev/null 2>&1
then then
printf "%s: mktemp(1): Missing dependency." "$argv0" printf "%s: mktemp(1): missing dependency" "$0"
exit 69 # sysexits.h(3) EX_UNAVAILABLE exit 69 # sysexits.h(3) EX_UNAVAILABLE
fi fi
help="$(printf "Commands:\n\ help="$(printf "Commands:\n\
/ display lines containing a string.\n\ / display lines containing a string\n\
? displays this help message.\n\ ? display this help message\n\
a appends a line to the current buffer.\n\ a append a line to the current buffer\n\
c clears the screen.\n\ c clear the screen\n\
d deletes a line.\n\ d delete a line\n\
e evaluates a command in the shell environment.\n\ e evaluate a command in the shell environment\n\
i inserts a line into the buffer at position line.\n\ i insert a line into the buffer at position line\n\
p prints the current buffer.\n\ p print the current buffer\n\
q terminates editing.\n\ q terminate editing\n\
r applies a regular expression to the current buffer.\n\ r applie a regular expression to the current buffer\n\
w writes the current buffer to the file.\n\ x exit the program without writing output\n\
\n\ \n\
To learn more about a command verb, type \`? verb'.\n\ en(1) Copyright (c) 20232024 Emma Tebibyte\n")"
en(1) Copyright (c) 2023 Emma Tebibyte\n")"
while test -n "$1"; do while test -n "$1"; do
content="$(cat "$1")" content="$(cat "$1")"
@ -55,22 +51,22 @@ while test -n "$1"; do
fi fi
while true; do while true; do
printf ">> " printf ">> " >/dev/tty
read -r command args read -r command args
case $command in case $command in
"/") "/")
if test -z "$args"; then if test -z "$args"; then
printf "%s: %s: Missing argument.\n" "$argv0" "$args" printf "%s: %s: missing argument\n" "$0" "$args"
else else
printf "%s" "$content" | nl | sed -n "/$args/p" printf "%s" "$content" | nl | sed -n "/$args/p"
fi fi
;; ;;
"?") "?")
if test -z "$args"; then if test -z "$args"; then
printf "%s: %s\n" "$argv0" "$help" printf "%s: %s\n" "$0" "$help"
else else
printf "%s: Command-specific help not implemented.\n" "$argv0" 1>&2 printf "%s: command-specific help not implemented\n" "$0" 1>&2
continue continue
fi fi
;; ;;
@ -87,7 +83,7 @@ while test -n "$1"; do
;; ;;
"d") "d")
if test -z "$args"; then if test -z "$args"; then
printf "%s: %s: Missing argument.\n" "$argv0" "$command" 1>&2 printf "%s: %s: Missing argument.\n" "$0" "$command" 1>&2
else else
for line in $(printf "%s\n" "$args" | sed 's/,/\n/g') for line in $(printf "%s\n" "$args" | sed 's/,/\n/g')
do do
@ -100,39 +96,28 @@ while test -n "$1"; do
eval "$args" || true eval "$args" || true
;; ;;
"i") "i")
printf "%s: i: Command not implemented.\n" "$argv0" 1>&2 printf "%s: i: Command not implemented.\n" "$0" 1>&2
;; ;;
"p") "p")
out="$(syntax_h "$content" 2>/dev/null || printf "%s\n" "$content")" out="$(syntax_h "$content" 2>/dev/null || printf "%s\n" "$content")"
printf "%s\n" "$out" | nl -ba printf "%s\n" "$out" | nl -ba >/dev/tty
;; ;;
"q") "q")
if test -n "$(printf "%s\n" "$content" | diff "$1" -)" break
then
printf "%s: %s: Unsaved changes in the buffer. Quit anyway? [y/N] " \
"$argv0" \
"$1"
read -r quit
if [ "$quit" = "y" ]; then
break
else
continue
fi
else
break
fi
;; ;;
"r") "r")
content="$(printf "%s" "$content" | sed -e "$args")" content="$(printf "%s" "$content" | sed -e "$args")"
;; ;;
"w") "x")
printf "%s\n" "$content" > "$1" exit
;; ;;
*) *)
printf "%s: %s: No such command.\n" "$argv0" "$command" printf "%s: %s: unrecognized command\n" "$0" "$command"
;; ;;
esac esac
done done
printf '%s\n' "$content"
shift shift
done done