Create custom functions for Fish


03 Jan 2015 linux

Fish has become my favorite shell for the last several months. Most lovely features of it are - auto-complete, auto- capitalization and colorful text. I use fish shell as my default shell with Konsole on my KDE 4.10 desktop.

Creating functions and aliases for bash was easy (adding them to .bashrc or .bash_profile). But fish has a bit different interpretor. It stores functions as a copy of mostly used and common commands to provide arguments suggestion. Default fish functions are stored at /usr/share/fish/functions.

Well, I don’t want to interfere with their read-only territory. Instead I would create custom functions in my home folder. Configuration path of fish in my home is /home/me/.config/fish/functions.

I wanted to use a function that will execute aria2c with my favorite arguments (-x 8 -c link). I also wanted to shorten the name to a 2/3 digit alias. To make it done do the following -

function dl --description "Parallel and resumable download with aria2c"
    aria2c -c -x 4 $argv[1]
end
dl http://google.com
you@yourpc ~> dl http://google.com
[#1 SIZE:0B/0B CN:1 SPD:0Bs]                                                                 
2013-03-19 04:40:31.054353 NOTICE - Download complete: /home/you/index.html

Download Results:
gid|stat|avg speed  |path/URI
===+====+===========+===========================================================
    1|  OK|   7.3KiB/s|/home/you/index.html

Status Legend:
    (OK):download completed.

Now go away and create more functions!