{"id":7989,"date":"2020-11-16T01:01:00","date_gmt":"2020-11-16T01:01:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/16\/clvv-fasd\/"},"modified":"2022-08-30T15:19:58","modified_gmt":"2022-08-30T15:19:58","slug":"clvv-fasd","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2020\/11\/16\/clvv-fasd\/","title":{"rendered":"clvv\/fasd"},"content":{"rendered":"<p>Fasd (pronounced similar to \u201cfast\u201d) is a command-line productivity booster. Fasd offers quick access to files and directories for POSIX shells. It is inspired by tools like autojump, z and v. Fasd keeps track of files and directories you have accessed, so that you can quickly reference them in the command line.<\/p>\n<p>The name fasd comes from the default suggested aliases <code>f<\/code>(files), <code>a<\/code>(files\/directories), <code>s<\/code>(show\/search\/select), <code>d<\/code>(directories).<\/p>\n<p>Fasd ranks files and directories by \u201cfrecency,\u201d that is, by both \u201cfrequency\u201d and \u201crecency.\u201d The term \u201cfrecency\u201d was first coined by Mozilla and used in Firefox (link).<\/p>\n<h2>Introduction<\/h2>\n<p>If you use your shell to navigate and launch applications, fasd can help you do it more efficiently. With fasd, you can open files regardless of which directory you are in. Just with a few key strings, fasd can find a \u201cfrecent\u201d file or directory and open it with command you specify. Below are some hypothetical situations, where you can type in the command on the left and fasd will \u201cexpand\u201d your command into the right side. Pretty magic, huh?<\/p>\n<pre><code>  v def conf       =&gt;     vim \/some\/awkward\/path\/to\/type\/default.conf\n  j abc            =&gt;     cd \/hell\/of\/a\/awkward\/path\/to\/get\/to\/abcdef\n  m movie          =&gt;     mplayer \/whatever\/whatever\/whatever\/awesome_movie.mp4\n  o eng paper      =&gt;     xdg-open \/you\/dont\/remember\/where\/english_paper.pdf\n  vim `f rc lo`    =&gt;     vim \/etc\/rc.local\n  vim `f rc conf`  =&gt;     vim \/etc\/rc.conf\n<\/code><\/pre>\n<p>Fasd comes with some useful aliases by default:<\/p>\n<pre><code>alias a='fasd -a'        # any\nalias s='fasd -si'       # show \/ search \/ select\nalias d='fasd -d'        # directory\nalias f='fasd -f'        # file\nalias sd='fasd -sid'     # interactive directory selection\nalias sf='fasd -sif'     # interactive file selection\nalias z='fasd_cd -d'     # cd, same functionality as j in autojump\nalias zz='fasd_cd -d -i' # cd with interactive selection\n<\/code><\/pre>\n<p>Fasd will smartly detect when to display a list of files or just the best match. For instance, when you call fasd in a subshell with some search parameters, fasd will only return the best match. This enables you to do:<\/p>\n<pre><code>mv update.html `d www`\ncp `f mov` .\n<\/code><\/pre>\n<h2>Install<\/h2>\n<p>Fasd is available in various package managers. Please check the wiki page for an up-to-date list.<\/p>\n<p>You can also manually obtain a copy of fasd.<\/p>\n<p>Download fasd 1.0.1 from GitHub: zip, tar.gz.<\/p>\n<p>Fasd is a self-contained POSIX shell script that can be either sourced or executed. A Makefile is provided to install <code>fasd<\/code> and <code>fasd.1<\/code> to desired places.<\/p>\n<p>System-wide install:<\/p>\n<pre><code>make install\n<\/code><\/pre>\n<p>Install to $HOME:<\/p>\n<pre><code>PREFIX=$HOME make install\n<\/code><\/pre>\n<p>Or alternatively you can just copy <code>fasd<\/code> to anywhere you like (preferably under some directory in <code>$PATH<\/code>).<\/p>\n<p>To get fasd working in a shell, some initialization code must be run. Put the line below in your shell rc.<\/p>\n<pre><code>eval \"$(fasd --init auto)\"\n<\/code><\/pre>\n<p>This will setup a command hook that executes on every command and advanced tab completion for zsh and bash.<\/p>\n<p>If you want more control over what gets into your shell environment, you can pass customized set of arguments to <code>fasd --init<\/code>.<\/p>\n<pre><code>zsh-hook             # define _fasd_preexec and add it to zsh preexec array\nzsh-ccomp            # zsh command mode completion definitions\nzsh-ccomp-install    # setup command mode completion for zsh\nzsh-wcomp            # zsh word mode completion definitions\nzsh-wcomp-install    # setup word mode completion for zsh\nbash-hook            # add hook code to bash $PROMPT_COMMAND\nbash-ccomp           # bash command mode completion definitions\nbash-ccomp-install   # setup command mode completion for bash\nposix-alias          # define aliases that applies to all posix shells\nposix-hook           # setup $PS1 hook for shells that's posix compatible\ntcsh-alias           # define aliases for tcsh\ntcsh-hook            # setup tcsh precmd alias\n<\/code><\/pre>\n<p>Example for a minimal zsh setup (no tab completion):<\/p>\n<pre><code>eval \"$(fasd --init posix-alias zsh-hook)\"\n<\/code><\/pre>\n<p>Note that this method will slightly increase your shell start-up time, since calling binaries has overhead. You can cache fasd init code if you want minimal overhead. Example code for bash (to be put into .bashrc):<\/p>\n<pre><code>fasd_cache=\"$HOME\/.fasd-init-bash\"\nif [ \"$(command -v fasd)\" -nt \"$fasd_cache\" -o ! -s \"$fasd_cache\" ]; then\n  fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install &gt;| \"$fasd_cache\"\nfi\nsource \"$fasd_cache\"\nunset fasd_cache\n<\/code><\/pre>\n<p>Optionally, if you can also source <code>fasd<\/code> if you want <code>fasd<\/code> to be a shell function instead of an executable.<\/p>\n<p>You can tweak initialization code. For instance, if you want to use \u201cc\u201d instead of \u201cz\u201d to do directory jumping, you can use the alias below:<\/p>\n<pre><code>alias c='fasd_cd -d'\n# `-d` option present for bash completion\n# function fasd_cd is defined in posix-alias\n<\/code><\/pre>\n<p>After you first installed fasd, open some files (with any program) or <code>cd<\/code> around in your shell. Then try some examples below.<\/p>\n<h2>Examples<\/h2>\n<pre><code>f foo           # list frecent files matching foo\na foo bar       # list frecent files and directories matching foo and bar\nf js$           # list frecent files that ends in js\nf -e vim foo    # run vim on the most frecent file matching foo\nmplayer `f bar` # run mplayer on the most frecent file matching bar\nz foo           # cd into the most frecent directory matching foo\nopen `sf pdf`   # interactively select a file matching pdf and launch `open`\n<\/code><\/pre>\n<p>You should add your own aliases to fully utilize the power of fasd. Here are some examples to get you started:<\/p>\n<pre><code>alias v='f -e vim' # quick opening files with vim\nalias m='f -e mplayer' # quick opening files with mplayer\nalias o='a -e xdg-open' # quick opening files with xdg-open\n<\/code><\/pre>\n<p>If you\u2019re using bash, you have to call <code>_fasd_bash_hook_cmd_complete<\/code> to make completion work. For instance:<\/p>\n<pre><code>_fasd_bash_hook_cmd_complete v m j o\n<\/code><\/pre>\n<p>You could select an entry in the list of matching files.<\/p>\n<h2>Matching<\/h2>\n<p>Fasd has three matching modes: default, case-insensitive, and fuzzy.<\/p>\n<p>For a given set of queries (the set of command-line arguments passed to fasd), a path is a match if and only if:<\/p>\n<ol>\n<li>Queries match the path <em>in order<\/em>.<\/li>\n<li>The last query matches the <em>last segment<\/em> of the path.<\/li>\n<\/ol>\n<p>If no match is found, fasd will try the same process ignoring case. If still no match is found, fasd will allow extra characters to be placed between query characters for fuzzy matching.<\/p>\n<p>Tips:<\/p>\n<ul>\n<li>If you want your last query not to match the last segment of the path, append <code>\/<\/code> as the last query.<\/li>\n<li>If you want your last query to match the end of the filename, append <code>$<\/code> to the last query.<\/li>\n<\/ul>\n<h2>How It Works<\/h2>\n<p>When you run fasd init code or source <code>fasd<\/code>, fasd adds a hook which will be executed whenever you execute a command. The hook will scan your commands\u2019 arguments and determine if any of them refer to existing files or directories. If yes, fasd will add them to the database.<\/p>\n<h2>Compatibility<\/h2>\n<p>Fasd\u2019s basic functionalities are POSIX compliant, meaning that you should be able to use fasd in all POSIX compliant shells. Your shell need to support command substitution in <code>$PS1<\/code> in order for fasd to automatically track your commands and files. This feature is not specified by the POSIX standard, but it\u2019s nonetheless present in many POSIX compliant shells. In shells without prompt command or prompt command substitution (csh for instance), you can add entries manually with <code>fasd -A<\/code>. You are very welcomed to contribute shell initialization code for not yet supported shells.<\/p>\n<p>Fasd has been tested on the following shells: bash, zsh, mksh, pdksh, dash, busybox ash, FreeBSD 9 \/bin\/sh and OpenBSD \/bin\/sh.<\/p>\n<h2>Synopsis<\/h2>\n<pre><code>fasd [options] [query ...]\n[f|a|s|d|z] [options] [query ...]\n  options:\n    -s         list paths with scores\n    -l         list paths without scores\n    -i         interactive mode\n    -e    set command to execute on the result file\n    -b   only use  backend\n    -B   add additional backend \n    -a         match files and directories\n    -d         match directories only\n    -f         match files only\n    -r         match by rank only\n    -t         match by recent access only\n    -R         reverse listing order\n    -h         show a brief help message\n    -[0-9]     select the nth entry\n\nfasd [-A|-D] [paths ...]\n    -A    add paths\n    -D    delete paths\n<\/code><\/pre>\n<p>Fasd offers two completion modes, command mode completion and word mode completion. Command mode completion works in bash and zsh. Word mode completion only works in zsh.<\/p>\n<p>Command mode completion is just like completion for any other commands. It is triggered when you hit tab on a <code>fasd<\/code> command or its aliases. Under this mode your queries can be separated by a space. Tip: if you find that the completion result overwrites your queries, type an extra space before you hit tab.<\/p>\n<p>Word mode completion can be triggered on <em>any<\/em> command. Word completion is triggered by any command line argument that starts with <code>,<\/code> (all), <code>f,<\/code> (files), or <code>d,<\/code> (directories), or that ends with <code>,,<\/code> (all), <code>,,f<\/code> (files), or <code>,,d<\/code> (directories). Examples:<\/p>\n<pre><code>$ vim ,rc,lo\n$ vim \/etc\/rc.local\n\n$ mv index.html d,www\n$ mv index.html \/var\/www\/\n<\/code><\/pre>\n<p>There are also three zle widgets: <code>fasd-complete<\/code>, <code>fasd-complete-f<\/code>, <code>fasd-complete-d<\/code>. You can bind them to keybindings you like:<\/p>\n<pre><code>bindkey '^X^A' fasd-complete    # C-x C-a to do fasd-complete (fils and directories)\nbindkey '^X^F' fasd-complete-f  # C-x C-f to do fasd-complete-f (only files)\nbindkey '^X^D' fasd-complete-d  # C-x C-d to do fasd-complete-d (only directories)\n<\/code><\/pre>\n<h2>Backends<\/h2>\n<p>Fasd can take advantage of different sources of recent \/ frequent files. Most desktop environments (such as OS X and Gtk) and some editors (such as Vim) keep a list of accessed files. Fasd can use them as additional backends if the data can be converted into fasd\u2019s native format. Below is a list of available backends.<\/p>\n<pre><code>`spotlight`\nOSX spotlight, provides entries that are changed today or opened within the\npast month\n\n`recently-used`\nGTK's recently-used file (Usually available on Linux)\n\n`current`\nProvides everything in $PWD (whereever you are executing `fasd`)\n\n`viminfo`\nVim's editing history, useful if you want to define an alias just for editing\nthings in vim\n<\/code><\/pre>\n<p>You can define your own backend by declaring a function by that name in your <code>.fasdrc<\/code>. You can set default backend with <code>_FASD_BACKENDS<\/code> variable in our <code>.fasdrc<\/code>.<\/p>\n<p>Fasd can mimic v&#8217;s behavior by this alias:<\/p>\n<pre><code>alias v='f -t -e vim -b viminfo'\n<\/code><\/pre>\n<h2>Tweaks<\/h2>\n<p>Some shell variables that you can set before sourcing <code>fasd<\/code>. You can set them in <code>$HOME\/.fasdrc<\/code><\/p>\n<pre><code>$_FASD_DATA\nPath to the fasd data file, default \"$HOME\/.fasd\".\n\n$_FASD_BLACKLIST\nList of blacklisted strings. Commands matching them will not be processed.\nDefault is \"--help\".\n\n$_FASD_SHIFT\nList of all commands that needs to be shifted, defaults to \"sudo busybox\".\n\n$_FASD_IGNORE\nList of all commands that will be ignored, defaults to \"fasd ls echo\".\n\n$_FASD_TRACK_PWD\nFasd defaults to track your \"$PWD\". Set this to 0 to disable this behavior.\n\n$_FASD_AWK\nWhich awk to use. Fasd can detect and use a compatible awk.\n\n$_FASD_SINK\nFile to log all STDERR to, defaults to \"\/dev\/null\".\n\n$_FASD_MAX\nMax total score \/ weight, defaults to 2000.\n\n$_FASD_SHELL\nWhich shell to execute. Some shells will run faster than others. fasd\nruns faster with dash and ksh variants.\n\n$_FASD_BACKENDS\nDefault backends.\n\n$_FASD_RO\nIf set to any non-empty string, fasd will not add or delete entries from\ndatabase. You can set and export this variable from command line.\n\n$_FASD_FUZZY\nLevel of \"fuzziness\" when doing fuzzy matching. More precisely, the number of\ncharacters that can be skipped to generate a match. Set to empty or 0 to\ndisable fuzzy matching. Default value is 2.\n\n$_FASD_VIMINFO\nPath to .viminfo file for viminfo backend, defaults to \"$HOME\/.viminfo\"\n\n$_FASD_RECENTLY_USED_XBEL\nPath to XDG recently-used.xbel file for recently-used backend, defaults to\n\"$HOME\/.local\/share\/recently-used.xbel\"\n\n<\/code><\/pre>\n<h2>Debugging<\/h2>\n<p>If fasd does not work as expected, please file a bug report describing the unexpected behavior along with your OS version, shell version, awk version, sed version, and a log file.<\/p>\n<p>You can set <code>_FASD_SINK<\/code> in your <code>.fasdrc<\/code> to obtain a log.<\/p>\n<pre><code>_FASD_SINK=\"$HOME\/.fasd.log\"\n<\/code><\/pre>\n<h2>COPYING<\/h2>\n<p>Fasd is originally written based on code from z by rupa deadwyler under the WTFPL license. Most if not all of the code has been rewritten. Fasd is licensed under the \u201cMIT\/X11\u201d license.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fasd (pronounced similar to \u201cfast\u201d) is a command-line productivity booster. Fasd offers quick access to files and directories for POSIX shells. It is inspired by tools like autojump, z and v. Fasd keeps track of files and directories you have accessed, so that you can quickly reference them in the command line. The name fasd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7989","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7989"}],"version-history":[{"count":2,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7989\/revisions"}],"predecessor-version":[{"id":8728,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7989\/revisions\/8728"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}