mirror of
https://github.com/ej52/proxmox-scripts.git
synced 2025-07-26 09:28:18 +02:00
refactor: clear the scrollback buffer properly on all terminals
This commit is contained in:
parent
30b2386e30
commit
d78e6ae325
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
trap trapexit EXIT EXIT SIGINT SIGTERM
|
trap trapexit EXIT SIGTERM
|
||||||
|
|
||||||
TEMPDIR=$(mktemp -d)
|
TEMPDIR=$(mktemp -d)
|
||||||
TEMPLOG="$TEMPDIR/tmplog"
|
TEMPLOG="$TEMPDIR/tmplog"
|
||||||
@ -14,7 +14,7 @@ cd $TEMPDIR
|
|||||||
touch $TEMPLOG
|
touch $TEMPLOG
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
log() { logs=$(cat $TEMPLOG | sed -e "s/34/32/g" | sed -e "s/info/success/g"); printf "\033c$logs\n\e[34m[info] $*\e[0m\n" | tee $TEMPLOG; }
|
log() { logs=$(cat $TEMPLOG | sed -e "s/34/32/g" | sed -e "s/info/success/g"); clear && printf "\033c\e[3J$logs\n\e[34m[info] $*\e[0m\n" | tee $TEMPLOG; }
|
||||||
runcmd() {
|
runcmd() {
|
||||||
LASTCMD=$(grep -n "$*" "$0" | sed "s/[[:blank:]]*runcmd//");
|
LASTCMD=$(grep -n "$*" "$0" | sed "s/[[:blank:]]*runcmd//");
|
||||||
if [[ "$#" -eq 1 ]]; then
|
if [[ "$#" -eq 1 ]]; then
|
||||||
@ -25,13 +25,14 @@ runcmd() {
|
|||||||
}
|
}
|
||||||
trapexit() {
|
trapexit() {
|
||||||
status=$?
|
status=$?
|
||||||
|
|
||||||
if [[ $status -eq 0 ]]; then
|
if [[ $status -eq 0 ]]; then
|
||||||
logs=$(cat $TEMPLOG | sed -e "s/34/32/g" | sed -e "s/info/success/g")
|
logs=$(cat $TEMPLOG | sed -e "s/34/32/g" | sed -e "s/info/success/g")
|
||||||
printf "\033c$logs\n";
|
clear && printf "\033c\e[3J$logs\n";
|
||||||
elif [[ -s $TEMPERR ]]; then
|
elif [[ -s $TEMPERR ]]; then
|
||||||
logs=$(cat $TEMPLOG | sed -e "s/34/31/g" | sed -e "s/info/error/g")
|
logs=$(cat $TEMPLOG | sed -e "s/34/31/g" | sed -e "s/info/error/g")
|
||||||
err=$(cat $TEMPERR | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' | rev | cut -d':' -f1 | rev | cut -d' ' -f2-)
|
err=$(cat $TEMPERR | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' | rev | cut -d':' -f1 | rev | cut -d' ' -f2-)
|
||||||
printf "\033c$logs\e[33m\n$0: line $LASTCMD\n\e[33;2;3m$err\e[0m\n"
|
clear && printf "\033c\e[3J$logs\e[33m\n$0: line $LASTCMD\n\e[33;2;3m$err\e[0m\n"
|
||||||
else
|
else
|
||||||
printf "\e[33muncaught error occurred\n\e[0m"
|
printf "\e[33muncaught error occurred\n\e[0m"
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user