Skip to content
Linwei edited this page Feb 20, 2019 · 35 revisions

fz.sh for better completion

fz is a bash/zsh plugin that seamlessly adds fuzzy search to tab completion of z.sh. z.lua can work with it for better completion result, just define a _z function and pass all the arguments to _zlua before sourcing fz.sh:

function _z() { _zlua "$@"; }
source /path/to/fz.sh

If you are using zsh with antigen, initialize them like this:

antigen boundle skywind3000/z.lua
antigen boundle changyuheng/fz

function _z() { _zlua "$@"; }

How to use z as cd ?

Paste this script in your .bashrc / .zshrc:

function j() {
    if [[ "$argv[1]" == "-"* ]]; then
        z "$@"
    else
        cd "$@" 2> /dev/null || z "$@"
    fi
}

When you are using j xxx it will first try cd xxx and then z xxx if cd failed.

How to import data from bash / zsh command history ?

Issue #46 asked for a script to import some history path from bash command history after a fresh install of z.lua and @antonalekseev provided two script below:

for bash:

fc -ln -10000| sed -e 's|^'[[:blank:]]' ||'|grep -o "^cd [~/].*"|sed -e "s|cd ||" -e "s|~|$HOME|" -e 's|\\ | |' -e "s|/$||"|sort|uniq|while read -r d; do test -d "$d" && echo "$d|1|0"; done >> ~/z.lua

for zsh:

fc -ln 0|grep -o "^cd [~/].*"|sed -e "s|cd ||" -e "s|~|$HOME|" -e 's|\\ | |' -e "s|/$||"|sort|uniq|while read -r d; do test -d "$d" && echo "$d|1|0"; done >> ~/z.lua

These two scripts above can be used for pre-warm .zlua database.

Define a new z -I

Define a new zii shell function to override z -I:

function zii() {
    local $dest="$(z -l "$@"|fzf --nth 2 --reverse --inline-info --tac +s -e --height 35%)"
    [ -n "$dest" ] && cd "$dest"
}

or just ignore the frecent order:

function zii() {
    local $dir="$(z -l -s "$@"|fzf ---reverse -e --height 35%)"
    [ -n "$dir" ] && cd "$dest"
}
Clone this wiki locally