Fish Shell Idioms and Tips

In the past I talked about my switch to Fish. If you often find yourself using a Linux terminal but you’ve never seen Fish then I recommend you take a peek. Most people, myself included, start off using GNU Bash or some variant thereof. Having used Fish for nearly two years now, I want to talk about some of its useful idioms. Some of them replicate features from Bash, and some are unique to Fish. But hopefully you will find them useful.

Keyboard Shortcuts

Want to clear the entire line you’re typing? You can use the classic Ctrl-A Ctrl-K combination. Or you can simply press Ctrl-C (think ‘C’ for ‘clear’).

Tired of typing ls? I know it’s only two characters. But if you want to see the contents of a directory in Fish you need only press Alt-L (think ‘L’ for ls). This will list the contents of the current directory, unless the cursor is over the name of another directory, in which case Alt-L will show you its contents instead.

Are you always adding | less to the end of commands so you can page through the output? Pressing Alt-P in Fish tacks that on for you (think ‘P’ for ‘pager’).

Want to browse the history for the word under the cursor, even if the word is incomplete? Alt-Up is your friend. You can use that to cycle through things such as previous command arguments.

Want to know a little bit about the command underneath the cursor? Press Alt-W to see a brief description (think ‘W’ as in ‘what’). For example, if my cursor is over luac and I press Alt-W then I get this output:

luac (1)        - Lua compiler

Sequence of Commands

Here is something I often typed into Bash:

$ ./configure && make && make install

Fish does not use the && syntax. Instead it looks like this:

$ ./configure; and make; and make install

You can use or if you want to run a command in the event something fails. For example:

$ make; and make install; or make clean

That will run make and then make install, but if that fails it will run make clean.

Searching History

Want to see every command in your history that contains make?

$ history --search --contains make

Hint: Alt-P is useful here, to page through the output.

MIME Types and Default Actions

The mimedb command queries the MIME information on your computer to provide you with information about a given file. By default it shows the MIME type. For example:

$ mimedb foo.lua
text/x-lua

If you use the open command on a file then Fish will execute the default action for it. For example, if I entered open foo.lua then Fish would open that source file in a text editor. You can see the default action for any file by using mimedb -a, e.g.

$ mimedb -a foo.lua
gedit %U
Advertisements

Add Your Thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s