On Jul 8, 2012, at 8:59 AM, Dario Bertini wrote:

> On 1 July 2012 23:14, ridiculous_fish <corydo...@ridiculousfish.com> wrote:
>> I wasn't able to reproduce this. If you share your fish_prompt function, I 
>> can dig into it a bit more.
>> 
> 
> this is my current function:
> 
> http://dpaste.com/768437/
> 
> as I said: this works, thanks to the suggestion of Tom Most... but if
> you remove the 3rd line, it doesn't work...
> 
> that's fine, I guess... but it should be documented in the help
> 

Thank you Dario, this is valuable feedback. Any sort of behavior that users 
find surprising or unexpected is important to know, and if you would like to 
submit a patch to the documentation, we'll be glad to merge it (provided it's 
correct of course!)

To clarify things, $status is treated like a global variable, and it is not 
rebound within functions.  Changes to $status get propagated out of functions 
like other global variables.

In the "dummy3" example at http://dpaste.com/hold/768717/, the  first call to 
echo within the function reports failure, and the subsequent call outside the 
function reports success; however this is because the first echo statement 
overwrite $status with its own success. If you remove the echo statement within 
the dummy3 function, you should see that $status is propagated outside, e.g.:

    function foo ; false ; end
    foo 
    echo $status

There is an important exception: subshells. In general subshells behave like 
functions, i.e. if you ran this:

    set -l foo outer
    echo (set foo inner)
    echo $foo

You will see that the subshell changed the variable to 'inner'. However this is 
NOT true for $status.  For example:

    echo (false) $status (false)

The failures returned by 'false' cannot be seen by the echo statements. The 
current status is saved before the subshells, and restored after they're run. 
(However, $status does get propagated IN to subshells). This is different than 
bash, and has the potential to be confusing. FWIW, it is documented at 
http://ridiculousfish.com/shell/user_doc/html/#expand-command-substitution .

fish_prompt is executed like a subshell, so it inherits the current $status, 
and can modify it. The status is restored after the subshell is run, so the 
prompt's status doesn't "leak" out of the prompt function.

Hope that clarifies things!
_fish


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to