GithubHelp home page GithubHelp logo

PROMPT_COMMAND clobbers $? about jump HOT 4 CLOSED

gsamokovarov avatar gsamokovarov commented on June 17, 2024
PROMPT_COMMAND clobbers $?

from jump.

Comments (4)

gsamokovarov avatar gsamokovarov commented on June 17, 2024

Can you give a bit more context? I'm still being able to access $? for the return value in bash as usual.

from jump.

greygore avatar greygore commented on June 17, 2024

Yes, that confused me too. I assume PROMPT_COMMAND is executed in a subshell which preserves the value of $? outside of that. The problem comes inside that PROMPT_COMMAND subshell. If I want to alter my bash prompt in response to the success or failure of the last command, I need to do is store that return value to prevent clobbering it myself:

function my_prompt_func() {
    local code=$?
    local dir=$(pwd)

    if [ $? -eq 0 ]; then
        PS1="$dir ✔ $"
    else
        PS1="$dir ✕ $"
    fi
}

PROMPT_COMMAND=my_prompt_func

(Or a real life example)

Of course, when I add eval "$(jump shell bash) it changes that to PROMPT_COMMAND="__jump_prompt_command;$PROMPT_COMMAND", which means that $? inside of my_prompt_func is the exit code of __jump_prompt_command and not the command last executed by the user.

Since it looks like you're just hooking into that to adjust the score, it seems like you could reorder those PROMPT_COMMANDs to put __jump_prompt_command last, which is what I've done in my workaround. Alternately, you could return the original exit code from _jump_prompt_command, or preserve the last exit code in an environmental variable, but those both seem unnecessary

from jump.

gsamokovarov avatar gsamokovarov commented on June 17, 2024

I get you now! Will reorder it for the next version. Haven't thought that someone may require the return value somewhere in PROMPT_COMMAND.

Thanks for the detailed report!

from jump.

gsamokovarov avatar gsamokovarov commented on June 17, 2024

Hey @greygore, can you try the changes in f124fa4 and see whether they work for you? A lot of tools inject themselves into the beginning of PROMPT_COMMAND and if I inject myself last I have to be weary of ;;.

from jump.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.