Skip to content

Instantly share code, notes, and snippets.

Created August 28, 2019 21:54
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thugcee/12411b2d10b0367f7a353a0a4cae312d to your computer and use it in GitHub Desktop.
My versions of v, vd and z functions using fasd and fzf
if which fasd >/dev/null; then
# install fasd hooks and basic aliases in the shell
eval "$(fasd --init auto)"
# if there is fzf available use it to search fasd results
if which fzf >/dev/null; then
alias v >/dev/null && unalias v
alias vd >/dev/null && unalias vd
alias z >/dev/null && unalias z
# edit given file or search in recently used files
function v {
local file
# if arg1 is a path to existing file then simply open it in the editor
test -e "$1" && $EDITOR "$@" && return
# else use fasd and fzf to search for recent files
file="$(fasd -Rfl "$*" | fzf -1 -0 --no-sort +m)" && $EDITOR "${file}" || $EDITOR "$@"
# cd into the directory containing a recently used file
function vd {
local dir
local file
file="$(fasd -Rfl "$*" | fzf -1 -0 --no-sort +m)" && dir=$(dirname "$file") && cd "$dir"
# cd into given dir or search in recently used dirs
function z {
[ $# -eq 1 ] && test -d "$1" && cd "$1" && return
local dir
dir="$(fasd -Rdl "$*" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment