You are not logged in.

#1 2012-02-12 04:33:26

clvv
Member
Registered: 2011-02-07
Posts: 9

Fasd - Quick Access to Frequent/Recent Files and Directories

Hello fellow Archers,

Fasd is built for faster access to resources in a command shell.

A quick grasp of what fasd is:

  • Autojump(forum link), and z(github) with support for files

  • History file / directory completion that's path aware

  • Custom program launcher (like v(github)) for recent / frequent files

  • Smart address bar (chromium, firefox) for the command line

A few examples:

z vim proj              # cd into the most "frecent" directory matching proj and vim, just like autojump or z
cp readme `d vim proj`  # copy "readme" to the most "frecent" directory matching vim and proj
cp readme `sd vim prok` # interactive select a directory out of a list of dirs matching vim and proj
alias v='f -e vim'      # set up alias for launching vim on "frecent" files
v x vim                 # launch vim on the most frecent file matching x and vim
apvlv `sf pdf`          # intereactively select a file out of a list of files matching pdf and launch apvlv
apvlv f,pdf<TAB>        # tab complete frecent files mathcing pdf (only in zsh, experimental support for bash)
ls d,bundle<TAB>        # tab complete frecent directories mathcing bundle (only in zsh, experimental support for bash)

Fasd is now in AUR: https://aur.archlinux.org/packages.php?ID=56604

Fasd is self-contained in only one executable "fasd". It is suggested that you use the defualt alias f, a, s, d, and z.

To set up fasd in your shell, put code below into you .bashrc or .zshrc:

eval "$(fasd --init auto)"

The above code will do three things:
1. Set up command hook that will be executed after every command (to track files and directories)
2. Set up tab completion
3. Set up default aliases: f (files), a (any: files and dir), s (show / search / select), d (directories), z (cd)

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):

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.

More comprehensive documentation and other information:
1. man fasd
2. Fasd on Github
3. Fasd wiki on Github

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 "MIT/X11" license.

Last edited by clvv (2012-02-13 01:25:13)

Offline

#2 2012-02-12 14:48:12

mutantpineapple
Member
From: UK
Registered: 2009-12-16
Posts: 29

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

So far it seems great. Thanks! I have sv aliased to 'f -e "sudo vim"' and I couldn't be happier with the result.
What format should the backends take? I'd like to provide a list of directories for fasd to start jumping to right away.

Offline

#3 2012-02-12 21:06:36

clvv
Member
Registered: 2011-02-07
Posts: 9

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

If you want to hardcode some paths, you can just edit your database file "~/.fasd". Backends are there for other sources.
It follows this format, one entry per line:

path|rank|timestamp

Rank shows roughly how many times the file / dir has been accessed. Timestamp is the last access timestamp.

Edit: by the way, multiple words for '-e' is not yet officially supported(only work in bash right now). I'm working on it for the next release.

Glad to know you like the tool!

Last edited by clvv (2012-02-12 21:11:54)

Offline

#4 2012-02-12 21:18:57

Awebb
Member
Registered: 2010-05-06
Posts: 6,688

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

I'm currently trying it. I still don't know if this is something I want to get used to, but it's nice playing around with fasd.

You have, by the way, a typo in your manpage: "Defualt backends".

Offline

#5 2012-02-12 21:42:54

clvv
Member
Registered: 2011-02-07
Posts: 9

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

Awebb wrote:

I'm currently trying it. I still don't know if this is something I want to get used to, but it's nice playing around with fasd.

You have, by the way, a typo in your manpage: "Defualt backends".

Thanks, I just went through all the docs and corrected all the typos I could find. It looks like I make this typo a lot.

Offline

#6 2012-02-13 11:34:01

mutantpineapple
Member
From: UK
Registered: 2009-12-16
Posts: 29

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

The s command doesn't seem to like typos. For instance, if I do this:

/home/dan/ → v `s rc`
2    240        /home/dan/.bashrc
1    1200       /etc/rc.conf

and then press, say, 5, or a letter, I get a list of apparently my most recent files:

> 5
6    4          /etc/cups/ppd/deskjet-3050a.ppd
5    8          /etc/cups/printers.conf
4    12         /home/dan/.bashrc
3    24         /home/dan/.environment/xmonad/xmonad.hs
2    30         /home/dan/.fasd
1    60         /etc/rc.conf

Entering another invalid number at this point opens vim at the current directory listing, while entering a letter returns me to the command prompt.

Offline

#7 2012-02-13 15:48:42

clvv
Member
Registered: 2011-02-07
Posts: 9

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

mutantpineapple wrote:

The s command doesn't seem to like typos. For instance, if I do this:

/home/dan/ → v `s rc`
2    240        /home/dan/.bashrc
1    1200       /etc/rc.conf

and then press, say, 5, or a letter, I get a list of apparently my most recent files:

> 5
6    4          /etc/cups/ppd/deskjet-3050a.ppd
5    8          /etc/cups/printers.conf
4    12         /home/dan/.bashrc
3    24         /home/dan/.environment/xmonad/xmonad.hs
2    30         /home/dan/.fasd
1    60         /etc/rc.conf

Entering another invalid number at this point opens vim at the current directory listing, while entering a letter returns me to the command prompt.

Which shell are you using?

This is probably caused by a problem in your shell setup. For instance, this behavior is observed under zsh with oh-my-zsh.

Try this in your shell:

echo `echo 1 >&2`

It should print:

1

But if it prints:

1
1

then you should check your shell setup. Basicaly some code is causing your shell to evaluate the command substitution twice.

Offline

#8 2012-02-14 01:11:49

mutantpineapple
Member
From: UK
Registered: 2009-12-16
Posts: 29

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

I'm using bash. Running that command gives me a single 1 and a blank line below it.

Offline

#9 2012-02-14 01:19:31

mutantpineapple
Member
From: UK
Registered: 2009-12-16
Posts: 29

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

Sorry, just realised that it's actually the expected behaviour. `s rc` does the initial selection, and when I enter an invalid number it returns nothing, so then v is run without an argument so it presents the list of likely files.

Offline

#10 2012-02-14 02:28:49

clvv
Member
Registered: 2011-02-07
Posts: 9

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

mutantpineapple wrote:

Sorry, just realised that it's actually the expected behaviour. `s rc` does the initial selection, and when I enter an invalid number it returns nothing, so then v is run without an argument so it presents the list of likely files.

My bad, I didn't really think about what you were doing first. Your analysis is right.

It doesn't really makes sense to use 'v `s rc`', since you're really doing the selection process twice. But it works if you select an valid entry the first time, then the second time the last argument to fasd will be an absolute path, in which case fasd defaults to use it directly.

It's a matter of personal taste whether to do a interactive selection or just type a few extra letters. But I'm sure you already know that you can pass '-i' option to force enable interactive mode.

Offline

#11 2012-02-15 14:07:50

mutantpineapple
Member
From: UK
Registered: 2009-12-16
Posts: 29

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

You're right, that's a much more sensible way of doing the same thing.
I still notice a difference between entering an invalid number and entering a letter. If I'm given two options and I press 3, the output is a blank line, but if I press a letter then there's no output at all. This means that the v command will open vim on the current directory listing if an invalid number is entered, but will return to the command prompt if a letter is entered. The obvious answer is "be accurate", but perhaps it would be good to be consistent in how typos are handled.

Offline

#12 2012-02-15 15:16:12

clvv
Member
Registered: 2011-02-07
Posts: 9

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

mutantpineapple wrote:

You're right, that's a much more sensible way of doing the same thing.
I still notice a difference between entering an invalid number and entering a letter. If I'm given two options and I press 3, the output is a blank line, but if I press a letter then there's no output at all. This means that the v command will open vim on the current directory listing if an invalid number is entered, but will return to the command prompt if a letter is entered. The obvious answer is "be accurate", but perhaps it would be good to be consistent in how typos are handled.

Thanks for noticing this. Now it is specifically checked that if a selected entry is valid, and no invalid arguments will be passed on to the command. The fix will be included in the next release.

Offline

#13 2012-02-21 22:15:17

joepvd
Member
Registered: 2011-10-06
Posts: 31

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

Just wanted to say thanks! Have been using a few month's old version of f for a while, and f has helped to ease the pain of the (slow) transformation from terminal cannon fudder to, ahem, command line warrior.

Happy to try it out smile

Offline

#14 2012-06-09 15:01:06

meszka
Member
From: Poznań, Poland
Registered: 2010-07-18
Posts: 7

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

Fantastic tool!
And you can easily use it with dmenu smile Here's what I bound to mod-o (right next to mod-p for apps):

#!/bin/bash
exec xdg-open "$(fasd -al |\
    tac |\
    sed "s:$HOME:~:" |\
    dmenu "$@" |\
    sed "s:~:$HOME:")"

Offline

#15 2012-06-09 19:18:08

theGunslinger
Member
Registered: 2011-05-20
Posts: 300

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

Amazing piece of software, made me tons faster in working the terminal.

Offline

#16 2012-06-10 12:05:43

utdemir
Member
Registered: 2009-06-10
Posts: 23

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

Thanks for this excellent tool.

Just I'm completely stranger to shell scripting, and I've been using this function:

cd() {
    builtin cd "${@:-$HOME}" && ls
}

But it seems like

eval "$(fasd --init auto)"

overrides this function, if I move the fasd before the cd function, then fasd does not work. Do you have a workaround?

Offline

#17 2012-06-10 21:51:32

clvv
Member
Registered: 2011-02-07
Posts: 9

Re: Fasd - Quick Access to Frequent/Recent Files and Directories

utdemir wrote:

Thanks for this excellent tool.

Just I'm completely stranger to shell scripting, and I've been using this function:

cd() {
    builtin cd "${@:-$HOME}" && ls
}

But it seems like

eval "$(fasd --init auto)"

overrides this function, if I move the fasd before the cd function, then fasd does not work. Do you have a workaround?

Fasd does not override cd, so theoretically it should work, and it does in bash for me. But in zsh, after defining the above "cd" function, a function "fasd" also gets defined. I'm assuming you're using zsh, correct? If

which fasd

outputs a function definition, then we're experiencing the same issue. And yes, there is a quick work-around:

cd() {
    builtin cd "${@:-$HOME}" && ls
}
unfunction fasd

However, it works for me if I load fasd after defining cd. If the above doesn't help, you should post some error messages and other information that can help.

Offline

Board footer

Powered by FluxBB