Add env var $CMD #1542

Closed
wants to merge 11 commits into
from

Conversation

Projects
None yet
5 participants
@justmao945
Contributor

justmao945 commented Jul 11, 2014

$_ is nice to get the program name.
But there's no way to get the entire command line string(maybe there's a way I don't know, please tell me if I am wrong). So I add a readonly env var $CMD, and it is very useful in function fish_title.

function fish_title
  if [ $_ = 'fish' ]
    echo (prompt_pwd)
  else if [ $_ = 'ssh' ]
    echo $CMD
  else
    echo $_
  end
end

I'm not sure if CMD is a good name or not, because $_ is a really very cool name.

Thanks.

justmao945 and others added some commits Jul 11, 2014

Add env var $CMD
$_ is nice to get the program name.
But there's no way to get the entire command line string.
$CMD is very useful in function fish_title.
@zanchey

This comment has been minimized.

Show comment
Hide comment
@zanchey

zanchey Jul 14, 2014

Member

See also #334, which suggests populating $argv for fish_title functions.

Member

zanchey commented Jul 14, 2014

See also #334, which suggests populating $argv for fish_title functions.

zanchey and others added some commits Jul 14, 2014

Fix documentation on variable scopes for `read`
The `read` docs incorrectly asserted that -g was the default for
variables. In actuality it behaves the same way that `set` does.
@justmao945

This comment has been minimized.

Show comment
Hide comment
@justmao945

justmao945 Jul 14, 2014

Contributor

@zanchey
Do you mean

  1. set $argv to arguments received by $_ ? This is a more elegant way, but I find it is hard(or may exist some functions I didn't find, please point out if I am wrong) to retrieve arguments array before we parse the expression. The $argv can be messed when the expression(aka command string) is something like echo hello; and vim some.txt. In this case the $_ is set to echo and never set to vim, so the $argv should be set to hello ? But I don't think this is easy to do in our current implementation of reader_write_title.
  2. or set $argv[1] to the command string. This should be a reasonable way. We don't need to parse anything. Instead of create a new env var $CMD(less is better), I think we can call fish_title with the whole command string(inspired by #334 ). Please see the new pull request #1554 for this implementation.
function fish_title
  if [ $_ = 'fish' ]
    echo (prompt_pwd)
  else
    # instead of $CMD, we use the local var $argv
    echo $argv
  end
end
Contributor

justmao945 commented Jul 14, 2014

@zanchey
Do you mean

  1. set $argv to arguments received by $_ ? This is a more elegant way, but I find it is hard(or may exist some functions I didn't find, please point out if I am wrong) to retrieve arguments array before we parse the expression. The $argv can be messed when the expression(aka command string) is something like echo hello; and vim some.txt. In this case the $_ is set to echo and never set to vim, so the $argv should be set to hello ? But I don't think this is easy to do in our current implementation of reader_write_title.
  2. or set $argv[1] to the command string. This should be a reasonable way. We don't need to parse anything. Instead of create a new env var $CMD(less is better), I think we can call fish_title with the whole command string(inspired by #334 ). Please see the new pull request #1554 for this implementation.
function fish_title
  if [ $_ = 'fish' ]
    echo (prompt_pwd)
  else
    # instead of $CMD, we use the local var $argv
    echo $argv
  end
end

@justmao945 justmao945 closed this Jul 14, 2014

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