hishtory icon indicating copy to clipboard operation
hishtory copied to clipboard

hishtory changes exit code

Open GRbit opened this issue 1 year ago • 3 comments

Hi @ddworken!

I didn't notice it when I started to use your wonderful tool, but suddenly I realized that my command line prompt now always shows me 0 exit code.

I have a prompt_comm() function that reads last command exit code and shows it, but now it looks like the last code is returned by hishtory command, so it's always 0.

I'm not so good when it comes to bash scripts. Do you know if it would be easy to change hishtory bash script to make exit code of the command that was run available for the prompt_comm() funtiofunction?

Here is how my command lie behaves without hishtory:

[0] $ ^C
[130] $ echi
bash: echi: command not found
[127] $

As you can see, the exit code shown right away. Now with .hishtory/config.sh file:

[0] $ ^C
[0] $ echo $?
130
[0] $ echi
bash: echi: command not found
[0] $ echo $?
127

I thought I can change my prompt command, but it doesn't matter when I save exit code, in the beginning of the function, or at the end, it's always 0, unfortunately.

Thank you in advance for your time.

GRbit avatar Sep 12 '24 07:09 GRbit

Hmm, interesting. Can you share exactly how you have your prompt command configured? And what version of bash you're using? I tried to reproduce this using this example but it seems to be working fine for me.

ddworken avatar Sep 16 '24 00:09 ddworken

I tried to minimize example for reproducing the issue

function prompt_comm()
{ 
    local EXIT=${?};
    PS1="\u\h:\w  \t\n[${EXIT}] \$";
}
PROMPT_COMMAND="prompt_comm"

HISTCONTROL=ignoredups:ignorespace:erasedups
shopt -s histappend
shopt -s checkwinsize
shopt -s globstar

export HISHTORY_SERVER=https://private.server
HISHTORY_SERVER=https://private.server

# Hishtory Config:
export PATH="$PATH:/home/grbit/.hishtory"
source $HOME/.hishtory/config.sh

$HOME/.hishtory/config.sh is a copy of https://raw.githubusercontent.com/ddworken/hishtory/1c33189f38cca8e31e1e90923f39c7de4c06b4da/client/lib/config.sh

GRbit avatar Sep 16 '24 07:09 GRbit

Thank you for the time spent on this, I think I found something:

export HISHTORY_SERVER=https://private.server
HISHTORY_SERVER=https://private.server
export PATH="$PATH:/home/grbit/.hishtory"
source $HOME/.hishtory/config.sh

function prompt_comm()
{ 
    local EXIT=${?};
    PS1="\u\h:\w  \t\n[${EXIT}] \$";
}
PROMPT_COMMAND="prompt_comm"

HISTCONTROL=ignoredups:ignorespace:erasedups
shopt -s histappend
shopt -s checkwinsize
shopt -s globstar

Just moving hishtory source file before the moment I set PROMPT_COMMAND variable helps. I don't see this as an issue anymore, still I'm a bit curious to know the exact reason. So, unless you want to dig into bash a bit, the issue could be closed.

UPDATE: Unfortunately, moving the source $HOME/.hishtory/config.sh before I set PROMPT_COMMAND was not a solution since hishtory stopped save data :sweat_smile: I didn't notice that .hishtory/config.sh set PROMPT_COMMAND by itself.

GRbit avatar Sep 16 '24 08:09 GRbit

Ok, thank you for the detailed description! I now see what is happening here. 3a0c08c should fix this, I'll get it into the next release once it passes tests on actions.

ddworken avatar Oct 03 '24 13:10 ddworken