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

command substitutions should modify $status #547

Closed
ridiculousfish opened this Issue Jan 27, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@ridiculousfish
Member

ridiculousfish commented Jan 27, 2013

This is a proposal to make command substitutions modify $status. Currently, the exit status of command substitutions is just discarded.

This will usually have no effect, because command substitutions must be passed to another command, which will overwrite status:

echo (false)

$status will be 0, because it reflects the result of echo, not false.

However, some commands do not modify status, such as switch. This allows us to determine whether the command succeeded:

switch (uname)
    case Linux
          echo "You're on Linux"
    case Darwin
           echo "You're OS X"
    case '*'
        if test $status = 0
             echo "You are on another system"
        else
             echo "uname failed"
        end
  end

Another change is that $status will reflect the value of a command substitution within a prior argument:

echo (false) $status (true) $status

This will now output "1 0", which matches the behavior of bash and zsh.

The most significant benefit of this is that it allows a "transparent set", as in #214:

if set path (which python)
    echo "Python is at $path"
else
    echo "Python is not installed"
end

Without this change, it is far more difficult to determine whether which failed.

This only affects command substitutions run by user code. Internal uses, such as fish_prompt, will not change the exit status.

@maxfl

This comment has been minimized.

Show comment
Hide comment
@maxfl

maxfl Jan 28, 2013

Contributor

Looks cool.
The only limitation I see is that it will be only helpful for the internal commands.
All the external commands which are used with command substitutions will override the status. But this is a minor issue. The benefits of this feature are going to cover most of the needs.

Contributor

maxfl commented Jan 28, 2013

Looks cool.
The only limitation I see is that it will be only helpful for the internal commands.
All the external commands which are used with command substitutions will override the status. But this is a minor issue. The benefits of this feature are going to cover most of the needs.

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Jan 31, 2013

Member

Since there was no objections (or even much interest) I went ahead with this.
ad8d68d

Member

ridiculousfish commented Jan 31, 2013

Since there was no objections (or even much interest) I went ahead with this.
ad8d68d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment