From de2bce40eed0f462643004fdf5ec560223123974 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 13 Jul 2023 15:35:38 -0600 Subject: [PATCH] better deleting --- en | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/en b/en index b4526f9..3728c33 100755 --- a/en +++ b/en @@ -12,13 +12,13 @@ exec >&2 &2 - exit 1 + exit 64 # sysexits.h(3) EX_USAGE fi if ! command -v mktemp >/dev/null 2>&1 then printf "%s: mktemp(1): Missing dependency." "$argv0" - exit 1 + exit 69 # sysexits.h(3) EX_UNAVAILABLE fi help="$(printf "Commands:\n\ @@ -39,13 +39,13 @@ en(1) Copyright (c) 2023 Emma Tebibyte\n")" while test -n "$1"; do content="$(cat "$1")" file="$(printf "%s\n" "$1" | tr -d '/')" + temp_highlight="$(mktemp -t "XXXXX$file")" # use bat for syntax highlighting if it’s available, but remove the frills if command -v bat >/dev/null then # there has to be a temp file for writing the highlighted text to syntax_h() { - temp_highlight="$(mktemp -t "XXXXX$file")" printf "%s\n" "$1" >"$temp_highlight" bat -pp --color always "$temp_highlight" } @@ -66,7 +66,7 @@ while test -n "$1"; do ;; "a") read -r append - content="$(printf "%s\n%s" "$content" "$append")" + content="$content$append" ;; "c") clear @@ -77,8 +77,10 @@ while test -n "$1"; do else for line in $(printf "%s\n" "$args" | sed 's/,/\n/g') do - del="$(printf "%s\n" "$content" | head -n "$line" | tail -n 1)" - content="$(printf "%s\n" "$content" | sed -n "/$del/!p")" + content="$(printf "%s\n" "$content" |\ + awk -v l="$line" 'NR == l {next} {print}')" + #del="$(printf "%s\n" "$content" | head -n "$line" | tail -n 1)" + #content="$(printf "%s\n" "$content" | sed -n "/$del/!p")" done fi ;;