Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define an alias in fish shell

Tags:

linux

shell

fish

People also ask

Where is alias defined?

Definition of alias : otherwise called : otherwise known as —used to indicate an additional name that a person (such as a criminal) sometimes uses John Smith alias Richard Jones was identified as the suspect.

What is alias function?

Bash Alias allows to aggregate multiple functions into a single command and also it avoids repetitive or large commands into a simple shortcut command. BASH Alias is a map of shortcut command with the sets of commands which are stored in a file called either . bash_profile or . bashrc with a specific syntax.

How do you put a path in fish shell?

It does this by adding the components either to $fish_user_paths or directly to $PATH (if the --path switch is given). It is (by default) safe to use fish_add_path in config. fish, or it can be used once, interactively, and the paths will stay in future because of universal variables.


Just use alias. Here's a basic example:

# Define alias in shell
alias rmi "rm -i"

# Define alias in config file
alias rmi="rm -i"

# This is equivalent to entering the following function:
function rmi
    rm -i $argv
end

# Then, to save it across terminal sessions:
funcsave rmi

This last command creates the file ~/.config/fish/functions/rmi.fish.

Interested people might like to find out more about fish aliases in the official manual.


This is how I define a new function foo, run it, and save it persistently.

sthorne@pearl~> function foo
                    echo 'foo was here'
                end
sthorne@pearl~> foo
foo was here
sthorne@pearl~> funcsave foo

For posterity, fish aliases are just functions:

$ alias foo="echo bar"
$ type foo
foo is a function with definition
function foo
    echo bar $argv; 
end

To remove it

$ unalias foo
/usr/bin/unalias: line 2: unalias: foo: not found
$ functions -e foo
$ type foo
type: Could not find “foo”

fish starts by executing commands in ~/.config/fish/config.fish. You can create it if it does not exist:

vim ~/.config/fish/config.fish

and save it with :wq

step1. make configuration file (like .bashrc)

config.fish

step2. just write your alias like this;

alias rm="rm -i"


If you add an abbr instead of an alias you'll get better auto-complete. In fish abbr more closely matches the behavior of a bash alias.

abbr -a gco git checkout

Will -add a new abbreviation gco that expands to git checkout.

Here's a video demo of the resulting auto-complete features


  1. if there is not config.fish in ~/.config/fish/, make it.
  2. there you can write your function .function name; command; end