Skip to content

Commit

Permalink
Use traps to ensure tty settings get restored
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru committed Jan 1, 2025
1 parent 94e2add commit d9b0786
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rootfs/etc/profile.d/_01-launch-warning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
# so the cursor never advances. Then we eval the message with backspaces removed.
# We have to then add some extra characters to erase the eval command.
function warn_if_piped() {
local saved_stty=$(stty -g)
local saved_stty
saved_stty=$(stty -g)
trap 'stty "$saved_stty"' EXIT

stty -echo -opost

local mesg cmd xb m fx bx feval beval
Expand Down Expand Up @@ -53,6 +56,7 @@ function warn_if_piped() {
echo -n "$beval$feval$beval"

stty "$saved_stty"
trap - EXIT
}

warn_if_piped
Expand Down

0 comments on commit d9b0786

Please sign in to comment.