fish

Fish shell: variable with last argument


What is a fish shell equivalent of mkdir -p foo/bar/baz/quux && cd $_?

I know about $history[1], but here I need only last argument of the previous command.


Solution

  • fish doesn't support a last argument variable unfortunately.

    An efficient interactive way to do this is to make the directory:

    > mkdir -p foo/bar/baz/quux
    

    Then type cd and the first character of the path.

    > cd f
    

    At this point fish will probably autosuggest the whole path. If not you can press alt-up to do a history token search and it will certainly find it.

    A scripting way to do it would be:

    set path foo/bar/baz/quux && mkdir -p $path && cd $path