Published on

Interacting with folders and files in bash faster using FASD

Authors

I am a huge fan of the FASD command line tool. What it does is build up and maintain an index of the folders you open and go to based on your movement around the system (using cd) and your interactions with files. So for example you can type z code and FASD will know that it must cd to your code path under ~/path/to/code as it can see from your command line history that when you want to cd to code you likely mean that code folder.

Today I discovered that all FASD file commands (commands that interact with files and not folders) can use the -e editorName flag to pass the given file to the specified command. So I can type sf -e vim .json:

> sf -e vim .json
5       1.62917    /home/abc/stuff/code/someproject4/package.json
4       2.00556    /home/abc/stuff/code/someproject3/package.json
3       2.025      /home/abc/stuff/code/someproject2/package.json
2       2.87794    /home/abc/stuff/code/foobar/package.json
1       4          /home/abc/stuff/code/someproject1/package.json
>

You then type in the number of the file you want and push enter. This then opens the given file in the command specified which in this case is vim. This makes it trivial to work with files across multiple projects without having to keep cd-ing around and having to remember where those files are.

FASD ships with a number of aliases:

alias a='fasd -a'        # any
alias s='fasd -si'       # show / search / select
alias d='fasd -d'        # directory
alias f='fasd -f'        # file
alias sd='fasd -sid'     # interactive directory selection
alias sf='fasd -sif'     # interactive file selection
alias z='fasd_cd -d'     # cd, same functionality as j in autojump
alias zz='fasd_cd -d -i' # cd with interactive selection

You can also easily make your own for example if I want to run a find and then open the given file in vim:

alias vf='sf -e vim'

To use this I would simply type: vf fileIAmLookingFor.blah.