Skip to content
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

Add env var $CMD #1542

Closed
wants to merge 11 commits into from
Closed

Add env var $CMD #1542

wants to merge 11 commits into from

Conversation

@justmao945
Copy link
Contributor

@justmao945 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 2 commits Jul 11, 2014
$_ 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
Copy link
Member

@zanchey zanchey commented Jul 14, 2014

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

zanchey and others added 3 commits Jul 14, 2014
The `read` docs incorrectly asserted that -g was the default for
variables. In actuality it behaves the same way that `set` does.
@justmao945
Copy link
Contributor Author

@justmao945 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 added 2 commits Jul 14, 2014
This reverts commit e3b102f.
@justmao945 justmao945 closed this Jul 14, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.