bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fg via keybind modifies tty settings


From: Martin D Kealey
Subject: Re: fg via keybind modifies tty settings
Date: Thu, 28 Nov 2024 20:52:10 +1000

On Thu, 28 Nov 2024 at 13:54, David Moberg <kaddkaka@gmail.com> wrote:

> Yes, if seems like the way to do this in bash. It's unfortunate because
> doing it with a binding is more elegant as it avoids polluting the terminal
> output and shell history.
>

You can avoid polluting history by inserting " fg\n" with a leading space.
(You'd also have to set HISTCONTROL to include either ignorespace or
ignoreboth.)

If it was me, I'd want the "fg" visually presented, but if you really hate
it ...

I would write a function that clears the unwanted line off the terminal.
And then arrange for a binding to put that name  and “ ; fg\n” into the
input.

However you still can't prevent ‘fg’ from printing out either the command
that it's bringing to the foreground, or a complaint that it cannot do so,
so I would try to highlight that, like this:

hide () {
  printf '\e[%sA\r\e[K' "$1"  # move up and erase the previous prompt
  [[ -n $2 ]] && printf '\e[1;31m%s> \e[m' "$2" # output a small indication
that this is a hotkey activation
}
bind '"\e[20;2~": "\C-e\C-u hide 1 s-F9 ; fg\n"'  # shift-F9

In this, “hide” is completely generic; you can give it whatever extra
prompt you want, separately from the command to be hidden. In a few cases
you might have to increase the "up" parameter, particularly when you're
testing by hand.

-Martin

PS: some folk will tell you to use tput “for portability”, but all
terminals that *didn't* support VT100-compatibility wound up in landfills
or museums two decades ago; and the few incompatibilities that remain are
quite poorly described by terminfo, which isn't really a surprise given how
poorly it describes many 4-decade-old features.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]