Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hishtory changes exit code #247

Open
GRbit opened this issue Sep 12, 2024 · 3 comments
Open

hishtory changes exit code #247

GRbit opened this issue Sep 12, 2024 · 3 comments

Comments

@GRbit
Copy link
Contributor

GRbit commented Sep 12, 2024

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.

@ddworken
Copy link
Owner

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.

@GRbit
Copy link
Contributor Author

GRbit commented Sep 16, 2024

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
Copy link
Contributor Author

GRbit commented Sep 16, 2024

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 😅
I didn't notice that .hishtory/config.sh set PROMPT_COMMAND by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants