<commit_before># Fasd

Fasd is a tool for quick access to files for POSIX shells. It is inspired by
tools like `autojump`(https://github.com/joelthelion/autojump),
`z`(http://github.com/rupa/z) and `v`(https://github.com/rupa/v). Fasd keeps
track of files you have accessed, so that you can quickly reference them in the
command line.

The name fasd comes from the default suggested aliases `f`(files),
`a`(files/directories), `s`(show/search/select), `d`(directories).

Fasd ranks files and directories by "frecency," that is, by both "frequency" and
"recency." The term "frecency" was first coined by Mozilla and used in Firefox
([link](https://developer.mozilla.org/en/The_Places_frecency_algorithm)).

Fasd uses [Bayesian Inference](https://en.wikipedia.org/wiki/Bayesian_inference)
and [Bayesian Ranking](https://github.com/clvv/fasd/wiki/Bayesian-Ranking) to rank
files and directories for a set of given matching patterns. "Frecency" is used
as the prior probability distribution, and a simple algorithm is used to
calculate the likelihood of the given set of patterns.

# A Note for Early Adopters

Fasd was originally named `f`. `f` was renamed to fasd for various reasons. And
the latest release contains many improvements compared to old master branch of
`f`, most importantly fasd acquired the ability to be run as an executable
(instead of as a shell function, which is comparably slower). Previous f users
please update all of your f-related configurations accordingly. And don't
forget to rename your database file:

```sh
mv "$HOME/.f" "$HOME/.fasd"
```

# Introduction

If you're like me, you use your shell to navigate and launch applications. Fasd
helps you do that 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 "frecent" 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 "expand" your command into the right side. Pretty magic, huh?

```
  v def conf       =>     vim /some/awkward/path/to/type/default.conf
  j abc            =>     cd /hell/of/a/awkward/path/to/get/to/abcdef
  m movie          =>     mplayer /whatever/whatever/whatever/awesome_movie.mp4
  o eng paper      =>     xdg-open /you/dont/remember/where/english_paper.pdf
  vim `f rc lo`    =>     vim /etc/rc.local
  vim `f rc conf`  =>     vim /etc/rc.conf
```

Fasd comes with four useful aliases by default:

```sh
alias a='fasd -a' # any
alias s='fasd -s' # show / search / select
alias d='fasd -d' # directory
alias f='fasd -f' # file
alias z='fasd_cd -d' # cd, same functionality as j in autojump
```

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:

```sh
mv update.html `d www`
cp `f mov` .
```

# Install

Fasd is available in various package managers. Please check
[the wiki page](https://github.com/clvv/fasd/wiki/Installing-via-Package-Managers)
for an up-to-date list.

You can also manually obtain a copy of fasd.

Download fasd 0.5.3 from GitHub:
[zip](https://github.com/clvv/fasd/zipball/0.5.3),
[tar.gz](https://github.com/clvv/fasd/tarball/0.5.3).

Fasd is a self-contained POSIX shell script that can be either sourced or
executed. A Makefile is provided to install `fasd` and `fasd.1` to desired
places.

System-wide install:

    make install

Install to $HOME:

    PREFIX=$HOME make install

Or alternatively you can just copy `fasd` to anywhere you like (preferably
under some directory in `$PATH`).

To get fasd working in a shell, some initialization code must be run. Put the
line below in your shell rc.

```sh
eval "$(fasd --init auto)"
```

This will setup a command hook that executes on every command and advanced tab
completion for zsh and bash.

If you want more control over what gets into your shell environment, you can
pass customized set of arguments to `fasd --init`.

```
zsh-hook             # define _fasd_preexec and add it to zsh preexec array
zsh-ccomp            # zsh command mode completion definitions
zsh-ccomp-install    # setup command mode completion for zsh
zsh-wcomp            # zsh word mode completion definitions
zsh-wcomp-install    # setup word mode completioin for zsh
bash-hook            # add hook code to bash $PROMPT_COMMAND
bash-ccomp           # bash command mode completion definitions
bash-ccomp-install   # setup command mode completion for bash
bash-wcomp           # bash word mode completion definitions (experimental)
bash-wcomp-install   # setup word mode completion for bash (experimental)
posix-alias          # define alias that applies to all posix shells
posix-hook           # setup $PS1 hook for shells that's posix compatible
```

Example for a minimal zsh setup (no tab completion):

```sh
eval "$(fasd --init posix-alias zsh-hook)"
```

Optionally, if you can also source `fasd` if you want `fasd` to be a shell
function instead of an executable.

You can tweak initialization code. For instance, if you want to use "c"
instead of "z" to do directory jumping. You run the code below:

    # function to execute built-in cd
    fasd_cd() { [ $# -gt 1 ] && cd "$(fasd -e echo "$@")" || fasd "$@"; }
    alias c='fasd_cd -d' # `-d' option present for bash completion

After you first installed fasd, open some files (with any program) or `cd`
around in your shell. Then try some examples below.

# Examples

```sh
f foo # list recent files mathcing foo
a foo bar # list recent files and directories mathcing foo and bar
f -e vim foo # run vim on the most frecent file matching foo<commit_msg>Shell syntax highlighting for a code snippet on GitHub.<commit_after># Fasd

Fasd is a tool for quick access to files for POSIX shells. It is inspired by
tools like `autojump`(https://github.com/joelthelion/autojump),
`z`(http://github.com/rupa/z) and `v`(https://github.com/rupa/v). Fasd keeps
track of files you have accessed, so that you can quickly reference them in the
command line.

The name fasd comes from the default suggested aliases `f`(files),
`a`(files/directories), `s`(show/search/select), `d`(directories).

Fasd ranks files and directories by "frecency," that is, by both "frequency" and
"recency." The term "frecency" was first coined by Mozilla and used in Firefox
([link](https://developer.mozilla.org/en/The_Places_frecency_algorithm)).

Fasd uses [Bayesian Inference](https://en.wikipedia.org/wiki/Bayesian_inference)
and [Bayesian Ranking](https://github.com/clvv/fasd/wiki/Bayesian-Ranking) to rank
files and directories for a set of given matching patterns. "Frecency" is used
as the prior probability distribution, and a simple algorithm is used to
calculate the likelihood of the given set of patterns.

# A Note for Early Adopters

Fasd was originally named `f`. `f` was renamed to fasd for various reasons. And
the latest release contains many improvements compared to old master branch of
`f`, most importantly fasd acquired the ability to be run as an executable
(instead of as a shell function, which is comparably slower). Previous f users
please update all of your f-related configurations accordingly. And don't
forget to rename your database file:

```sh
mv "$HOME/.f" "$HOME/.fasd"
```

# Introduction

If you're like me, you use your shell to navigate and launch applications. Fasd
helps you do that 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 "frecent" 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 "expand" your command into the right side. Pretty magic, huh?

```
  v def conf       =>     vim /some/awkward/path/to/type/default.conf
  j abc            =>     cd /hell/of/a/awkward/path/to/get/to/abcdef
  m movie          =>     mplayer /whatever/whatever/whatever/awesome_movie.mp4
  o eng paper      =>     xdg-open /you/dont/remember/where/english_paper.pdf
  vim `f rc lo`    =>     vim /etc/rc.local
  vim `f rc conf`  =>     vim /etc/rc.conf
```

Fasd comes with four useful aliases by default:

```sh
alias a='fasd -a' # any
alias s='fasd -s' # show / search / select
alias d='fasd -d' # directory
alias f='fasd -f' # file
alias z='fasd_cd -d' # cd, same functionality as j in autojump
```

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:

```sh
mv update.html `d www`
cp `f mov` .
```

# Install

Fasd is available in various package managers. Please check
[the wiki page](https://github.com/clvv/fasd/wiki/Installing-via-Package-Managers)
for an up-to-date list.

You can also manually obtain a copy of fasd.

Download fasd 0.5.3 from GitHub:
[zip](https://github.com/clvv/fasd/zipball/0.5.3),
[tar.gz](https://github.com/clvv/fasd/tarball/0.5.3).

Fasd is a self-contained POSIX shell script that can be either sourced or
executed. A Makefile is provided to install `fasd` and `fasd.1` to desired
places.

System-wide install:

    make install

Install to $HOME:

    PREFIX=$HOME make install

Or alternatively you can just copy `fasd` to anywhere you like (preferably
under some directory in `$PATH`).

To get fasd working in a shell, some initialization code must be run. Put the
line below in your shell rc.

```sh
eval "$(fasd --init auto)"
```

This will setup a command hook that executes on every command and advanced tab
completion for zsh and bash.

If you want more control over what gets into your shell environment, you can
pass customized set of arguments to `fasd --init`.

```
zsh-hook             # define _fasd_preexec and add it to zsh preexec array
zsh-ccomp            # zsh command mode completion definitions
zsh-ccomp-install    # setup command mode completion for zsh
zsh-wcomp            # zsh word mode completion definitions
zsh-wcomp-install    # setup word mode completioin for zsh
bash-hook            # add hook code to bash $PROMPT_COMMAND
bash-ccomp           # bash command mode completion definitions
bash-ccomp-install   # setup command mode completion for bash
bash-wcomp           # bash word mode completion definitions (experimental)
bash-wcomp-install   # setup word mode completion for bash (experimental)
posix-alias          # define alias that applies to all posix shells
posix-hook           # setup $PS1 hook for shells that's posix compatible
```

Example for a minimal zsh setup (no tab completion):

```sh
eval "$(fasd --init posix-alias zsh-hook)"
```

Optionally, if you can also source `fasd` if you want `fasd` to be a shell
function instead of an executable.

You can tweak initialization code. For instance, if you want to use "c"
instead of "z" to do directory jumping. You run the code below:

```sh
# function to execute built-in cd
fasd_cd() { [ $# -gt 1 ] && cd "$(fasd -e echo "$@")" || fasd "$@"; }
alias c='fasd_cd -d' # `-d' option present for bash completion
```

After you first installed fasd, open some files (with any program) or `cd`
around in your shell. Then try some examples below.

# Examples

```sh
f foo # list recent files mathcing foo
a foo bar # list recent files and directories mathcing foo and bar
f -e vim foo # run vim on the most frecent file matching foo
{'fraction_non_alphanumeric': 0.08775439206818578, 'fraction_numerical': 0.0022612628283179685, 'mean_word_length': 3.6255028157683027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 16, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3034285', 'n_tokens_mistral': 3587, 'n_tokens_neox': 3437, 'n_words': 1572}