abra zsh config 2.0

This commit is contained in:
Andrey Anurin
2018-08-12 15:26:21 +03:00
parent 201abd09c4
commit 6b114440e2
1195 changed files with 68948 additions and 10539 deletions

View File

@@ -12,6 +12,12 @@ module.
The Prezto Fasd configuration differs from the default. The default aliases have
been disabled.
Installation
------------
`fasd` is bundled with prezto as a git submodule. Alternatively, you can manually install `fasd`.
If a manual install is found, it will be used instead of the bundled version.
Aliases
-------

View File

@@ -0,0 +1 @@
gitdir: ../../../.git/modules/modules/fasd/external

View File

@@ -0,0 +1,72 @@
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.
To get fasd working in a shell, some initialization code must be run. Put the
line below in your shell rc.
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 completion 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
posix-alias # define alias that applies to all posix shells
posix-hook # setup $PS1 hook for shells that's posix compatible
tcsh-alias # define aliases for tcsh
tcsh-hook # setup tcsh precmd alias
Example for a minimal zsh setup (no tab completion):
eval "$(fasd --init posix-alias zsh-hook)"
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):
fasd_cache="$HOME/.fasd-init-bash"
if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install >| "$fasd_cache"
fi
source "$fasd_cache"
unset fasd_cache
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() {
if [ $# -le 1 ]; then
fasd "$@"
else
local _fasd_ret="$(fasd -e echo "$@")"
[ -z "$_fasd_ret" ] && return
[ -d "$_fasd_ret" ] && cd "$_fasd_ret" || echo "$_fasd_ret"
fi
}
alias c='fasd_cd -d' # `-d' option present for bash completion

20
.zprezto/modules/fasd/external/LICENSE vendored Normal file
View File

@@ -0,0 +1,20 @@
Copyright (C) 2011, 2012 by Wei Dai. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

27
.zprezto/modules/fasd/external/Makefile vendored Normal file
View File

@@ -0,0 +1,27 @@
PREFIX?= /usr/local
BINDIR?= ${PREFIX}/bin
MANDIR?= ${PREFIX}/share/man
INSTALL?= install
INSTALLDIR= ${INSTALL} -d
INSTALLBIN= ${INSTALL} -m 755
INSTALLMAN= ${INSTALL} -m 644
all: fasd.1
uninstall:
rm -f ${DESTDIR}${BINDIR}/fasd
rm -f ${DESTDIR}${MANDIR}/man1/fasd.1
install:
${INSTALLDIR} ${DESTDIR}${BINDIR}
${INSTALLBIN} fasd ${DESTDIR}${BINDIR}
${INSTALLDIR} ${DESTDIR}${MANDIR}/man1
${INSTALLMAN} fasd.1 ${DESTDIR}${MANDIR}/man1
man: fasd.1
fasd.1: fasd.1.md
pandoc -s -w man fasd.1.md -o fasd.1
.PHONY: all install uninstall man

378
.zprezto/modules/fasd/external/README.md vendored Normal file
View File

@@ -0,0 +1,378 @@
# Fasd
Fasd (pronounced similar to "fast") is a command-line productivity booster.
Fasd offers quick access to files and directories 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 and directories 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)).
# Introduction
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 "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 some useful aliases by default:
```sh
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
```
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 1.0.1 from GitHub:
[zip](https://github.com/clvv/fasd/zipball/1.0.1),
[tar.gz](https://github.com/clvv/fasd/tarball/1.0.1).
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 completion 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
posix-alias # define aliases that applies to all posix shells
posix-hook # setup $PS1 hook for shells that's posix compatible
tcsh-alias # define aliases for tcsh
tcsh-hook # setup tcsh precmd alias
```
Example for a minimal zsh setup (no tab completion):
```sh
eval "$(fasd --init posix-alias zsh-hook)"
```
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):
```sh
fasd_cache="$HOME/.fasd-init-bash"
if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install >| "$fasd_cache"
fi
source "$fasd_cache"
unset fasd_cache
```
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 can use the alias below:
```sh
alias c='fasd_cd -d'
# `-d` option present for bash completion
# function fasd_cd is defined in posix-alias
```
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 frecent files matching foo
a foo bar # list frecent files and directories matching foo and bar
f js$ # list frecent files that ends in js
f -e vim foo # run vim on the most frecent file matching foo
mplayer `f bar` # run mplayer on the most frecent file matching bar
z foo # cd into the most frecent directory matching foo
open `sf pdf` # interactively select a file matching pdf and launch `open`
```
You should add your own aliases to fully utilize the power of fasd. Here are
some examples to get you started:
```sh
alias v='f -e vim' # quick opening files with vim
alias m='f -e mplayer' # quick opening files with mplayer
alias o='a -e xdg-open' # quick opening files with xdg-open
```
If you're using bash, you have to call `_fasd_bash_hook_cmd_complete` to make
completion work. For instance:
_fasd_bash_hook_cmd_complete v m j o
You could select an entry in the list of matching files.
# Matching
Fasd has three matching modes: default, case-insensitive, and fuzzy.
For a given set of queries (the set of command-line arguments passed to fasd),
a path is a match if and only if:
1. Queries match the path *in order*.
2. The last query matches the *last segment* of the path.
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.
Tips:
* If you want your last query not to match the last segment of the path, append
`/` as the last query.
* If you want your last query to match the end of the filename, append `$` to
the last query.
# How It Works
When you run fasd init code or source `fasd`, fasd adds a hook which will be
executed whenever you execute a command. The hook will scan your commands'
arguments and determine if any of them refer to existing files or directories.
If yes, fasd will add them to the database.
# Compatibility
Fasd's 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 `$PS1` in order for fasd to automatically track your
commands and files. This feature is not specified by the POSIX standard, but
it's 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 `fasd -A`. You are very welcomed to contribute shell
initialization code for not yet supported shells.
Fasd has been tested on the following shells: bash, zsh, mksh, pdksh, dash,
busybox ash, FreeBSD 9 /bin/sh and OpenBSD /bin/sh.
# Synopsis
fasd [options] [query ...]
[f|a|s|d|z] [options] [query ...]
options:
-s list paths with scores
-l list paths without scores
-i interactive mode
-e <cmd> set command to execute on the result file
-b <name> only use <name> backend
-B <name> add additional backend <name>
-a match files and directories
-d match directories only
-f match files only
-r match by rank only
-t match by recent access only
-R reverse listing order
-h show a brief help message
-[0-9] select the nth entry
fasd [-A|-D] [paths ...]
-A add paths
-D delete paths
# Tab Completion
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.
Command mode completion is just like completion for any other commands. It is
triggered when you hit tab on a `fasd` 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.
Word mode completion can be triggered on *any* command. Word completion is
triggered by any command line argument that starts with `,` (all), `f,`
(files), or `d,` (directories), or that ends with `,,` (all), `,,f` (files), or
`,,d` (directories). Examples:
$ vim ,rc,lo<Tab>
$ vim /etc/rc.local
$ mv index.html d,www<Tab>
$ mv index.html /var/www/
There are also three zle widgets: `fasd-complete`, `fasd-complete-f`,
`fasd-complete-d`. You can bind them to keybindings you like:
```sh
bindkey '^X^A' fasd-complete # C-x C-a to do fasd-complete (files and directories)
bindkey '^X^F' fasd-complete-f # C-x C-f to do fasd-complete-f (only files)
bindkey '^X^D' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories)
```
# Backends
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's native format. Below is a list of available
backends.
```
`spotlight`
OSX spotlight, provides entries that are changed today or opened within the
past month
`recently-used`
GTK's recently-used file (Usually available on Linux)
`current`
Provides everything in $PWD (whereever you are executing `fasd`)
`viminfo`
Vim's editing history, useful if you want to define an alias just for editing
things in vim
```
You can define your own backend by declaring a function by that name in your
`.fasdrc`. You can set default backend with `_FASD_BACKENDS` variable in our
`.fasdrc`.
Fasd can mimic [v](http://github.com/rupa/v)'s behavior by this alias:
```sh
alias v='f -t -e vim -b viminfo'
```
# Tweaks
Some shell variables that you can set before sourcing `fasd`. You can set them
in `$HOME/.fasdrc`
```
$_FASD_DATA
Path to the fasd data file, default "$HOME/.fasd".
$_FASD_BLACKLIST
List of blacklisted strings. Commands matching them will not be processed.
Default is "--help".
$_FASD_SHIFT
List of all commands that needs to be shifted, defaults to "sudo busybox".
$_FASD_IGNORE
List of all commands that will be ignored, defaults to "fasd ls echo".
$_FASD_TRACK_PWD
Fasd defaults to track your "$PWD". Set this to 0 to disable this behavior.
$_FASD_AWK
Which awk to use. Fasd can detect and use a compatible awk.
$_FASD_SINK
File to log all STDERR to, defaults to "/dev/null".
$_FASD_MAX
Max total score / weight, defaults to 2000.
$_FASD_SHELL
Which shell to execute. Some shells will run faster than others. fasd
runs faster with dash and ksh variants.
$_FASD_BACKENDS
Default backends.
$_FASD_RO
If set to any non-empty string, fasd will not add or delete entries from
database. You can set and export this variable from command line.
$_FASD_FUZZY
Level of "fuzziness" when doing fuzzy matching. More precisely, the number of
characters that can be skipped to generate a match. Set to empty or 0 to
disable fuzzy matching. Default value is 2.
$_FASD_VIMINFO
Path to .viminfo file for viminfo backend, defaults to "$HOME/.viminfo"
$_FASD_RECENTLY_USED_XBEL
Path to XDG recently-used.xbel file for recently-used backend, defaults to
"$HOME/.local/share/recently-used.xbel"
```
# Debugging
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.
You can set `_FASD_SINK` in your `.fasdrc` to obtain a log.
```sh
_FASD_SINK="$HOME/.fasd.log"
```
# COPYING
Fasd is originally written based on code from [z](https://github.com/rupa/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.

636
.zprezto/modules/fasd/external/fasd vendored Executable file
View File

@@ -0,0 +1,636 @@
#!/usr/bin/env sh
# Fasd (this file) can be sourced or executed by any POSIX compatible shell.
# Fasd is originally written based on code from z (https://github.com/rupa/z)
# by rupa deadwyler under the WTFPL license. Most if not all of the code has
# been rewritten.
# Copyright (C) 2011, 2012 by Wei Dai. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
fasd() {
# make zsh do word splitting inside this function
[ "$ZSH_VERSION" ] && emulate sh && setopt localoptions
case $1 in
--init) shift
while [ "$1" ]; do
case $1 in
env)
{ # source rc files if present
[ -s "/etc/fasdrc" ] && . "/etc/fasdrc"
[ -s "$HOME/.fasdrc" ] && . "$HOME/.fasdrc"
# set default options
[ -z "$_FASD_DATA" ] && _FASD_DATA="$HOME/.fasd"
[ -z "$_FASD_BLACKLIST" ] && _FASD_BLACKLIST="--help"
[ -z "$_FASD_SHIFT" ] && _FASD_SHIFT="sudo busybox"
[ -z "$_FASD_IGNORE" ] && _FASD_IGNORE="fasd ls echo"
[ -z "$_FASD_SINK" ] && _FASD_SINK=/dev/null
[ -z "$_FASD_TRACK_PWD" ] && _FASD_TRACK_PWD=1
[ -z "$_FASD_MAX" ] && _FASD_MAX=2000
[ -z "$_FASD_BACKENDS" ] && _FASD_BACKENDS=native
[ -z "$_FASD_FUZZY" ] && _FASD_FUZZY=2
[ -z "$_FASD_VIMINFO" ] && _FASD_VIMINFO="$HOME/.viminfo"
[ -z "$_FASD_RECENTLY_USED_XBEL" ] && \
_FASD_RECENTLY_USED_XBEL="$HOME/.local/share/recently-used.xbel"
if [ -z "$_FASD_AWK" ]; then
# awk preferences
local awk; for awk in mawk gawk original-awk nawk awk; do
$awk "" && _FASD_AWK=$awk && break
done
fi
} >> "${_FASD_SINK:-/dev/null}" 2>&1
;;
auto) cat <<EOS
{ if [ "\$ZSH_VERSION" ] && compctl; then # zsh
eval "\$(fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install \\
zsh-wcomp zsh-wcomp-install)"
elif [ "\$BASH_VERSION" ] && complete; then # bash
eval "\$(fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install)"
else # posix shell
eval "\$(fasd --init posix-alias posix-hook)"
fi
} >> "$_FASD_SINK" 2>&1
EOS
;;
posix-alias) cat <<EOS
alias a='fasd -a'
alias s='fasd -si'
alias sd='fasd -sid'
alias sf='fasd -sif'
alias d='fasd -d'
alias f='fasd -f'
# function to execute built-in cd
fasd_cd() {
if [ \$# -le 1 ]; then
fasd "\$@"
else
local _fasd_ret="\$(fasd -e 'printf %s' "\$@")"
[ -z "\$_fasd_ret" ] && return
[ -d "\$_fasd_ret" ] && cd "\$_fasd_ret" || printf %s\\n "\$_fasd_ret"
fi
}
alias z='fasd_cd -d'
alias zz='fasd_cd -d -i'
EOS
;;
tcsh-alias) cat <<EOS
;alias a 'fasd -a';
alias s 'fasd -si';
alias sd 'fasd -sid';
alias sf 'fasd -sif';
alias d 'fasd -d';
alias f 'fasd -f';
alias z 'cd "\`fasd -d -e printf\\ %s \\!*\`" >& /dev/null || fasd -d';
EOS
;;
zsh-hook) cat <<EOS
# add zsh hook
_fasd_preexec() {
{ eval "fasd --proc \$(fasd --sanitize \$2)"; } >> "$_FASD_SINK" 2>&1
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec _fasd_preexec
EOS
;;
bash-hook) cat <<EOS
_fasd_prompt_func() {
eval "fasd --proc \$(fasd --sanitize \$(history 1 | \\
sed "s/^[ ]*[0-9]*[ ]*//"))" >> "$_FASD_SINK" 2>&1
}
# add bash hook
case \$PROMPT_COMMAND in
*_fasd_prompt_func*) ;;
*) PROMPT_COMMAND="_fasd_prompt_func;\$PROMPT_COMMAND";;
esac
EOS
;;
posix-hook) cat <<EOS
_fasd_ps1_func() {
{ eval "fasd --proc \$(fasd --sanitize \$(fc -nl -1))"; } \\
>> "$_FASD_SINK" 2>&1
}
case \$PS1 in
*_fasd_ps1_func*) ;;
*) export PS1="\\\$(_fasd_ps1_func)\$PS1";;
esac
EOS
;;
tcsh-hook) cat <<EOS
;alias fasd-prev-cmd 'fasd --sanitize \`history -h 1\`';
set pprecmd="\`alias precmd\`";
alias precmd '\$pprecmd; eval "fasd --proc \`fasd-prev-cmd\`" >& /dev/null';
EOS
;;
zsh-ccomp) cat <<EOS
# zsh command mode completion
_fasd_zsh_cmd_complete() {
local compl
read -c compl
(( \$+compstate )) && compstate[insert]=menu # no expand if compsys loaded
reply=(\${(f)"\$(fasd --complete "\$compl")"})
}
EOS
;;
zsh-wcomp) cat <<EOS
(( \$+functions[compdef] )) && {
# zsh word mode completion
_fasd_zsh_word_complete() {
[ "\$2" ] && local _fasd_cur="\$2"
[ -z "\$_fasd_cur" ] && local _fasd_cur="\${words[CURRENT]}"
local fnd="\${_fasd_cur//,/ }"
local typ=\${1:-e}
fasd --query \$typ "\$fnd" 2>> "$_FASD_SINK" | \\
sort -nr | sed 's/^[^ ]*[ ]*//' | while read -r line; do
compadd -U -V fasd "\$line"
done
compstate[insert]=menu # no expand
}
_fasd_zsh_word_complete_f() { _fasd_zsh_word_complete f ; }
_fasd_zsh_word_complete_d() { _fasd_zsh_word_complete d ; }
_fasd_zsh_word_complete_trigger() {
local _fasd_cur="\${words[CURRENT]}"
eval \$(fasd --word-complete-trigger _fasd_zsh_word_complete \$_fasd_cur)
}
# define zle widgets
zle -C fasd-complete complete-word _generic
zstyle ':completion:fasd-complete:*' completer _fasd_zsh_word_complete
zstyle ':completion:fasd-complete:*' menu-select
zle -C fasd-complete-f complete-word _generic
zstyle ':completion:fasd-complete-f:*' completer _fasd_zsh_word_complete_f
zstyle ':completion:fasd-complete-f:*' menu-select
zle -C fasd-complete-d complete-word _generic
zstyle ':completion:fasd-complete-d:*' completer _fasd_zsh_word_complete_d
zstyle ':completion:fasd-complete-d:*' menu-select
}
EOS
;;
zsh-ccomp-install) cat <<EOS
# enable command mode completion
compctl -U -K _fasd_zsh_cmd_complete -V fasd -x 'C[-1,-*e],s[-]n[1,e]' -c - \\
'c[-1,-A][-1,-D]' -f -- fasd fasd_cd
EOS
;;
zsh-wcomp-install) cat <<EOS
(( \$+functions[compdef] )) && {
# enable word mode completion
orig_comp="\$(zstyle -L ':completion:\\*' completer 2>> "$_FASD_SINK")"
if [ "\$orig_comp" ]; then
case \$orig_comp in
*_fasd_zsh_word_complete_trigger*);;
*) eval "\$orig_comp _fasd_zsh_word_complete_trigger";;
esac
else
zstyle ':completion:*' completer _complete _fasd_zsh_word_complete_trigger
fi
unset orig_comp
}
EOS
;;
bash-ccomp) cat <<EOS
# bash command mode completion
_fasd_bash_cmd_complete() {
# complete command after "-e"
local cur=\${COMP_WORDS[COMP_CWORD]}
[[ \${COMP_WORDS[COMP_CWORD-1]} == -*e ]] && \\
COMPREPLY=( \$(compgen -A command \$cur) ) && return
# complete using default readline complete after "-A" or "-D"
case \${COMP_WORDS[COMP_CWORD-1]} in
-A|-D) COMPREPLY=( \$(compgen -o default \$cur) ) && return;;
esac
# get completion results using expanded aliases
local RESULT=\$( fasd --complete "\$(alias -p \$COMP_WORDS \\
2>> "$_FASD_SINK" | sed -n "\\\$s/^.*'\\\\(.*\\\\)'/\\\\1/p")
\${COMP_LINE#* }" | while read -r line; do
quote_readline "\$line" 2>/dev/null || \\
printf %q "\$line" 2>/dev/null && \\
printf \\\\n
done)
local IFS=\$'\\n'; COMPREPLY=( \$RESULT )
}
_fasd_bash_hook_cmd_complete() {
for cmd in \$*; do
complete -F _fasd_bash_cmd_complete \$cmd
done
}
EOS
;;
bash-ccomp-install) cat <<EOS
# enable bash command mode completion
_fasd_bash_hook_cmd_complete fasd a s d f sd sf z zz
EOS
;;
esac; shift
done
;;
# if "$_fasd_cur" or "$2" is a query, then output shell code to be eval'd
--word-complete-trigger)
shift; [ "$2" ] && local _fasd_cur="$2" || return
case $_fasd_cur in
,*) printf %s\\n "$1 e $_fasd_cur";;
f,*) printf %s\\n "$1 f ${_fasd_cur#?}";;
d,*) printf %s\\n "$1 d ${_fasd_cur#?}";;
*,,) printf %s\\n "$1 e $_fasd_cur";;
*,,f) printf %s\\n "$1 f ${_fasd_cur%?}";;
*,,d) printf %s\\n "$1 d ${_fasd_cur%?}";;
esac
;;
--sanitize) shift; printf %s\\n "$*" | \
sed 's/\([^\]\)$( *[^ ]* *\([^)]*\)))*/\1\2/g
s/\([^\]\)[|&;<>$`{}]\{1,\}/\1 /g'
;;
--proc) shift # process commands
# stop if we don't own $_FASD_DATA or $_FASD_RO is set
[ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return
# blacklists
local each; for each in $_FASD_BLACKLIST; do
case " $* " in *\ $each\ *) return;; esac
done
# shifts
while true; do
case " $_FASD_SHIFT " in
*\ $1\ *) shift;;
*) break;;
esac
done
# ignores
case " $_FASD_IGNORE " in
*\ $1\ *) return;;
esac
shift; fasd --add "$@" # add all arguments except command
;;
--add|-A) shift # add entries
# stop if we don't own $_FASD_DATA or $_FASD_RO is set
[ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return
# find all valid path arguments, convert them to simplest absolute form
local paths="$(while [ "$1" ]; do
[ -e "$1" ] && printf %s\\n "$1"; shift
done | sed '/^[^/]/s@^@'"$PWD"'/@
s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0
s@[^/][^/]*//*\.\./@/@;t 0
s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@;s@^$@/@' 2>> "$_FASD_SINK" \
| tr '\n' '|')"
# add current pwd if the option is set
[ "$_FASD_TRACK_PWD" = "1" -a "$PWD" != "$HOME" ] && paths="$paths|$PWD"
[ -z "${paths##\|}" ] && return # stop if we have nothing to add
# maintain the file
local tempfile
tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return
$_FASD_AWK -v list="$paths" -v now="$(date +%s)" -v max="$_FASD_MAX" -F"|" '
BEGIN {
split(list, files, "|")
for(i in files) {
path = files[i]
if(path == "") continue
paths[path] = path # array for checking
rank[path] = 1
time[path] = now
}
}
$2 >= 1 {
if($1 in paths) {
rank[$1] = $2 + 1 / $2
time[$1] = now
} else {
rank[$1] = $2
time[$1] = $3
}
count += $2
}
END {
if(count > max)
for(i in rank) print i "|" 0.9*rank[i] "|" time[i] # aging
else
for(i in rank) print i "|" rank[i] "|" time[i]
}' "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile"
if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then
env rm -f "$tempfile"
else
env mv -f "$tempfile" "$_FASD_DATA"
fi
;;
--delete|-D) shift # delete entries
# stop if we don't own $_FASD_DATA or $_FASD_RO is set
[ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return
# turn valid arguments into entry-deleting sed commands
local sed_cmd="$(while [ "$1" ]; do printf %s\\n "$1"; shift; done | \
sed '/^[^/]/s@^@'"$PWD"'/@;s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0
s@[^/][^/]*//*\.\./@/@;t 0
s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@
s@^$@/@;s@\([.[\/*^$]\)@\\\1@g;s@^\(.*\)$@/^\1|/d@' 2>> "$_FASD_SINK")"
# maintain the file
local tempfile
tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return
sed "$sed_cmd" "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile"
if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then
env rm -f "$tempfile"
else
env mv -f "$tempfile" "$_FASD_DATA"
fi
;;
--query) shift # query the db, --query [$typ ["$fnd" [$mode]]]
[ -f "$_FASD_DATA" ] || return # no db yet
[ "$1" ] && local typ="$1"
[ "$2" ] && local fnd="$2"
[ "$3" ] && local mode="$3"
# cat all backends
local each _fasd_data; for each in $_FASD_BACKENDS; do
_fasd_data="$_fasd_data
$(fasd --backend $each)"
done
[ "$_fasd_data" ] || _fasd_data="$(cat "$_FASD_DATA")"
# set mode specific code for calculating the prior
case $mode in
rank) local prior='times[i]';;
recent) local prior='sqrt(100000/(1+t-la[i]))';;
*) local prior='times[i] * frecent(la[i])';;
esac
if [ "$fnd" ]; then # dafault matching
local bre="$(printf %s\\n "$fnd" | sed 's/\([*\.\\\[]\)/\\\1/g
s@ @[^|]*@g;s/\$$/|/')"
bre='^[^|]*'"$bre"'[^|/]*|'
local _ret="$(printf %s\\n "$_fasd_data" | grep "$bre")"
[ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do
[ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line"
done)"
if [ "$_ret" ]; then
_fasd_data="$_ret"
else # no case mathcing
_ret="$(printf %s\\n "$_fasd_data" | grep -i "$bre")"
[ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do
[ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line"
done)"
if [ "$_ret" ]; then
_fasd_data="$_ret"
elif [ "${_FASD_FUZZY:-0}" -gt 0 ]; then # fuzzy matching
local fuzzy_bre="$(printf %s\\n "$fnd" | \
sed 's/\([*\.\\\[]\)/\\\1/g;s/\$$/|/
s@\(\\\{0,1\}[^ ]\)@\1[^|/]\\{0,'"$_FASD_FUZZY"'\\}@g
s@ @[^|]*@g')"
fuzzy_bre='^[^|]*'"$fuzzy_bre"'[^|/]*|'
_ret="$(printf %s\\n "$_fasd_data" | grep -i "$fuzzy_bre")"
[ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do
[ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line"
done)"
[ "$_ret" ] && _fasd_data="$_ret" || _fasd_data=
fi
fi
else # no query arugments
_fasd_data="$(printf %s\\n "$_fasd_data" | while read -r line; do
[ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line"
done)"
fi
# query the database
[ "$_fasd_data" ] && printf %s\\n "$_fasd_data" | \
$_FASD_AWK -v t="$(date +%s)" -F"|" '
function frecent(time) {
dx = t-time
if( dx < 3600 ) return 6
if( dx < 86400 ) return 4
if( dx < 604800 ) return 2
return 1
}
{
if(!paths[$1]) {
times[$1] = $2
la[$1] = $3
paths[$1] = 1
} else {
times[$1] += $2
if($3 > la[$1]) la[$1] = $3
}
}
END {
for(i in paths) printf "%-10s %s\n", '"$prior"', i
}' - 2>> "$_FASD_SINK"
;;
--backend)
case $2 in
native) cat "$_FASD_DATA";;
viminfo)
< "$_FASD_VIMINFO" sed -n '/^>/{s@~@'"$HOME"'@
s/^..//
p
}' | $_FASD_AWK -v t="$(date +%s)" '{
t -= 60
print $0 "|1|" t
}'
;;
recently-used)
local nl="$(printf '\\\nX')"; nl="${nl%X}" # slash newline for sed
tr -d '\n' < "$_FASD_RECENTLY_USED_XBEL" | \
sed 's@file:/@'"$nl"'@g;s@count="@'"$nl"'@g' | sed '1d;s/".*$//' | \
tr '\n' '|' | sed 's@|/@'"$nl"'@g' | $_FASD_AWK -F'|' '{
sum = 0
for( i=2; i<=NF; i++ ) sum += $i
print $1 "|" sum
}'
;;
current)
for path in *; do
printf "$PWD/%s|1\\n" "$path"
done
;;
spotlight)
mdfind '(kMDItemFSContentChangeDate >= $time.today) ||
kMDItemLastUsedDate >= $time.this_month' \
| sed '/Library\//d
/\.app$/d
s/$/|2/'
;;
*) eval "$2";;
esac
;;
*) # parsing logic and processing
local fnd= last= _FASD_BACKENDS="$_FASD_BACKENDS" _fasd_data= comp= exec=
while [ "$1" ]; do case $1 in
--complete) [ "$2" = "--" ] && shift; set -- $2; local lst=1 r=r comp=1;;
--query|--add|--delete|-A|-D) fasd "$@"; return $?;;
--version) [ -z "$comp" ] && echo "1.0.1" && return;;
--) while [ "$2" ]; do shift; fnd="$fnd $1"; last="$1"; done;;
-*) local o="${1#-}"; while [ "$o" ]; do case $o in
s*) local show=1;;
l*) local lst=1;;
i*) [ -z "$comp" ] && local interactive=1 show=1;;
r*) local mode=rank;;
t*) local mode=recent;;
e*) o="${o#?}"; if [ "$o" ]; then # there are characters after "-e"
local exec="$o" # anything after "-e"
else # use the next argument
local exec="${2:?"-e: Argument needed "}"
shift
fi; break;;
b*) o="${o#?}"; if [ "$o" ]; then
_FASD_BACKENDS="$o"
else
_FASD_BACKENDS="${2:?"-b: Argument needed"}"
shift
fi; break;;
B*) o="${o#?}"; if [ "$o" ]; then
_FASD_BACKENDS="$_FASD_BACKENDS $o"
else
_FASD_BACKENDS="$_FASD_BACKENDS ${2:?"-B: Argument needed"}"
shift
fi; break;;
a*) local typ=e;;
d*) local typ=d;;
f*) local typ=f;;
R*) local r=r;;
[0-9]*) local _fasd_i="$o"; break;;
h*) [ -z "$comp" ] && echo "fasd [options] [query ...]
[f|a|s|d|z] [options] [query ...]
options:
-s list paths with scores
-l list paths without scores
-i interactive mode
-e <cmd> set command to execute on the result file
-b <name> only use <name> backend
-B <name> add additional backend <name>
-a match files and directories
-d match directories only
-f match files only
-r match by rank only
-t match by recent access only
-R reverse listing order
-h show a brief help message
-[0-9] select the nth entry
fasd [-A|-D] [paths ...]
-A add paths
-D delete paths" >&2 && return;;
esac; o="${o#?}"; done;;
*) fnd="$fnd $1"; last="$1";;
esac; shift; done
# guess whether the last query is selected from tab completion
case $last in
/?*) if [ -z "$show$lst" -a -${typ:-e} "$last" -a "$exec" ]; then
$exec "$last"
return
fi;;
esac
local R; [ -z "$r" ] && R=r || R= # let $R be the opposite of $r
fnd="${fnd# }"
local res
res="$(fasd --query 2>> "$_FASD_SINK")" # query the database
[ $? -gt 0 ] && return
if [ 0 -lt ${_fasd_i:-0} ] 2>> "$_FASD_SINK"; then
res="$(printf %s\\n "$res" | sort -n${R} | \
sed -n "$_fasd_i"'s/^[^ ]*[ ]*//p')"
elif [ "$interactive" ] || [ "$exec" -a -z "$fnd$lst$show" -a -t 1 ]; then
if [ "$(printf %s "$res" | sed -n '$=')" -gt 1 ]; then
res="$(printf %s\\n "$res" | sort -n${R})"
printf %s\\n "$res" | sed = | sed 'N;s/\n/ /' | sort -nr >&2
printf "> " >&2
local i; read i; [ 0 -lt "${i:-0}" ] 2>> "$_FASD_SINK" || return 1
fi
res="$(printf %s\\n "$res" | sed -n "${i:-1}"'s/^[^ ]*[ ]*//p')"
elif [ "$lst" ]; then
[ "$res" ] && printf %s\\n "$res" | sort -n${r} | sed 's/^[^ ]*[ ]*//'
return
elif [ "$show" ]; then
[ "$res" ] && printf %s\\n "$res" | sort -n${r}
return
elif [ "$fnd" ] && [ "$exec" -o ! -t 1 ]; then # exec or subshell
res="$(printf %s\\n "$res" | sort -n | sed -n '$s/^[^ ]*[ ]*//p')"
else # no args, show
[ "$res" ] && printf %s\\n "$res" | sort -n${r}
return
fi
if [ "$res" ]; then
fasd --add "$res"
[ -z "$exec" ] && exec='printf %s\n'
$exec "$res"
fi
;;
esac
}
fasd --init env
case $- in
*i*) ;; # assume being sourced, do nothing
*) # assume being executed as an executable
if [ -x "$_FASD_SHELL" -a -z "$_FASD_SET" ]; then
_FASD_SET=1 exec $_FASD_SHELL "$0" "$@"
else
fasd "$@"
fi;;
esac

313
.zprezto/modules/fasd/external/fasd.1 vendored Normal file
View File

@@ -0,0 +1,313 @@
.TH "FASD" "1" "Jul 16, 2012" "fasd user manual" ""
.SH NAME
.PP
fasd \- quick access to files and directories
.SH SYNOPSIS
.PP
fasd [options] [query ...]
.PP
[f|a|s|d|z] [options] [query ...]
.PP
fasd [\-A|\-D] [paths ...]
.SH OPTIONS
.IP
.nf
\f[C]
\-s\ \ \ \ \ \ \ \ \ list\ paths\ with\ ranks
\-l\ \ \ \ \ \ \ \ \ list\ paths\ without\ ranks
\-i\ \ \ \ \ \ \ \ \ interactive\ mode
\-e\ <cmd>\ \ \ set\ command\ to\ execute\ on\ the\ result\ file
\-b\ <name>\ \ only\ use\ <name>\ backend
\-B\ <name>\ \ add\ additional\ backend\ <name>
\-a\ \ \ \ \ \ \ \ \ match\ files\ and\ directories
\-d\ \ \ \ \ \ \ \ \ match\ directories\ only
\-f\ \ \ \ \ \ \ \ \ match\ files\ only
\-r\ \ \ \ \ \ \ \ \ match\ by\ rank\ only
\-t\ \ \ \ \ \ \ \ \ match\ by\ recent\ access\ only
\-R\ \ \ \ \ \ \ \ \ reverse\ listing\ order
\-h\ \ \ \ \ \ \ \ \ show\ a\ brief\ help\ message
\-[0\-9]\ \ \ \ \ select\ the\ nth\ entry
\f[]
.fi
.SH DESCRIPTION
.PP
Fasd keeps track of files and directories you access in your shell and
gives you quick access to them.
You can use fasd to reference files or directories by just a few key
identifying characters.
You can use fasd to boost your command line productivity by defining
your own aliases to launch programs on files or directories.
Fasd, by default, provides some basic aliases, including a shell
function "z" that resembles the functionality of "z" and "autojump."
.PP
The name "fasd" comes from the default suggested aliases
\f[C]f\f[](files), \f[C]a\f[](files/directories),
\f[C]s\f[](show/search/select), \f[C]d\f[](directories).
.PP
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.
.SH EXAMPLES
.IP
.nf
\f[C]
z\ bundle
f\ \-e\ vim\ nginx\ conf
f\ \-i\ rc$
vi\ `f\ nginx\ conf`
cp\ update.html\ `d\ www`
open\ `sf\ pdf`
\f[]
.fi
.SH SHELL INITIALIZATION
.PP
To get fasd working in a shell, some initialization code must be run.
Put lines below in your POSIX compatible shell rc.
.IP
.nf
\f[C]
eval\ "$(fasd\ \-\-init\ auto)"
\f[]
.fi
.PP
This will setup a command hook that executes on every command and
advanced tab completion for zsh and bash.
.PP
If you want more control over what gets into your shell environment, you
can pass customized set of arguments to \f[C]fasd\ \-\-init\f[].
.IP
.nf
\f[C]
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\ completion\ 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
posix\-alias\ \ \ \ \ \ \ \ \ \ #\ define\ aliases\ that\ applies\ to\ all\ posix\ shells
posix\-hook\ \ \ \ \ \ \ \ \ \ \ #\ setup\ $PS1\ hook\ for\ shells\ that\[aq]s\ posix\ compatible
tcsh\-alias\ \ \ \ \ \ \ \ \ \ \ #\ define\ aliases\ for\ tcsh
tcsh\-hook\ \ \ \ \ \ \ \ \ \ \ \ #\ setup\ tcsh\ precmd\ alias
\f[]
.fi
.PP
Example for a minimal zsh setup (no tab completion):
.IP
.nf
\f[C]
eval\ "$(fasd\ \-\-init\ posix\-alias\ zsh\-hook)"
\f[]
.fi
.PP
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):
.IP
.nf
\f[C]
fasd_cache="$HOME/.fasd\-init\-bash"
if\ [\ "$(command\ \-v\ fasd)"\ \-nt\ "$fasd_cache"\ \-o\ !\ \-s\ "$fasd_cache"\ ];\ then
\ \ fasd\ \-\-init\ posix\-alias\ bash\-hook\ bash\-ccomp\ bash\-ccomp\-install\ >|\ "$fasd_cache"
fi
source\ "$fasd_cache"
unset\ fasd_cache
\f[]
.fi
.PP
Optionally, if you can also source \f[C]fasd\f[] if you want
\f[C]fasd\f[] to be a shell function instead of an executable.
.PP
You can tweak initialization code.
For instance, if you want to use "c" instead of "z" to do directory
jumping, you can use the alias below:
.IP
.nf
\f[C]
alias\ c=\[aq]fasd_cd\ \-d\[aq]
#\ `\-d\[aq]\ option\ present\ for\ bash\ completion
#\ function\ fasd_cd\ is\ defined\ in\ posix\-alias
\f[]
.fi
.SH MATCHING
.PP
Fasd has three matching modes: default, case\-insensitive, and fuzzy.
.PP
For a given set of queries (the set of command\-line arguments passed to
fasd), a path is a match if and only if:
.IP "1." 3
Queries match the path in order.
.IP "2." 3
The last query matches the last segment of the path.
.PP
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.
.PP
Tips:
.IP \[bu] 2
If you want your last query not to match the last segment of the path,
append `/\[aq] as the last query.
.IP \[bu] 2
If you want your last query to match the end of the filename, append
`$\[aq] to the last query.
.SH COMPATIBILITY
.PP
Fasd\[aq]s 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 $PS1 in order for
fasd to automatically track your commands and files.
This feature is not specified by the POSIX standard, but it\[aq]s
nonetheless present in many POSIX compliant shells.
In shells without prompt command or prompt command substitution (tcsh
for instance), you can add entries manually with "fasd \-A".
You are very welcomed to contribute shell initialization code for not
yet supported shells.
.SH TAB COMPLETION
.PP
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.
.PP
Command mode completion is just like completion for any other commands.
It is triggered when you hit tab on a fasd 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.
.PP
Word mode completion can be triggered on \f[I]any\f[] command.
Word completion is triggered by any command line argument that starts
with "," (all), "f," (files), or "d," (directories), or that ends with
",," (all), ",,f" (files), or ",,d" (directories).
Examples:
.IP
.nf
\f[C]
$\ vim\ ,rc,lo<Tab>
$\ vim\ /etc/rc.local
$\ mv\ index.html\ d,www<Tab>
$\ mv\ index.html\ /var/www/
\f[]
.fi
.PP
There are also three zle widgets: "fasd\-complete", "fasd\-complete\-f",
"fasd\-complete\-d".
You can bind them to keybindings you like:
.IP
.nf
\f[C]
bindkey\ \[aq]^X^A\[aq]\ fasd\-complete\ \ \ \ #\ C\-x\ C\-a\ to\ do\ fasd\-complete\ (files\ and\ directories)
bindkey\ \[aq]^X^F\[aq]\ fasd\-complete\-f\ \ #\ C\-x\ C\-f\ to\ do\ fasd\-complete\-f\ (only\ files)
bindkey\ \[aq]^X^D\[aq]\ fasd\-complete\-d\ \ #\ C\-x\ C\-d\ to\ do\ fasd\-complete\-d\ (only\ directories)
\f[]
.fi
.SH BACKENDS
.PP
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\[aq]s native format.
Below is a list of available backends.
.IP \[bu] 2
spotlight: OSX spotlight, provides entries that are changed today or
opened within the past month
.IP \[bu] 2
recently\-used: GTK\[aq]s recently\-used file (Usually available on
Linux)
.IP \[bu] 2
current: Provides everything in $PWD (whereever you are executing
\f[C]fasd\f[])
.IP \[bu] 2
viminfo: Vim\[aq]s editing history, useful if you want to define an
alias just for editing things in vim
.PP
You can define your own backend by declaring a function by that name in
your \f[C]\&.fasdrc\f[].
You can set default backend with \f[C]_FASD_BACKENDS\f[] variable in our
\f[C]\&.fasdrc\f[].
.SH TWEAKS
.PP
Upon every execution, fasd will source "/etc/fasdrc" and "$HOME/.fasdrc"
if they are present.
Below are some variables you can set:
.IP
.nf
\f[C]
$_FASD_DATA
Path\ to\ the\ fasd\ data\ file,\ default\ "$HOME/.fasd".
$_FASD_BLACKLIST
List\ of\ blacklisted\ strings.\ Commands\ matching\ them\ will\ not\ be\ processed.
Default\ is\ "\-\-help".
$_FASD_SHIFT
List\ of\ all\ commands\ that\ needs\ to\ be\ shifted,\ defaults\ to\ "sudo\ busybox".
$_FASD_IGNORE
List\ of\ all\ commands\ that\ will\ be\ ignored,\ defaults\ to\ "fasd\ ls\ echo".
$_FASD_TRACK_PWD
Fasd\ defaults\ to\ track\ your\ "$PWD".\ Set\ this\ to\ 0\ to\ disable\ this\ behavior.
$_FASD_AWK
Which\ awk\ to\ use.\ fasd\ can\ detect\ and\ use\ a\ compatible\ awk.
$_FASD_SINK
File\ to\ log\ all\ STDERR\ to,\ defaults\ to\ "/dev/null".
$_FASD_MAX
Max\ total\ score\ /\ weight,\ defaults\ to\ 2000.
$_FASD_SHELL
Which\ shell\ to\ execute.\ Some\ shells\ will\ run\ faster\ than\ others.\ fasd
runs\ faster\ with\ dash\ and\ ksh\ variants.
$_FASD_BACKENDS
Default\ backends.
$_FASD_RO
If\ set\ to\ any\ non\-empty\ string,\ fasd\ will\ not\ add\ or\ delete\ entries\ from
database.\ You\ can\ set\ and\ export\ this\ variable\ from\ command\ line.
$_FASD_FUZZY
Level\ of\ "fuzziness"\ when\ doing\ fuzzy\ matching.\ More\ precisely,\ the\ number\ of
characters\ that\ can\ be\ skipped\ to\ generate\ a\ match.\ Set\ to\ empty\ or\ 0\ to
disable\ fuzzy\ matching.\ Default\ value\ is\ 2.
$_FASD_VIMINFO
Path\ to\ .viminfo\ file\ for\ viminfo\ backend,\ defaults\ to\ "$HOME/.viminfo"
$_FASD_RECENTLY_USED_XBEL
Path\ to\ XDG\ recently\-used.xbel\ file\ for\ recently\-used\ backend,\ defaults\ to
"$HOME/.local/share/recently\-used.xbel"
\f[]
.fi
.SH DEBUGGING
.PP
Fasd is hosted on GitHub: https://github.com/clvv/fasd
.PP
If fasd does not work as expected, please file a bug report on GitHub
describing the unexpected behavior along with your OS version, shell
version, awk version, sed version, and a log file.
.PP
You can set \f[C]_FASD_SINK\f[] in your \f[C]\&.fasdrc\f[] to obtain a
log.
.IP
.nf
\f[C]
_FASD_SINK="$HOME/.fasd.log"
\f[]
.fi
.SH COPYING
.PP
Fasd is originally written based on code from z
(https://github.com/rupa/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.
.SH AUTHORS
Wei Dai <x@wei23.net>.

263
.zprezto/modules/fasd/external/fasd.1.md vendored Normal file
View File

@@ -0,0 +1,263 @@
% FASD(1) fasd user manual
% Wei Dai <x@wei23.net>
% Jul 16, 2012
# NAME
fasd - quick access to files and directories
# SYNOPSIS
fasd [options] [query ...]
[f|a|s|d|z] [options] [query ...]
fasd [-A|-D] [paths ...]
# OPTIONS
-s list paths with ranks
-l list paths without ranks
-i interactive mode
-e <cmd> set command to execute on the result file
-b <name> only use <name> backend
-B <name> add additional backend <name>
-a match files and directories
-d match directories only
-f match files only
-r match by rank only
-t match by recent access only
-R reverse listing order
-h show a brief help message
-[0-9] select the nth entry
# DESCRIPTION
Fasd keeps track of files and directories you access in your shell and gives you
quick access to them. You can use fasd to reference files or directories by just
a few key identifying characters. You can use fasd to boost your command line
productivity by defining your own aliases to launch programs on files or
directories. Fasd, by default, provides some basic aliases, including a shell
function "z" that resembles the functionality of "z" and "autojump."
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.
# EXAMPLES
z bundle
f -e vim nginx conf
f -i rc$
vi `f nginx conf`
cp update.html `d www`
open `sf pdf`
# SHELL INITIALIZATION
To get fasd working in a shell, some initialization code must be run. Put
lines below in your POSIX compatible shell rc.
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 completion 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
posix-alias # define aliases that applies to all posix shells
posix-hook # setup $PS1 hook for shells that's posix compatible
tcsh-alias # define aliases for tcsh
tcsh-hook # setup tcsh precmd alias
Example for a minimal zsh setup (no tab completion):
eval "$(fasd --init posix-alias zsh-hook)"
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):
fasd_cache="$HOME/.fasd-init-bash"
if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install >| "$fasd_cache"
fi
source "$fasd_cache"
unset fasd_cache
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 can use the alias below:
alias c='fasd_cd -d'
# `-d' option present for bash completion
# function fasd_cd is defined in posix-alias
# MATCHING
Fasd has three matching modes: default, case-insensitive, and fuzzy.
For a given set of queries (the set of command-line arguments passed to fasd),
a path is a match if and only if:
1. Queries match the path in order.
2. The last query matches the last segment of the path.
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.
Tips:
* If you want your last query not to match the last segment of the path, append
`/' as the last query.
* If you want your last query to match the end of the filename, append `$' to
the last query.
# COMPATIBILITY
Fasd's 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 $PS1 in order for fasd to automatically track your
commands and files. This feature is not specified by the POSIX standard, but
it's nonetheless present in many POSIX compliant shells. In shells without
prompt command or prompt command substitution (tcsh for instance), you can add
entries manually with "fasd -A". You are very welcomed to contribute shell
initialization code for not yet supported shells.
# TAB COMPLETION
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.
Command mode completion is just like completion for any other commands. It is
triggered when you hit tab on a fasd 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.
Word mode completion can be triggered on *any* command. Word completion is
triggered by any command line argument that starts with "," (all), "f,"
(files), or "d," (directories), or that ends with ",," (all), ",,f" (files),
or ",,d" (directories). Examples:
$ vim ,rc,lo<Tab>
$ vim /etc/rc.local
$ mv index.html d,www<Tab>
$ mv index.html /var/www/
There are also three zle widgets: "fasd-complete", "fasd-complete-f",
"fasd-complete-d". You can bind them to keybindings you like:
bindkey '^X^A' fasd-complete # C-x C-a to do fasd-complete (files and directories)
bindkey '^X^F' fasd-complete-f # C-x C-f to do fasd-complete-f (only files)
bindkey '^X^D' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories)
# BACKENDS
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's native format. Below is a list of available
backends.
* spotlight: OSX spotlight, provides entries that are changed today or opened
within the past month
* recently-used: GTK's recently-used file (Usually available on Linux)
* current: Provides everything in $PWD (whereever you are executing `fasd`)
* viminfo: Vim's editing history, useful if you want to define an alias just
for editing things in vim
You can define your own backend by declaring a function by that name in your
`.fasdrc`. You can set default backend with `_FASD_BACKENDS` variable in our
`.fasdrc`.
# TWEAKS
Upon every execution, fasd will source "/etc/fasdrc" and "$HOME/.fasdrc" if
they are present. Below are some variables you can set:
$_FASD_DATA
Path to the fasd data file, default "$HOME/.fasd".
$_FASD_BLACKLIST
List of blacklisted strings. Commands matching them will not be processed.
Default is "--help".
$_FASD_SHIFT
List of all commands that needs to be shifted, defaults to "sudo busybox".
$_FASD_IGNORE
List of all commands that will be ignored, defaults to "fasd ls echo".
$_FASD_TRACK_PWD
Fasd defaults to track your "$PWD". Set this to 0 to disable this behavior.
$_FASD_AWK
Which awk to use. fasd can detect and use a compatible awk.
$_FASD_SINK
File to log all STDERR to, defaults to "/dev/null".
$_FASD_MAX
Max total score / weight, defaults to 2000.
$_FASD_SHELL
Which shell to execute. Some shells will run faster than others. fasd
runs faster with dash and ksh variants.
$_FASD_BACKENDS
Default backends.
$_FASD_RO
If set to any non-empty string, fasd will not add or delete entries from
database. You can set and export this variable from command line.
$_FASD_FUZZY
Level of "fuzziness" when doing fuzzy matching. More precisely, the number of
characters that can be skipped to generate a match. Set to empty or 0 to
disable fuzzy matching. Default value is 2.
$_FASD_VIMINFO
Path to .viminfo file for viminfo backend, defaults to "$HOME/.viminfo"
$_FASD_RECENTLY_USED_XBEL
Path to XDG recently-used.xbel file for recently-used backend, defaults to
"$HOME/.local/share/recently-used.xbel"
# DEBUGGING
Fasd is hosted on GitHub: https://github.com/clvv/fasd
If fasd does not work as expected, please file a bug report on GitHub describing
the unexpected behavior along with your OS version, shell version, awk version,
sed version, and a log file.
You can set `_FASD_SINK` in your `.fasdrc` to obtain a log.
_FASD_SINK="$HOME/.fasd.log"
# COPYING
Fasd is originally written based on code from z (https://github.com/rupa/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.

View File

@@ -9,17 +9,20 @@
# Load dependencies.
pmodload 'editor'
# Return if requirements are not found.
# If the command doesn't exist externally, we need to fall back to the bundled
# submodule.
if (( ! $+commands[fasd] )); then
return 1
source "${0:h}/external/fasd" || return 1
fi
#
# Initialization
#
cache_file="${0:h}/cache.zsh"
if [[ "${commands[fasd]}" -nt "$cache_file" || ! -s "$cache_file" ]]; then
cache_file="${TMPDIR:-/tmp}/prezto-fasd-cache.$UID.zsh"
if [[ "${commands[fasd]}" -nt "$cache_file" \
|| "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \
|| ! -s "$cache_file" ]]; then
# Set the base init arguments.
init_args=(zsh-hook)