• Re: [ksh] Show command number in shell prompt

    From hymie!@21:1/5 to who on Tue Sep 24 12:59:06 2024
    In our last episode, the evil Dr. Lacto had captured our hero,
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com>, who said:
    Not long ago I added an '!' (exclamation mark) to my prompt to have
    it get expanded to the command number [in Kornshell]; PS1='(!)$ '
    The effect is that a new shell instance starts with the number 1000
    which incidentally equals the HISTSIZE. - Any ideas what could have
    gone wrong here?

    Nothing has gone wrong.

    HISTSIZE=1000 means that the maximum size of your history is 1000. Once it hits that level, the oldest entries are dropped, and the newest entries
    are added to the end.

    So every command you issue is always the last command in the history.
    Since the history is full, it's always command number 1000.

    --hymie! http://nasalinux.net/~hymie hymie@nasalinux.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to All on Tue Sep 24 14:45:46 2024
    Not long ago I added an '!' (exclamation mark) to my prompt to have
    it get expanded to the command number [in Kornshell]; PS1='(!)$ '
    The effect is that a new shell instance starts with the number 1000
    which incidentally equals the HISTSIZE. - Any ideas what could have
    gone wrong here?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to All on Tue Sep 24 15:23:56 2024
    On 24.09.2024 14:59, hymie! wrote:
    In our last episode, the evil Dr. Lacto had captured our hero,
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com>, who said:
    Not long ago I added an '!' (exclamation mark) to my prompt to have
    it get expanded to the command number [in Kornshell]; PS1='(!)$ '
    The effect is that a new shell instance starts with the number 1000
    which incidentally equals the HISTSIZE. - Any ideas what could have
    gone wrong here?

    Nothing has gone wrong.

    HISTSIZE=1000 means that the maximum size of your history is 1000. Once it hits that level, the oldest entries are dropped, and the newest entries
    are added to the end.

    So every command you issue is always the last command in the history.
    Since the history is full, it's always command number 1000.

    Hmm.. - that explains, maybe, part of it. Thanks.

    I'm still irritated; if I see in one shell session a value of 11059
    (which is an indication that the numbers created by '!' don't wrap)
    I'm astonished that the counting in a new window will start at 1000
    (and not at 1 or at the maximum previous value).

    I've just closed a window with an actual maximum command number of
    1643, and "restoring"[*] that window will continue at 1643.

    Still puzzling...

    Janis

    [*] Note: Closing a shell window and re-opening it anew will work
    on the previous, same history file.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hymie!@21:1/5 to who on Tue Sep 24 17:40:01 2024
    In our last episode, the evil Dr. Lacto had captured our hero,
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com>, who said:
    On 24.09.2024 14:59, hymie! wrote:
    In our last episode, the evil Dr. Lacto had captured our hero,
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com>, who said:
    Not long ago I added an '!' (exclamation mark) to my prompt to have
    it get expanded to the command number [in Kornshell]; PS1='(!)$ '
    The effect is that a new shell instance starts with the number 1000
    which incidentally equals the HISTSIZE. - Any ideas what could have
    gone wrong here?

    Nothing has gone wrong.

    HISTSIZE=1000 means that the maximum size of your history is 1000. Once it >> hits that level, the oldest entries are dropped, and the newest entries
    are added to the end.

    So every command you issue is always the last command in the history.
    Since the history is full, it's always command number 1000.

    Hmm.. - that explains, maybe, part of it. Thanks.

    I'm still irritated; if I see in one shell session a value of 11059
    (which is an indication that the numbers created by '!' don't wrap)
    I'm astonished that the counting in a new window will start at 1000
    (and not at 1 or at the maximum previous value).

    I don't use this feature, and I don't have ksh, just bash and zsh.
    Bash has separate options for

    \! the history number of this command
    \# the command number of this command

    I don't know what your goal is, but maybe ksh has these two options, and you want the other one?

    For the record, every time I open a bash shell, \! starts at 51 (HISTSIZE + 1) and \# starts at 1.

    --hymie! http://nasalinux.net/~hymie hymie@nasalinux.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to All on Tue Sep 24 21:56:13 2024
    On 24.09.2024 19:40, hymie! wrote:

    I'm still irritated; if I see in one shell session a value of 11059
    (which is an indication that the numbers created by '!' don't wrap)
    I'm astonished that the counting in a new window will start at 1000
    (and not at 1 or at the maximum previous value).

    I don't use this feature, and I don't have ksh, just bash and zsh.
    Bash has separate options for

    \! the history number of this command
    \# the command number of this command

    I don't know what your goal is, but maybe ksh has these two options, and you want the other one?

    In ksh I know only of '!', a single unquoted literal exclamation mark.

    But never mind. - My goal was just to not constantly see in my shell
    instances what appears to me to look like an inconsistency. - Another (bash-)prompt posting inspired me to post. But I also know only few
    folks use ksh nowadays, most use bash, so I didn't really expect any
    "solution" (sort of). Functionally there's no apparent drawback, so I
    can live with it. Thanks.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Janis Papanagnou on Tue Sep 24 21:31:33 2024
    On Tue, 24 Sep 2024 15:23:56 +0200, Janis Papanagnou wrote:

    [*] Note: Closing a shell window and re-opening it anew will work on the previous, same history file.

    I typically have over a dozen shell windows open at a time. They would all happily clobber the same history file, which somewhat limits its use for
    me.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Lawrence D'Oliveiro on Wed Sep 25 00:41:21 2024
    On 24.09.2024 23:31, Lawrence D'Oliveiro wrote:
    On Tue, 24 Sep 2024 15:23:56 +0200, Janis Papanagnou wrote:

    [*] Note: Closing a shell window and re-opening it anew will work on the
    previous, same history file.

    I typically have over a dozen shell windows open at a time. They would all happily clobber the same history file, which somewhat limits its use for
    me.

    Of course I have a more complex setup that uses an own history file
    per "window"; I use for example a name like ".sh_history_pts_57"
    (using 'HISTFILE').

    I have yet more functions associated, e.g. a "CWD" or a window title
    per "window", etc., to be able to keep and restore yet more context.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Keith Thompson on Tue Sep 24 22:53:22 2024
    On 2024-09-24, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
    Lawrence D'Oliveiro <ldo@nz.invalid> writes:
    On Tue, 24 Sep 2024 15:23:56 +0200, Janis Papanagnou wrote:
    [*] Note: Closing a shell window and re-opening it anew will work on the >>> previous, same history file.

    I typically have over a dozen shell windows open at a time. They would all >> happily clobber the same history file, which somewhat limits its use for
    me.

    Using a different $HISTFILE for each shell avoids that. I assign
    consistent names to shell windows, under tmux, and I construct $HISTFILE
    from the name.

    In the TXR Lisp listener, I implemented an incredible idea from the
    far future: on exit, it combines the to-be-saved history with new
    material that may have appeared in the history file by the termination
    of a parallel session.

    The algorithm is

    1. Load the existing history (using a new, shadow instance of the
    listener object), and save it to a temporary file, trimming the
    amount of history to the currently configured limit.

    2. Append to that temporary file all the new lines from the
    current session.

    3. Rename the temporary file to the real history file name.

    There is no locking: don't be somehow exiting your interactive sessions simultaneously.

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Keith Thompson on Wed Sep 25 02:24:02 2024
    On 25.09.2024 01:35, Keith Thompson wrote:
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
    [...]
    If you use numbered history references, they refer to the history
    number, not the command number. For example, !25 will execute the 25th
    command from your history. This could be confusing if you show the
    command number in $PS1.

    And of course the "history" command shows history numbers, not command numbers.

    The command number doesn't seem to be used for anything other than
    showing the number of commands issued in the current shell process. (Personally, I don't find the command number to be useful information.)

    Terminology obviously varies; ksh speaks only about "command number"
    and refers to it as '!' in the prompt, and all the history commands
    (or aliases), fc, hist, history, speak only about "command numbers".

    So bash's "history numbers" ('\!') are the equivalent of ksh's
    "command numbers" ('!') - a potential source of confusion?

    BTW: POSIX 'fc' speaks also about "reference commands by number".

    Bash's explanation:
    "The command number and the history number are usually different: the
    history number of a command is its position in the history list, which
    may include commands restored from the history file (see HISTORY
    below), while the command number is the position in the sequence of
    commands executed during the current shell session."

    Hmm...

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kees Nuyt@21:1/5 to janis_papanagnou+ng@hotmail.com on Thu Sep 26 00:26:07 2024
    On Wed, 25 Sep 2024 00:41:21 +0200, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    Of course I have a more complex setup that uses an own history file
    per "window"; I use for example a name like ".sh_history_pts_57"
    (using 'HISTFILE').

    I do that per "project"

    To switch projects, I source a bash script which ends like this:


    :
    [... project selection code here ...]
    :
    # r is the return code of some project selection
    # code (some whiptail involved)
    # b is the base directory for all projects
    # c is the project subdirectory
    #
    if [ $r -eq 0 ] && [ -n "$c" ] && [ -d "${b}/${c}" ]
    then
    history -a # save hist of previous project
    history -c # clear hist cache
    cd "${b}/${c}" || exit 9
    ls -lA
    test -d bin && PATH=./bin:$(echo $PATH \
    | sed -e 's@\./bin:@@')
    test -f .fslckout && fossil status
    test -f .fslckout && fossil stash list --verbose
    HISTFILE=${PWD}/.bash_history
    history -r # read any existing hist of this project
    unset b c r
    fi

    --
    Kees Nuyt

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kees Nuyt on Thu Sep 26 14:21:31 2024
    On 26.09.2024 00:26, Kees Nuyt wrote:
    On Wed, 25 Sep 2024 00:41:21 +0200, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    Of course I have a more complex setup that uses an own history file
    per "window"; I use for example a name like ".sh_history_pts_57"
    (using 'HISTFILE').

    I do that per "project"

    My "windows" are actually also dedicated to "projects", where every
    project typically uses 1..3 shell terminals.


    To switch projects, I source a bash script which ends like this:
    [...]
    test -f .fslckout && fossil status
    test -f .fslckout && fossil stash list --verbose
    [...]

    What is 'fossil'?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Weisgerber@21:1/5 to Janis Papanagnou on Thu Sep 26 15:32:48 2024
    On 2024-09-26, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    test -f .fslckout && fossil status
    test -f .fslckout && fossil stash list --verbose

    What is 'fossil'?

    A version control system, pardon, software configuration management
    system:
    https://fossil-scm.org/

    --
    Christian "naddy" Weisgerber naddy@mips.inka.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)