The fish shell

The fish shell is an interactive shell for Linux with syntax highlighting and auto completion.

Changing to fish.

You could just put this in the bottom of your .bashrc and that way your default bash setup runs and then throws you into fish.

exec fish 

Or to make fish your default shell add the fish shell /usr/local/bin/fish to /etc/shells

echo /usr/local/bin/fish | sudo tee -a /etc/shells 

Change your default shell to fish

chsh -s /usr/local/bin/fish 

Defining functions

Create a file in ~/.config/fish/functions named . In this file create a function of the same name as the file. You will then be able to call this function from the prompt by typing its name.

Change default prompt

Create the file .config/fish/functions/ and create the fish_prompt function in it.

The minimal one I like is:

function fish_prompt
    set_color $fish_color_cwd
    echo -n (pwd)
    set_color normal
    echo -n -e '\n$ '

Change the default greeting

create the file ./config/fish/functions/ and create the fish_greeting function in it. For a blank message just use an empty function.

function fish_greeting

Programming in fish!

Its all about writing scripts isn't it? Writing fish scripts is pretty easy, here are a few snippets I have gleaned while doing so.

Arrays start at 1

Yes the first index of an array is 1. You can get the last index of an array with -1. Indexing at -2 will give you the item before the last one, and so on.

You can index ranges of an array like this:

array[1]		# first
array[-1]		# last
array[5..-1]	# from the 5th element to the last
array[-1..1]	# reverse

Read file line by line

while read -la line 
	echo $line
end < file_name.txt

Switch checking string matches

You can use the wild card in switches on a string!

switch $var
	case "abc*" 	# var begins with abc
	case "*abc" 	# var ends with abc
	case "*abc*"	# var has abc in the middle

Loop over a string

set -l chars (string split '' $var )
for ch in $chars
echo $ch

Grow a list of values.

# Set the list to itself + the new value
# If list does no exist it is created!
set -l list $list "$value_to_add"