![]() We've made the switch to a better shell (in our opinion, I assume) - Why not take advantage of its improved features? ![]() One of the main factors that drove me from Zsh to fish was the increasingly slow startup of my Zsh config as I added features, functions, etc. How much of a difference this will make will depend on a lot of factors, but personally, I keep a lookout for simple ways to optimize my configuration. The first time you call a function with functionname, then and only then will fish lazy-load the function from ~/.config/fish/functions/. No part of the function other than the name (for lookup purposes) is loaded into memory until it is used. This can speed up launch times significantly, especially if you have many aliases and/or complex functions, or perhaps are running on a slower system/VM/shared CPU host. Note that this will be $XDG_CONFIG_HOME/fish/functions if that variable is defined.įunctions in this directory are lazy-loaded.įish does not load any part of your alias/function when it starts. Īs the original question mentioned, it is possible to define your functions in ~/.config/fish/functions/, although it is a directory rather than a file. You need lazy-loading (ok, well maybe not need), but anyway. One of the (many) features that sets fish apart from bash and zsh is lazy-loading. Defining functions/aliases in your startup config is the "bash/zsh way". That may have been correct in 2010, but even then I think fish supported lazy-loading of functions/aliases, which is a better option. With that in mind, the currently accepted answer from 2010 has a few issues nowadays.įirst, you really shouldn't define your aliases in your config. That ability was added shortly after that answer was written. However, when you define an alias this way, it is defined only in memory. Much more detail on why the above is preferred over the other answersįirst, it is important to understand that, as Glenn Jackman (a former fish shell contributor) mentioned in this answer, the alias command in fish is just syntactic sugar for creating a function. Provide the additional information on editing and removing aliases which are defined this way.Go into more detail on why the other answers are suboptimal with current fish releases.Go into more detail on why ('alias -s`) is the best solution.While answer is the best solution for current fish releases, I'm writing this as a separate answer to: While it could, in theory, be edited, the necessary changes, IMHO, would create a different answer, which we aren't supposed to do. However, the currently accepted answer is a bit outdated. Regardless, since it predates mine, I wouldn't mind at all if it was the accepted answer. Note that answer does include the alias -s command, but doesn't go into much detail. part, then funced -s unalias again to add the rm. You'll need to first alias -s unalias the functions -e. Ironically, you may even want to alias this into unalias. Note that since 3.4.0 was only released a few weeks ago, I'll include the commands that work in previous versions as well: functions -e # or -erase To remove an alias defined this way (since fish 3.4.0): functions -e # or -erase To edit an alias created this way: funced -s # or -save To list existing aliases which have been defined this way (since fish 2.5b1): alias Important: Simply do this one time per alias at the command-line. ![]() The quickest and best way to do what is requested in this question is: alias -s "command(s)" # Or -save Short, updated, current answer for all releases since 3.0b1: The following code will create rmi, which runs rm with additional arguments on every invocation.I know there are 11 answers already at this point, and they all work, but most are also suboptimal in 2022 (and for the past few years). Saves the function created by the alias into your fish configuration directory using funcsave. The following options are available: -h or -helpĭisplays help about using this command. Note that spaces need to be escaped in the call to alias just like at the command line, even inside quoted parts. You cannot create an alias to a function with the same name. alias automatically appends $argv, so that all parameters used with the alias are passed to the actual command. They must be erased using functions -e.ĭEFINITION is the actual command to execute. You can list alias-created functions by running alias without arguments. If you want to ease your interactive use, to save typing, consider using an abbreviation instead.įish marks functions that have been created by alias by including the command used to create them in the function description. For other uses, it is recommended to define a function. It has similar syntax to POSIX shell alias. Alias alias NAME DEFINITION alias NAME=DEFINITION Description ¶Īlias is a simple wrapper for the function builtin, which creates a function wrapping a command.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |