fasd icon indicating copy to clipboard operation
fasd copied to clipboard

Preserve exit code in bash hook

Open statik213 opened this issue 10 years ago • 5 comments

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.

statik213 avatar Nov 13 '15 18:11 statik213

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?

clvv avatar Nov 20 '15 04:11 clvv

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.

statik213 avatar Nov 20 '15 05:11 statik213

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.

catesandrew avatar Mar 19 '16 04:03 catesandrew

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.

statik213 avatar Mar 22 '16 18:03 statik213

@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.

tswicegood avatar Mar 25 '16 22:03 tswicegood