Define an alias in fish shell
Just use alias
. Here's a basic example:
# Define alias in shell
alias rmi "rm -i"
# Define alias in config file ( `~/.config/fish/config.fish` )
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.
How to create a alias in fish shell
If you need to make alias of ls
, then the above answers are OK.
However, fish already has a command for ls -lah
, which is la
.
Fish shell list with +30 aliases
fish has the same alias
syntax as bash. It just converts the aliases to functions for you. All you need to do is funcsave
them to make them "permanent".
Perhaps this will work for you:
awk -F '[ =]' '$1 == "alias" {print; print "funcsave", $2}' ~/.bashrc | source -
Storing fish shell aliases in another file
There are a few things fish offers here:
- Files in ~/.config/fish/functions named after a function (plus a ".fish" ending) will be autoloaded once that function is called
- Files in ~/.config/fish/conf.d/ (with a ".fish" ending) will be sourced before config.fish
So you can either put your functions/aliases in a function file each, or put them in files in conf.d in whatever grouping you want.
Also you can put your fish_prompt in its own file - ~/.config/fish/functions/fish_prompt.fish
(also "alias" is simply a cheesy helper function to make functions - the core shell has no concept of aliases)
Alias with spaces and arguments in Fish 3
Short answer: It's a bug in the alias function, tho your escaping is inconsistent.
"'/mnt/c/Program Files\ (x86)/Microsoft\ Visual\ Studio/2019/Enterprise/Common7/IDE/devenv.exe' /Edit"
Easy workaround is to fully escape it:
alias d "'/mnt/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2019/Enterprise/Common7/IDE/devenv.exe' /Edit"
Or, as alias is just a (hacky) function that writes functions, skip the middle man and just write a function:
function d
"/mnt/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/devenv.exe" /Edit $argv
end
Define that interactively and use funcsave d
, or write it manually to config.fish or a file called ~/.config/fish/functions/d.fish.
Alias with whitespace in fish shell
This is currently not possible with fish's alias
wrapper function.
However, what that ends up doing anyway is defining a function, so you could just do that.
function "hello there"
echo hello there
end
Execute with "hello there"
or hello\ there
.
Getting an error when defining an alias in the fish shell config file
The first thing to note is that the fish alias
command is not the same thing as the bash alias
command. In fish alias something
is just shorthand for
function something
something $argv
end
In this case I recommend making it an abbreviation: abbr em 'emacsclient -n -c $PWD&'
. Alternatively define it explicitly using the function
syntax.
Defining an Alias to Image Magick in Fish Shell
fish
does not have aliases; you need to define a function instead.
function trim
convert -trim $argv[1] $argv[1]
end
Running fish -c help
(or simply help
if you are already in a fish
session)
will open the fish
documentation in a web browser, where you can find the documentation for the function
command used to define shell functions.
fishshell alias without replacing command
What you're describing is abbreviations, not aliases. Abbreviations are commands that expand as you type them.
Running a command like you described:
alias aa="abc -d -e -f"
will indeed set an alias that will not expand in-line.
Related Topics
How Does Ngrok Work Behind a Firewall
Matlab Execute Script from Linux Command Line
List of Possible Internal Socket Statuses from /Proc
Genymotion Throws Libssl_Conf.So: Cannot Open Shared Object File: No Such File or Directory
How to Remove All Lines from a Text File Starting at First Empty Line
Track the Time a Command Takes in Unix/Linux
How to Remove X Bytes from the End of a Large File Without Reading the Whole File
Is Kernel Space Mapped into User Space on Linux X86
How to Capture Raw Hid Input on Linux
What's the Difference Between "Env" and "Set" (On MAC Os X or Linux)
Is There a Good Way to Detect a Stale Nfs Mount
Recursively Find All Files Newer Than a Given Time
Difference Between Gnuwin32 and Cygwin
After Changing /Etc/Profile, What Do I Have to Do to Reset My Shell