Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Passwords are implemented as a result of insecurity.


devel / comp.unix.shell / Nice prompt [Bash specific]

SubjectAuthor
* Nice prompt [Bash specific]Kaz Kylheku
+* Nice prompt [Bash specific]Janis Papanagnou
|+* Nice prompt [Bash specific]Kaz Kylheku
||`* Nice prompt [Bash specific]Janis Papanagnou
|| `* Nice prompt [Bash specific]Kaz Kylheku
||  `* Nice prompt [Bash specific]Janis Papanagnou
||   +- Nice prompt [Bash specific]Kaz Kylheku
||   `* Nice prompt [Bash specific]Janis Papanagnou
||    `* Nice prompt [Bash specific]Kaz Kylheku
||     `* Nice prompt [Bash specific]Janis Papanagnou
||      `* Nice prompt [Bash specific]Kaz Kylheku
||       `- Nice prompt [Bash specific]Janis Papanagnou
|`- Nice prompt [Bash specific]Keith Thompson
+* Nice prompt [Bash specific]Kaz Kylheku
|`* Nice prompt [Bash specific]Chris Elvidge
| `- Nice prompt [Bash specific]Kaz Kylheku
+* Nice prompt [Bash specific]Kaz Kylheku
|+- Nice prompt [Bash specific]Kaz Kylheku
|`- Nice prompt [Bash specific]Kaz Kylheku
+* Nice prompt [Bash specific]Kaz Kylheku
|`* Nice prompt [Bash specific]Kaz Kylheku
| `* Nice prompt [Bash specific]Kaz Kylheku
|  `- Nice prompt [Bash specific]Kaz Kylheku
+* Nice prompt [Bash specific]Kaz Kylheku
|`* Nice prompt [Bash specific]Janis Papanagnou
| `- Nice prompt [Bash specific]Kaz Kylheku
+* Nice prompt [Bash specific]Janis Papanagnou
|`* Nice prompt [Bash specific]Janis Papanagnou
| `* Nice prompt [Bash specific]Kaz Kylheku
|  `- Nice prompt [Bash specific]Janis Papanagnou
`* Nice prompt [Bash specific]Janis Papanagnou
 +* Nice prompt [Bash specific]Richard Harnden
 |`- Nice prompt [Bash specific]Janis Papanagnou
 +* Nice prompt [Bash specific]Kaz Kylheku
 |`* Nice prompt [Bash specific]Janis Papanagnou
 | `- Nice prompt [Bash specific]Janis Papanagnou
 `- Nice prompt [Bash specific]Kaz Kylheku

Pages:12
Nice prompt [Bash specific]

<20230803112254.131@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6514&group=comp.unix.shell#6514

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Nice prompt [Bash specific]
Date: Thu, 3 Aug 2023 18:31:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 73
Message-ID: <20230803112254.131@kylheku.com>
Injection-Date: Thu, 3 Aug 2023 18:31:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f577c4f42aa1f569bd3a056883839435";
logging-data="924977"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XNtguP7VPwJpanjUwsyQXVL/tO9hYq+A="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:XED4i2tf92YDQKuUQblP9/Vlyz8=
 by: Kaz Kylheku - Thu, 3 Aug 2023 18:31 UTC

I "redesigned" my shell prompt yesterday.

I now have the current date/time, host name and working directory
(possibly shortened) in a scroll-protected status line at the bottom of
the terminal.

The prompt is just a dollar sign (PS1='\$ ') which is very refreshing.

Here is the code. I have this in a ~/.bash_functions file that gets
sourced.

Using the PROMPT_COMMAND hook mechanism, before every command, we
update the status area and scroll-protect it. Before that, we check whether the
LINES or COLUMNS has changed, in which case we call prepare_terminal
to reserve the bottom row for ourselves, and make sure the cursor is
off thatline. This happens on the first call to update_status_line
also, since old_lines and old_cols are zero.

Whenever a command has a termination status other than successful, we
print the line !<n>! where <n> is the status before the prompt.
Logic in update_status_line ensures that repetitions of this are suppressed
if the user hits enter on an empty line.

prepare_terminal()
{ stty rows $((LINES - 1))
printf "\n\033[1A"
old_lines=$LINES
old_cols=$COLUMNS
}

old_cmdno=0
old_lines=0
old_cols=0

update_status_line()
{ local exit=$?
local getcmdno='\#'
local cmdno=${getcmdno@P}
local esc=$(printf "\033")
local pwd=$PWD
local dots=

[ $LINES -eq $old_lines -a $COLUMNS -eq $old_cols ] || prepare_terminal

while true; do
[ "${pwd#/*/}" == "$pwd" ] && break
local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME $dots$pwd"
local status_nohl="$(date +%m-%d/%H:%M) $HOSTNAME $dots$pwd"
[ ${#status_nohl} -le $COLUMNS ] && break
pwd=${pwd#/}
pwd=/${pwd#*/}
dots='...'
done

[ ${#status_nohl} -gt $COLUMNS ] && return

printf "${esc}7$esc[%s;1H$esc[K%s$esc[1;%sr${esc}8" $((LINES + 1)) "$status" $
LINES
if [ $exit -ne 0 -a $cmdno -ne $old_cmdno ] ; then
printf "!%s!\n" $exit
fi
old_cmdno=$cmdno
}

PROMPT_COMMAND='update_status_line'

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<uaj711$1b2hb$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6522&group=comp.unix.shell#6522

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Fri, 4 Aug 2023 17:55:12 +0200
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <uaj711$1b2hb$1@dont-email.me>
References: <20230803112254.131@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 4 Aug 2023 15:55:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b6483f700969c62b4b44792b8c756da0";
logging-data="1411627"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+DAPzn0dbITZc4FB6yq8b"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:n58ztkUC/yLvf87WmDjIxnx0+7s=
In-Reply-To: <20230803112254.131@kylheku.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Fri, 4 Aug 2023 15:55 UTC

On 03.08.2023 20:31, Kaz Kylheku wrote:
> I "redesigned" my shell prompt yesterday.
>
> [...]

Hi Kaz, I wanted to try out your script and have two questions...

My bash doesn't seem to support the @P in cmdno=${getcmdno@P}
what does it do?

At certain places you use in printf contexts \033 or define a
variable esc to carry that value. In Kornshell I use \E or \e
for ANSI escapes, and my bash also supports that. Is there in
bash with PROMPT_COMMAND some technical necessity to use $esc ?

Janis

>
> prepare_terminal()
> {
> stty rows $((LINES - 1))
> printf "\n\033[1A"
> old_lines=$LINES
> old_cols=$COLUMNS
> }
>
> old_cmdno=0
> old_lines=0
> old_cols=0
>
> update_status_line()
> {
> local exit=$?
> local getcmdno='\#'
> local cmdno=${getcmdno@P}
> local esc=$(printf "\033")
> local pwd=$PWD
> local dots=
>
> [ $LINES -eq $old_lines -a $COLUMNS -eq $old_cols ] || prepare_terminal
>
> while true; do
> [ "${pwd#/*/}" == "$pwd" ] && break
> local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME $dots$pwd"
> local status_nohl="$(date +%m-%d/%H:%M) $HOSTNAME $dots$pwd"
> [ ${#status_nohl} -le $COLUMNS ] && break
> pwd=${pwd#/}
> pwd=/${pwd#*/}
> dots='...'
> done
>
> [ ${#status_nohl} -gt $COLUMNS ] && return
>
> printf "${esc}7$esc[%s;1H$esc[K%s$esc[1;%sr${esc}8" $((LINES + 1)) "$status" $
> LINES
> if [ $exit -ne 0 -a $cmdno -ne $old_cmdno ] ; then
> printf "!%s!\n" $exit
> fi
> old_cmdno=$cmdno
> }
>
> PROMPT_COMMAND='update_status_line'
>
>

Re: Nice prompt [Bash specific]

<20230804101131.699@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6524&group=comp.unix.shell#6524

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Fri, 4 Aug 2023 17:26:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <20230804101131.699@kylheku.com>
References: <20230803112254.131@kylheku.com> <uaj711$1b2hb$1@dont-email.me>
Injection-Date: Fri, 4 Aug 2023 17:26:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="42a4086d1e45385610f8b9f4428b75ac";
logging-data="1440824"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18armRJ7ojbEg7ojKCcwZcfeGIdKBAj+Hk="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:hnfGmypMvenPjSF/4T19gg2xuK4=
 by: Kaz Kylheku - Fri, 4 Aug 2023 17:26 UTC

On 2023-08-04, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 03.08.2023 20:31, Kaz Kylheku wrote:
>> I "redesigned" my shell prompt yesterday.
>>
>> [...]
>
> Hi Kaz, I wanted to try out your script and have two questions...

Hi Janis,

Thanks for trying it; if you get it working 100%, you will like it,
I'm sure. The idea is to set the prompt to just PS=1'\$ ' which
is clean and refreshing, and feels like old Unix. All the junk
like showing the date, time, host name and current directory, goes into
a scroll-protected status line at the bottom.

> My bash doesn't seem to support the @P in cmdno=${getcmdno@P}
> what does it do?

This is a newer feature (Bash 4.4+)? It specifies prompt-like
expansion.

The variable getcmdno contains a code that is normally used
in the PS1 prompt. @{getcmdno@P} handles that variable as if it
were PS1, expanding that code.

The only reason I used this was to gain access to the current prompt
line number. I don't think there is any other way to get to it. The line
number lets us distinguish whether the user is just hitting Enter on an
empty line:

$
$
$ _

or actually issuing new commands.

When the user issues an empty line, the value of $? observed by the
PROMPT_COMMAND hook remains the same. I wanted the failed status like
!1! to be printed only once, like this:

$ false
!1!
$
$
$ _

and not:

$ false
!1!
$
!1!
$
!1!
$ _

which is achieved by observing no change in the prompt number.

So it is all for aesthetics.

Someone who doesn't mind that, or doesn't want the termination
status, or does something else with it can remove all that
code.

> At certain places you use in printf contexts \033 or define a
> variable esc to carry that value. In Kornshell I use \E or \e
> for ANSI escapes, and my bash also supports that. Is there in
> bash with PROMPT_COMMAND some technical necessity to use $esc ?

I initially had a hard-coded escape.

By defining it as a named term, we can do this:

esc=ESC # for debugging

The performance hit of the extra substitutions is not an issue.

Also, the reason the following variables are defined the way they are is
to support reloading of the code.

old_cmdno=${old_cmdno-0}
old_lines=${old_lines-0}
old_cols=${old_cols-0}

If the variables already exist, their values are left alone, so that
update_statusS_line will not call prepare_terminal, which will steal
another line of display, which is an annoying behavior.

In Common Lisp, (defvar variable value) will not evaluate the value
expression or assign the variable if the variable already exists. This
supports reloading of modules without disturbing their global variables.
(You use defparameter, which always assigns, if you want that.)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<20230804103236.533@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6525&group=comp.unix.shell#6525

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Fri, 4 Aug 2023 17:36:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <20230804103236.533@kylheku.com>
References: <20230803112254.131@kylheku.com>
Injection-Date: Fri, 4 Aug 2023 17:36:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="42a4086d1e45385610f8b9f4428b75ac";
logging-data="1440824"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yZcd8GlMoOhk3N07nYFWri/II/SR5ULQ="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:f1pzGDCJCfH3UwEl/dbL7L61ulA=
 by: Kaz Kylheku - Fri, 4 Aug 2023 17:36 UTC

On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> while true; do
> [ "${pwd#/*/}" == "$pwd" ] && break
> local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME $dots$pwd"
> local status_nohl="$(date +%m-%d/%H:%M) $HOSTNAME $dots$pwd"
> [ ${#status_nohl} -le $COLUMNS ] && break
> pwd=${pwd#/}
> pwd=/${pwd#*/}
> dots='...'
> done

Erratum: the break test at the top of the loop body should be moved to the
bottom:

while true; do
local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME $dots$pwd"
local status_len=$((${#status} - ${#status_esc}))
[ $status_len -le $COLUMNS ] && break
pwd=${pwd#/}
pwd=/${pwd#*/}
dots='...'
[ "${pwd#/*/}" == "$pwd" ] && break
done

This causes an issue reported by a user on Mastodon, that
when you change to a directory like / or /home, the status
line disappears. We need the loop body executed unconditionally
at least to calculate a status line, and then to stop iterating
if the path cannot be reduced further after that.

There is one more check after the loop for a status line that cannot fit
the current $COLUMNS with, in which case it is turned off.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<87sf8yk59o.fsf@nosuchdomain.example.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6526&group=comp.unix.shell#6526

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Fri, 04 Aug 2023 11:54:11 -0700
Organization: None to speak of
Lines: 26
Message-ID: <87sf8yk59o.fsf@nosuchdomain.example.com>
References: <20230803112254.131@kylheku.com> <uaj711$1b2hb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="ad89738ee6b746bb8bd9b1180a09fd6e";
logging-data="1463191"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BsKD2UUg4krBhK/g7wY35"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Y2aighkPNE9RwSUj3ut00Vm6gwA=
sha1:EIH1xplHua07NVbwP9C0Sw/KS9s=
 by: Keith Thompson - Fri, 4 Aug 2023 18:54 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
[...]
> Hi Kaz, I wanted to try out your script and have two questions...
>
> My bash doesn't seem to support the @P in cmdno=${getcmdno@P}
> what does it do?

What version of bash are you using? This feature was introduced in bash
4.4, released in 2016.

From "bash info param":

'${PARAMETER@OPERATOR}'
The expansion is either a transformation of the value of PARAMETER
or information about PARAMETER itself, depending on the value of
OPERATOR. Each OPERATOR is a single letter:
[...]
'P'
The expansion is a string that is the result of expanding the
value of PARAMETER as if it were a prompt string (*note
Controlling the Prompt::).

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: Nice prompt [Bash specific]

<uajlks$1datq$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6527&group=comp.unix.shell#6527

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris@mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Fri, 4 Aug 2023 21:04:43 +0100
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <uajlks$1datq$1@dont-email.me>
References: <20230803112254.131@kylheku.com> <20230804103236.533@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 4 Aug 2023 20:04:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4b4d8b8b3b9b4027989f770880629b86";
logging-data="1485754"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/raKDWjdNbGCKA5vlbhIAmhCHWgt5rEL0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:ukGoRFIJqbdUoQJBR6scPDNf7OU=
Content-Language: en-GB
In-Reply-To: <20230804103236.533@kylheku.com>
 by: Chris Elvidge - Fri, 4 Aug 2023 20:04 UTC

On 04/08/2023 18:36, Kaz Kylheku wrote:
> On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>> while true; do
>> [ "${pwd#/*/}" == "$pwd" ] && break
>> local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME $dots$pwd"
>> local status_nohl="$(date +%m-%d/%H:%M) $HOSTNAME $dots$pwd"
>> [ ${#status_nohl} -le $COLUMNS ] && break
>> pwd=${pwd#/}
>> pwd=/${pwd#*/}
>> dots='...'
>> done
>
> Erratum: the break test at the top of the loop body should be moved to the
> bottom:
>
> while true; do
> local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME $dots$pwd"
> local status_len=$((${#status} - ${#status_esc}))
> [ $status_len -le $COLUMNS ] && break
> pwd=${pwd#/}
> pwd=/${pwd#*/}
> dots='...'
> [ "${pwd#/*/}" == "$pwd" ] && break
> done
>
> This causes an issue reported by a user on Mastodon, that
> when you change to a directory like / or /home, the status
> line disappears. We need the loop body executed unconditionally
> at least to calculate a status line, and then to stop iterating
> if the path cannot be reduced further after that.
>
> There is one more check after the loop for a status line that cannot fit
> the current $COLUMNS with, in which case it is turned off.
>

Yes, nice, but you lose a line on the terminal (but who cares?). If you
use Esc]2; you can update the terminal title. However, no highlights.

Should PROMPT_COMMAND= be PROMPT_COMMAND[0]= for modernity?

As it happens, mine looks like this:
PROMPT_COMMAND=(
[0]="echo -ne \"\\033]11;#204A87\\007\""
[1]="echo -ne \"\\033]2;\${USER}@\${HOSTNAME} (\${IP}) : (\${KERNEL},
\${BASHVR}) : \$(pwd) : \${LAST_COMMAND}\\007\""
)

Cheers

--

Chris Elvidge, England
I AM NOT THE NEW DALAI LAMA

Re: Nice prompt [Bash specific]

<20230804135254.427@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6528&group=comp.unix.shell#6528

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Fri, 4 Aug 2023 20:56:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <20230804135254.427@kylheku.com>
References: <20230803112254.131@kylheku.com>
<20230804103236.533@kylheku.com> <uajlks$1datq$1@dont-email.me>
Injection-Date: Fri, 4 Aug 2023 20:56:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="42a4086d1e45385610f8b9f4428b75ac";
logging-data="1498202"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sH5r9u6IJXU3dV1hNvRTWnrXk8Ubxsm0="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:344OH5kancigYLYZLM+PT2lWrLg=
 by: Kaz Kylheku - Fri, 4 Aug 2023 20:56 UTC

On 2023-08-04, Chris Elvidge <chris@mshome.net> wrote:
> Yes, nice, but you lose a line on the terminal (but who cares?). If you
> use Esc]2; you can update the terminal title. However, no highlights.

Yes; putting stuff into the title is an old trick.

That stuff is far away from where my attention is, usually close
to the prompt.

Secondly, it's sometimes occupied. Right now I'm in screen session; when
you swap screens, screen updates the title.
(Though, that doesn't mean we can't clobber it, too.)

> Should PROMPT_COMMAND= be PROMPT_COMMAND[0]= for modernity?

I guess so; if there is a stack/list of them now, we want to
just be one entry. But probably [0] is already occupied?
We want to add to the array, not clobber an arbitrary index.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<20230804202215.733@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6529&group=comp.unix.shell#6529

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 03:30:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 90
Message-ID: <20230804202215.733@kylheku.com>
References: <20230803112254.131@kylheku.com>
Injection-Date: Sat, 5 Aug 2023 03:30:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46dbbd806c109ed3b898addd6bab648";
logging-data="1712998"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eXQ8PUPDy+pRaTMuaGEjdfCzj8sDNB38="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:l/hVQhNJcQLTDOedpLIzSmUD6fo=
 by: Kaz Kylheku - Sat, 5 Aug 2023 03:30 UTC

On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> I "redesigned" my shell prompt yesterday.

I have discovered an issue. When I run the "top" utility from procps-ng,
and then exit, stupidly puts the cursor into the scroll-protected area,
for whatever reason.

I implemented a countermeasure. As the last interaction with the
terminal, after we print the status line, and restore the cursor
position, we ask the terminal the X, Y position. If it is beyond the
last line, then we move the cursor to the first colum of the last line.

To read the X, Y position, we issue ESC[6h, and then parse the response
which is like ESC[<y>;<x>]R. Bash's read function lets us do this
nicely: read -s -d R <var>. Read until the delimiter R, silently
without echoing.

I will probably optimize things. Now that we are getting the ecurrent
position, we don't have to use the ESC 7 and ESC 8 trick for saving
and restoring position. We can just get the position once,
do the status line and then before restoring the position, check
for a valid line number.

For now it's like this:

old_cmdno=${old_cmdno-0}
old_lines=${old_lines-0}
old_cols=${old_cols-0}

prepare_terminal()
{ stty rows $((LINES - 1))
printf "\n\033[1A"
old_lines=$LINES
old_cols=$COLUMNS
}

get_current_line()
{ local esc=$(printf "\033")
local response
printf "$esc[6n" > /dev/tty
read -s -d R response < /dev/tty
local IFS="[;"
set -- $response
printf "%s\n" "$2"
}

update_status_line()
{ local exit=$?
local getcmdno='\#'
local cmdno=${getcmdno@P}
local esc=$(printf "\033")
local pwd=$PWD
local dots=

[ $LINES -eq $old_lines -a $COLUMNS -eq $old_cols ] || prepare_terminal

local status_esc="$esc[7m$esc[m"

while true; do
local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME $dots$pwd"
local status_len=$((${#status} - ${#status_esc}))
[ $status_len -le $COLUMNS ] && break
pwd=${pwd#/}
pwd=/${pwd#*/}
dots='...'
[ "${pwd#/*/}" == "$pwd" ] && break
done

status_len=$((${#status} - ${#status_esc}))

[ $status_len -gt $COLUMNS ] && status=

printf "${esc}7$esc[%s;1H$esc[K%s$esc[1;%sr${esc}8" $((LINES + 1)) "$status" $LINES
if [ $exit -ne 0 -a $cmdno -ne $old_cmdno ] ; then
printf "!%s!\n" $exit
fi

local curln=$(get_current_line)

if [ $curln > $LINES ]; then
printf "$esc[%s;1H" $LINES
fi

old_cmdno=$cmdno
}

PROMPT_COMMAND='update_status_line'

Re: Nice prompt [Bash specific]

<20230804203131.349@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6530&group=comp.unix.shell#6530

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 03:33:42 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <20230804203131.349@kylheku.com>
References: <20230803112254.131@kylheku.com> <20230804202215.733@kylheku.com>
Injection-Date: Sat, 5 Aug 2023 03:33:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46dbbd806c109ed3b898addd6bab648";
logging-data="1714741"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aPtvkLY+MXgdUfq9qYBjzAMD6k/uHl0k="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:80xRLDH6gBAGzGPqwNq98aO2gTI=
 by: Kaz Kylheku - Sat, 5 Aug 2023 03:33 UTC

On 2023-08-05, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>> I "redesigned" my shell prompt yesterday.
>
> I have discovered an issue. When I run the "top" utility from procps-ng,
> and then exit, stupidly puts the cursor into the scroll-protected area,
> for whatever reason.

The fix has the unexpected tiny benefit that when you quit top, the top
output left on the screen no longer scrolls up by one line The cursor is
placed over the last line of the top output, and you can still see the
first line of the display.

Normally, top occupies the entire screen. When you quit, it puts the
cursor on the next line after that, so the display scrolls by one line.

Now it's putting the cursor into the status line which we adjust to the
previous line, and so no scrolling takes place.

Re: Nice prompt [Bash specific]

<20230804225019.548@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6532&group=comp.unix.shell#6532

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 05:50:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <20230804225019.548@kylheku.com>
References: <20230803112254.131@kylheku.com> <20230804202215.733@kylheku.com>
Injection-Date: Sat, 5 Aug 2023 05:50:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46dbbd806c109ed3b898addd6bab648";
logging-data="1741116"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YLF54K6fqo3aLoAxAz117x8MhzS10n2o="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:tMjr+7Lpl6E/pvwMKfLeFQfPTqs=
 by: Kaz Kylheku - Sat, 5 Aug 2023 05:50 UTC

On 2023-08-05, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> if [ $curln > $LINES ]; then

You want to make this $curln -gt $LINES, if you don't want to keep
creating a file called 52 (or however many lines you have).

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<20230804232820.515@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6533&group=comp.unix.shell#6533

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 06:28:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <20230804232820.515@kylheku.com>
References: <20230803112254.131@kylheku.com>
Injection-Date: Sat, 5 Aug 2023 06:28:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46dbbd806c109ed3b898addd6bab648";
logging-data="1749768"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199fUSrplr2P76CfHReFOV8t36BlLTrW88="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:d/EjLcgX1Mw9143jZvTm9TPjcZ0=
 by: Kaz Kylheku - Sat, 5 Aug 2023 06:28 UTC

On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> I "redesigned" my shell prompt yesterday.

This now lives here:

https://www.kylheku.com/cgit/kabapro/tree/bash-prompt.sh

Re: Nice prompt [Bash specific]

<20230805010859.999@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6534&group=comp.unix.shell#6534

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 08:10:27 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <20230805010859.999@kylheku.com>
References: <20230803112254.131@kylheku.com>
Injection-Date: Sat, 5 Aug 2023 08:10:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46dbbd806c109ed3b898addd6bab648";
logging-data="1773475"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lNPwPRKwqIL2aQ2hlwioNMi/EAb+ejQk="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:4P63A0U3AWYYGJgU/u2WZXuxQtw=
 by: Kaz Kylheku - Sat, 5 Aug 2023 08:10 UTC

On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> I "redesigned" my shell prompt yesterday.

LOL, I got the clock in the status line to update spontaneously.

$ trap update_status_line ALRM
$ while true; do kill -ALRM $$ ; sleep 15 ; done &
[1] 19410

Background process sends SIGALRM every 15 seconds; status
line updates.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<ual8di$1n673$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6536&group=comp.unix.shell#6536

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 12:31:13 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ual8di$1n673$1@dont-email.me>
References: <20230803112254.131@kylheku.com> <20230805010859.999@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Aug 2023 10:31:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="625abbf5d081b0b4e2f01c00ed20ab0a";
logging-data="1808611"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/a/jeVWOW73viVjmDtsRTj"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:0hZLDbKCT2RR4YPdbQ2NOt609Xk=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <20230805010859.999@kylheku.com>
 by: Janis Papanagnou - Sat, 5 Aug 2023 10:31 UTC

On 05.08.2023 10:10, Kaz Kylheku wrote:
> On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>> I "redesigned" my shell prompt yesterday.
>
> LOL, I got the clock in the status line to update spontaneously.
>
> $ trap update_status_line ALRM
> $ while true; do kill -ALRM $$ ; sleep 15 ; done &
> [1] 19410
>
> Background process sends SIGALRM every 15 seconds; status
> line updates.

I think this extension introduced a bug; I started a bash shell,
sourced the script, exited the bash instance, and on a new start
and sourcing I get every 15s (even after leaving bash completely)
./bash-prompt-V0: line 73: kill: (4118) - No such process
I got rid by the timer background process only after a 'pkill bash'
(couldn't identify the actual PID under my own or init's UID).

I suppose it needs at least a process cleanup before termination?

Janis

PS: Does bash support (as known from ksh) process bound timers?

Re: Nice prompt [Bash specific]

<ualidd$1ojql$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6538&group=comp.unix.shell#6538

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 15:21:48 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ualidd$1ojql$1@dont-email.me>
References: <20230803112254.131@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Aug 2023 13:21:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="49c59df721c3408459000c2cce36acb0";
logging-data="1855317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DUsYq4Nmr9bSYzJY4M/Ix"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:u+fEfdmZ9H614rBtvsqMm3TbQ7E=
In-Reply-To: <20230803112254.131@kylheku.com>
 by: Janis Papanagnou - Sat, 5 Aug 2023 13:21 UTC

On 03.08.2023 20:31, Kaz Kylheku wrote:
> I "redesigned" my shell prompt yesterday.
> [...]

Yet another question...

> printf "${esc}7$esc[%s;1H$esc[K%s$esc[1;%sr${esc}8" $((LINES + 1)) "$status" $LINES

What does $esc[1;%sr (with $LINES expanded for %s) do?
Say, \033[1;24r
(It seems I cannot find the ANSI control character 'r'.)

Janis

Re: Nice prompt [Bash specific]

<uall88$1p0c0$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6539&group=comp.unix.shell#6539

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 16:10:15 +0200
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <uall88$1p0c0$1@dont-email.me>
References: <20230803112254.131@kylheku.com> <uaj711$1b2hb$1@dont-email.me>
<20230804101131.699@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Aug 2023 14:10:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="49c59df721c3408459000c2cce36acb0";
logging-data="1868160"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hvOUhW86+iqNnNVl6oHsM"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:+gJ9nN29sPgIdNftzKRdtlasHHQ=
In-Reply-To: <20230804101131.699@kylheku.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sat, 5 Aug 2023 14:10 UTC

On 04.08.2023 19:26, Kaz Kylheku wrote:
>
> Thanks for trying it; if you get it working 100%, you will like it,
> I'm sure. The idea is to set the prompt to just PS=1'\$ ' which
> is clean and refreshing, and feels like old Unix. All the junk
> like showing the date, time, host name and current directory, goes into
> a scroll-protected status line at the bottom.

I can already say that I like the idea! Formerly we already had "all
the junk" in a separate line by adding a \n before the $ prompt. The
fixed (and protected) status line is certainly a step forward. When
(or if) I write my ksh variant - bash is not my standard shell -, I
want to make further changes; the attributes I like to be displayed
are of course different, but I also prefer to change the cursor
position for the command input to be constantly at the bottom of the
screen. - The short time special case that the first commands are
entered at the top of the screen and only if the screen gets filled
it moves downwards until it permanently reaches the bottom of the
screen is somewhat strange if you think about it; after the first
or second command entered my screen is anyway full and the cursor
at the bottom, so why not keep it static where it usually is. For
my taste that would be another little step forwards.

I want to strive to this layout...

+-----
|
| Scroll area (Input and Output)
|
:
:
|
| Prompt (Input)
| Status (scroll protected)
+-----

(That faintly reminds me the old mainframe times.)

Janis

Re: Nice prompt [Bash specific]

<uallvj$1p3qe$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6540&group=comp.unix.shell#6540

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 16:22:43 +0200
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <uallvj$1p3qe$1@dont-email.me>
References: <20230803112254.131@kylheku.com> <ualidd$1ojql$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Aug 2023 14:22:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="49c59df721c3408459000c2cce36acb0";
logging-data="1871694"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NqfRPUh+b4fCmqhAON3zI"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:wE/jrXjVkSLIafVs2Q/NQa8pBLg=
In-Reply-To: <ualidd$1ojql$1@dont-email.me>
 by: Janis Papanagnou - Sat, 5 Aug 2023 14:22 UTC

On 05.08.2023 15:21, Janis Papanagnou wrote:
> On 03.08.2023 20:31, Kaz Kylheku wrote:
>> I "redesigned" my shell prompt yesterday.
>> [...]
>
> Yet another question...
>
>> printf "${esc}7$esc[%s;1H$esc[K%s$esc[1;%sr${esc}8" $((LINES + 1)) "$status" $LINES
>
> What does $esc[1;%sr (with $LINES expanded for %s) do?
> Say, \033[1;24r
> (It seems I cannot find the ANSI control character 'r'.)

I suppose I found the answer...

| The basics are: configure your device's shell to set scroll
| region once the command is accepted from user (equivalent of
| printf "\033[1,24r") -- and reset it once it completes --
| printf "\033[r".
[Stackexchange]

....presuming the differences (';' vs. ',') are not changing semantics.

>
> Janis
>

Re: Nice prompt [Bash specific]

<20230805082545.663@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6541&group=comp.unix.shell#6541

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 15:36:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <20230805082545.663@kylheku.com>
References: <20230803112254.131@kylheku.com>
<20230805010859.999@kylheku.com> <ual8di$1n673$1@dont-email.me>
Injection-Date: Sat, 5 Aug 2023 15:36:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46dbbd806c109ed3b898addd6bab648";
logging-data="1892950"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JdulcPfP1uDVy3lgnYtgZ52VeWFflIuM="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:U/05EkkGsdaDWpn9qbH9Wh+ysP0=
 by: Kaz Kylheku - Sat, 5 Aug 2023 15:36 UTC

On 2023-08-05, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 05.08.2023 10:10, Kaz Kylheku wrote:
>> On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>>> I "redesigned" my shell prompt yesterday.
>>
>> LOL, I got the clock in the status line to update spontaneously.
>>
>> $ trap update_status_line ALRM
>> $ while true; do kill -ALRM $$ ; sleep 15 ; done &
>> [1] 19410
>>
>> Background process sends SIGALRM every 15 seconds; status
>> line updates.
>
> I think this extension introduced a bug; I started a bash shell,
> sourced the script, exited the bash instance, and on a new start
> and sourcing I get every 15s (even after leaving bash completely)
> ./bash-prompt-V0: line 73: kill: (4118) - No such process

I looked for this problem proactively but didn't see it! Looks
like it has to be handled. A simple hack would be to terminate if
the kill fails. The ugly error should go to /dev/null.

I noticed another problem. In a fresh login shell, if I do a reverse
search with Ctrl-R for something, and cancel the search with Ctrl-C,
the background process dies. Orphaning the process so that it becomes
the child of PID 1 might fix it. It needs to be removed from the
TTY session so that it doesn't get signals.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<20230805083839.766@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6542&group=comp.unix.shell#6542

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 15:40:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <20230805083839.766@kylheku.com>
References: <20230803112254.131@kylheku.com> <ualidd$1ojql$1@dont-email.me>
<uallvj$1p3qe$1@dont-email.me>
Injection-Date: Sat, 5 Aug 2023 15:40:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46dbbd806c109ed3b898addd6bab648";
logging-data="1892950"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/jvZpPrP/mGFd7WU5dZ8jSICvTJZ8LBE="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:KUYqI3jF5Y2iVX3eoxhh1qWZ+tg=
 by: Kaz Kylheku - Sat, 5 Aug 2023 15:40 UTC

On 2023-08-05, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 05.08.2023 15:21, Janis Papanagnou wrote:
>> On 03.08.2023 20:31, Kaz Kylheku wrote:
>>> I "redesigned" my shell prompt yesterday.
>>> [...]
>>
>> Yet another question...
>>
>>> printf "${esc}7$esc[%s;1H$esc[K%s$esc[1;%sr${esc}8" $((LINES + 1)) "$status" $LINES
>>
>> What does $esc[1;%sr (with $LINES expanded for %s) do?
>> Say, \033[1;24r
>> (It seems I cannot find the ANSI control character 'r'.)
>
> I suppose I found the answer...
>
>| The basics are: configure your device's shell to set scroll
>| region once the command is accepted from user (equivalent of
>| printf "\033[1,24r") -- and reset it once it completes --
>| printf "\033[r".
> [Stackexchange]
>
> ...presuming the differences (';' vs. ',') are not changing semantics.

The documented syntax requires a semicolon. If it works with the
comma, it's some exstension; it doesn't on the terminal I'm using.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<20230805084100.353@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6543&group=comp.unix.shell#6543

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sat, 5 Aug 2023 15:45:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <20230805084100.353@kylheku.com>
References: <20230803112254.131@kylheku.com> <uaj711$1b2hb$1@dont-email.me>
<20230804101131.699@kylheku.com> <uall88$1p0c0$1@dont-email.me>
Injection-Date: Sat, 5 Aug 2023 15:45:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e46dbbd806c109ed3b898addd6bab648";
logging-data="1892950"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jw/GPuZ+RnqoYKcdAs/e7MHkbqAE9lb8="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Io/vhTJXmLuzwMI0sEaYwIRE08M=
 by: Kaz Kylheku - Sat, 5 Aug 2023 15:45 UTC

On 2023-08-05, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 04.08.2023 19:26, Kaz Kylheku wrote:
>>
>> Thanks for trying it; if you get it working 100%, you will like it,
>> I'm sure. The idea is to set the prompt to just PS=1'\$ ' which
>> is clean and refreshing, and feels like old Unix. All the junk
>> like showing the date, time, host name and current directory, goes into
>> a scroll-protected status line at the bottom.
>
> I can already say that I like the idea! Formerly we already had "all
> the junk" in a separate line by adding a \n before the $ prompt. The
> fixed (and protected) status line is certainly a step forward.

I like being able to cut and paste commands in examples without
the chore of editing out the long prompts down to '$'.

> (or if) I write my ksh variant - bash is not my standard shell -, I
> want to make further changes; the attributes I like to be displayed
> are of course different, but I also prefer to change the cursor
> position for the command input to be constantly at the bottom of the
> screen.

The logic is already there; it's executed when the cursor intrudes
into the status line.

We just have to execute that logic whenever the prior cursor position is
not exactly one line before the status line.

Maybe just executing the move unconditionally would also work,
in which case saving the previous position can be dropped.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<uamn1g$1u1u7$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6546&group=comp.unix.shell#6546

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sun, 6 Aug 2023 01:46:55 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uamn1g$1u1u7$1@dont-email.me>
References: <20230803112254.131@kylheku.com> <ualidd$1ojql$1@dont-email.me>
<uallvj$1p3qe$1@dont-email.me> <20230805083839.766@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Aug 2023 23:46:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6ac391c4cda2c85edfe9a55bb6afa368";
logging-data="2033607"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UeYj2TqIHEvGh7xe/aPoq"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:RA8AMkPqu69k3SsbXEw+IwWOiuU=
In-Reply-To: <20230805083839.766@kylheku.com>
 by: Janis Papanagnou - Sat, 5 Aug 2023 23:46 UTC

On 05.08.2023 17:40, Kaz Kylheku wrote:
> On 2023-08-05, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>> On 05.08.2023 15:21, Janis Papanagnou wrote:
>> [ANSI escape codes, Stackexchange quote]
>>
>> ...presuming the differences (';' vs. ',') are not changing semantics.
>
> The documented syntax requires a semicolon. If it works with the
> comma, it's some exstension; it doesn't on the terminal I'm using.

If it doesn't work it was probably just a typo of that poster.

Janis

Re: Nice prompt [Bash specific]

<20230805185618.891@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6547&group=comp.unix.shell#6547

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Sun, 6 Aug 2023 01:58:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <20230805185618.891@kylheku.com>
References: <20230803112254.131@kylheku.com> <20230804232820.515@kylheku.com>
Injection-Date: Sun, 6 Aug 2023 01:58:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8cfc75365922a18c54795bf707c63d9f";
logging-data="2184224"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xeDmp9+BQRRZ7WJsfTRBd7mpcjPzw08M="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:BSCh8CItF6AFGmKy8a1SUeiHaAw=
 by: Kaz Kylheku - Sun, 6 Aug 2023 01:58 UTC

On 2023-08-05, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>> I "redesigned" my shell prompt yesterday.
>
> This now lives here:
>
> https://www.kylheku.com/cgit/kabapro/tree/bash-prompt.sh

Renamed. It's not a prompt but a status line.
So it's called Basta! (BAsh STAtus).

https://www.kylheku.com/cgit/basta/tree/

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<uas7e5$370cu$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6552&group=comp.unix.shell#6552

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Tue, 8 Aug 2023 03:57:24 +0200
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <uas7e5$370cu$1@dont-email.me>
References: <20230803112254.131@kylheku.com> <uaj711$1b2hb$1@dont-email.me>
<20230804101131.699@kylheku.com> <uall88$1p0c0$1@dont-email.me>
<20230805084100.353@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 8 Aug 2023 01:57:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="521ef36333c047c9aeee7ae1946d5b07";
logging-data="3375518"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FYwWde+YVW9A7/kBgp1oa"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:mLCVKDq8n/9FFzJONHeEeT3PZlc=
In-Reply-To: <20230805084100.353@kylheku.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 8 Aug 2023 01:57 UTC

On 05.08.2023 17:45, Kaz Kylheku wrote:
> On 2023-08-05, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> [...]
>> (or if) I write my ksh variant - bash is not my standard shell -, I
>> want to make further changes; the attributes I like to be displayed
>> are of course different, but I also prefer to change the cursor
>> position for the command input to be constantly at the bottom of the
>> screen.
>
> The logic is already there; it's executed when the cursor intrudes
> into the status line.
>
> We just have to execute that logic whenever the prior cursor position is
> not exactly one line before the status line.
>
> Maybe just executing the move unconditionally would also work,
> in which case saving the previous position can be dropped.

I've written some experimental code using some Kornshell mechanisms,
so it differs from yours. (I've adopted/adapted your name though; I
like "basta" and named mine accordingly "kosta", kornshell status :-)
One thing I used (that I think doesn't exist in bash) are discipline
functions; I use them to update changes in rows/columns, and trigger
prompt PS1 access. And I have a few own details. Yet I've a lot to
add to that basic frame (path shortening, coloring, maybe composing
status lines, ...), it certainly can be shortened, and needs testing.
But I'm anyway just playing around with your status line idea...

Janis

function LINES.set { .kosta.rows=${.sh.value} ; .kosta.update ;}
function COLUMNS.set { .kosta.cols=${.sh.value} ;}
function PS1.get { .kosta.compose ;}

namespace kosta
{ typeset -i rows=${LINES} cols=${COLUMNS}
typeset -i prompt_line=$((rows-1))
typeset -i status_line=$((rows))

function update
{
prompt_line=$((rows-1))
status_line=$((rows))
}

function compose
{
prev_rc=$?
PS1='(!)$ '
status="${USER}@${HOSTNAME}:${PWD/${HOME}\//\~/} ${SHLVL_P}"

printf '\E[%d;1H\E[K' status_line # goto(row,column);
clear-to-eol;
if (( prev_rc > 255 )) # signal
then printf 'SIG %d (%s)! ' prev_rc-256 $( kill -l $((prev_rc)) )
elif (( prev_rc > 0 )) # error
then printf 'ERR %d! ' prev_rc
fi
printf '%s' "${status}"
printf '\E[1;%dr' prompt_line # scroll-region(from,to);
printf '\E[%d;1H' prompt_line # goto(row,column);
}

} # namespace kosta

Re: Nice prompt [Bash specific]

<20230807223339.993@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6555&group=comp.unix.shell#6555

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Tue, 8 Aug 2023 05:35:05 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <20230807223339.993@kylheku.com>
References: <20230803112254.131@kylheku.com> <uaj711$1b2hb$1@dont-email.me>
<20230804101131.699@kylheku.com> <uall88$1p0c0$1@dont-email.me>
<20230805084100.353@kylheku.com> <uas7e5$370cu$1@dont-email.me>
Injection-Date: Tue, 8 Aug 2023 05:35:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2e64aa5a28c0801679f7444cde71de51";
logging-data="3437232"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/s++gHR5VG5sXJDo/zuOIoC6LZos043fE="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Ad3uzXdT2IBGVI2PR7PX9bq2uZc=
 by: Kaz Kylheku - Tue, 8 Aug 2023 05:35 UTC

On 2023-08-08, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 05.08.2023 17:45, Kaz Kylheku wrote:
>> On 2023-08-05, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>> [...]
>>> (or if) I write my ksh variant - bash is not my standard shell -, I
>>> want to make further changes; the attributes I like to be displayed
>>> are of course different, but I also prefer to change the cursor
>>> position for the command input to be constantly at the bottom of the
>>> screen.
>>
>> The logic is already there; it's executed when the cursor intrudes
>> into the status line.
>>
>> We just have to execute that logic whenever the prior cursor position is
>> not exactly one line before the status line.
>>
>> Maybe just executing the move unconditionally would also work,
>> in which case saving the previous position can be dropped.
>
> I've written some experimental code using some Kornshell mechanisms,
> so it differs from yours. (I've adopted/adapted your name though; I
> like "basta" and named mine accordingly "kosta", kornshell status :-)

Great!

See, you can still innovate in the area of 1970's ECMA/ANSI terminal
control combined with 1980's Unix shells.

Re: Nice prompt [Bash specific]

<20230809115648.832@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6556&group=comp.unix.shell#6556

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED.s010614aedbccc4a9.vc.shawcable.net!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Wed, 9 Aug 2023 19:25:38 -0000 (UTC)
Organization: A noiseless patient Spider
Message-ID: <20230809115648.832@kylheku.com>
References: <20230803112254.131@kylheku.com>
<20230804232820.515@kylheku.com> <20230805185618.891@kylheku.com>
Injection-Date: Wed, 9 Aug 2023 19:25:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="s010614aedbccc4a9.vc.shawcable.net:70.79.182.7";
logging-data="65323"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: slrn/1.0.3 (Linux)
 by: Kaz Kylheku - Wed, 9 Aug 2023 19:25 UTC

On 2023-08-06, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> On 2023-08-05, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>> On 2023-08-03, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>>> I "redesigned" my shell prompt yesterday.
>>
>> This now lives here:
>>
>> https://www.kylheku.com/cgit/kabapro/tree/bash-prompt.sh
>
> Renamed. It's not a prompt but a status line.
> So it's called Basta! (BAsh STAtus).
>
> https://www.kylheku.com/cgit/basta/tree/

I'm seeing a weird glitch with Gnome terminal.

I have multiple terminal tabs open, each running a Bash with a Basta
status line.

When I switch from one tab to another, I see a spontaneous cursor
movement and scrolling a few seconds later.

What is happening is that the value of $LINES has spontaneously changed.
The basta.update_status function notices this and handles it like a
resize.

No resize has taken place; I'm just switching tabs.

This is some Gnome Terminal B.S. Probably, whenever a tab is selected to
be current, it is sending a SIGWINCH to the TTY session.

I'm guessing, they are doing it just in case the application window had
changed since the last time that tab was shown, whether it actually
changed or not.

Anyway, resize will just have to be handled more smoothly, so there
is no glitch.

Another, unrelated issue is that the background signal for updating the
screen can occur in the middle of an command line editing action. The
escape sequences get bungled.

I suspect my latest public changes already have the effect of mostly
mitigating it. I refactored the update function into two smaller ones,
and the trap handler only calls one of the two. That one no longer
interrogates the current position of the cursor, and so it isn't
processing input from the TTY that could be fooled by user input. I'm
keeping an eye on this issue to see how much of a problem it still is,
if any.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Nice prompt [Bash specific]

<20230809131211.547@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6557&group=comp.unix.shell#6557

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED.s010614aedbccc4a9.vc.shawcable.net!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Nice prompt [Bash specific]
Date: Wed, 9 Aug 2023 20:14:29 -0000 (UTC)
Organization: A noiseless patient Spider
Message-ID: <20230809131211.547@kylheku.com>
References: <20230803112254.131@kylheku.com>
<20230804232820.515@kylheku.com> <20230805185618.891@kylheku.com>
<20230809115648.832@kylheku.com>
Injection-Date: Wed, 9 Aug 2023 20:14:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="s010614aedbccc4a9.vc.shawcable.net:70.79.182.7";
logging-data="76575"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: slrn/1.0.3 (Linux)
 by: Kaz Kylheku - Wed, 9 Aug 2023 20:14 UTC

On 2023-08-09, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> Anyway, resize will just have to be handled more smoothly, so there
> is no glitch.

.... and I fixed it. Part the fix is to catch the window change
signal: "trap basta.update_status WINCH"!

This way, after a resize, we immediately restore the status line
and the scroll-protected region; the user has no chance to run
a command with the scroll-protection off where their output
then runs into the status line, which then scrolls up.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor