Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fish shell: variable with last argument

Tags:

fish

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.

like image 876
3voC Avatar asked Dec 14 '22 10:12

3voC


2 Answers

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
like image 121
ridiculous_fish Avatar answered Feb 07 '23 10:02

ridiculous_fish


As suggested in another thread Alt+. cycles arguments from previous commands at cursor input:

mkdir -p ~/fish/previous/arg/demo
cd 
#  ^ hit Alt + .
cd ~/fish/previous/arg/demo
like image 30
Nikolay Hidalgo Diaz Avatar answered Feb 07 '23 10:02

Nikolay Hidalgo Diaz