Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Preserve exit code in bash hook #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

statik213
Copy link

Preserve the exit code from the previous command the user ran when
exiting from the bash hook. This allows other commands in
PROMPT_COMMAND to handle the exit code from the original user command.

Preserve the exit code from the previous command the user ran when
exiting from the bash hook. This allows other commands in
PROMPT_COMMAND to handle the exit code from the original user command.
@clvv
Copy link
Owner

clvv commented Nov 20, 2015

Thanks for this pull request. This fixes the problem when fasd is the only thing modifying the prompt command. But if there are more prompt commands then each one has to do such exit code passing. Is there a common agreed upon way to do this in the Bash community / users?

@statik213
Copy link
Author

I'm not sure there is a common way to do this. I did some research and didn't find anything too helpful. Every prompt command should do be doing this to preserve the exit code, there's no other way. I did update my own handler the same way.

@catesandrew
Copy link

I add fasd to the precmd array provided to me by bash-preexec and in fact they do something very similar as you can see from the link. This commit seems more appropriate for a third party bash lib like bash-preexec or if you had a library loading themes etc it would and should have a function for installing to the PROMPT_COMMAND. I know bash-git-prompt provides one, so ... just fyi.

@statik213
Copy link
Author

I roll my own prompt and don't use any bash frameworks right now. There were two commands in my PROMPT_COMMAND (fasd and one of my own), and I needed this fix in both places to properly handle the previous command's return code.

I'm not sure it's reasonable to ask fasd users to install bash-preexec just to work around this issue.

tswicegood added a commit to tswicegood/bash-it that referenced this pull request Mar 25, 2016
There are multiple ways to install fasd, but the initialization
still needs to happen. Currently, fasd is broken in bash in that
it doesn't maintain the exit code properly. This custom init removes
the call to `fasd --init bash-hook` and replaces it with the version
that would be generated once fasd PR Bash-it#72 is merged.

See: clvv/fasd#72
@tswicegood
Copy link

@clvv howdy! I'm one of the maintainers of https://github.com/Bash-it/bash-it/. As noted in the linked PR and commit above, we have to work around this issue in fasd in order to get the correct exit status to work with inside themes and plugins and such. I'd really like to see this merged so we can simplify our plugin.

kshitijagrwl pushed a commit to kshitijagrwl/dotfiles_bash that referenced this pull request Jun 27, 2016
There are multiple ways to install fasd, but the initialization
still needs to happen. Currently, fasd is broken in bash in that
it doesn't maintain the exit code properly. This custom init removes
the call to `fasd --init bash-hook` and replaces it with the version
that would be generated once fasd PR #72 is merged.

See: clvv/fasd#72
CervantesVive pushed a commit to CervantesVive/bash-it that referenced this pull request May 6, 2017
There are multiple ways to install fasd, but the initialization
still needs to happen. Currently, fasd is broken in bash in that
it doesn't maintain the exit code properly. This custom init removes
the call to `fasd --init bash-hook` and replaces it with the version
that would be generated once fasd PR Bash-it#72 is merged.

See: clvv/fasd#72
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants