Skip to content
John Hawthorn edited this page Jul 24, 2016 · 13 revisions

fzy

Examples

Here are some scripts people have built using fzy. Please feel free to add your own.

Search for a file and open it in vim

FILE=$(ag -l -g '' | fzy) && vim "$FILE"

cd into a directory

This has to be a shell function (not script file) in order to use cd

fcd(){
  cd "$(find -type d | fzy)"
}

Search for a gem and open a new tmux window in its directory

#!/bin/sh
GEM=$(bundle list | cut -f 4 -d' ' | fzy)
DESTINATION=$(bundle show $GEM)
tmux new-window -c "$DESTINATION" -n "$GEM"

Select some text to add to the clipboard

alias fzyank='fzy | xclip'

Zsh: Insert fuzzy-found paths directly into the shell command line

Based on snippet from selecta's EXAMPLES.md

function insert-fzy-path-in-command-line() {
        local selected_path
        echo # Run fzy underneath the current prompt
        selected_path=$(ag . -l -g '' | fzy) || return
        LBUFFER="$LBUFFER${(q)selected_path} " # ${(q)VAR} shell-escapes the string
        zle reset-prompt
}
zle -N insert-fzy-path-in-command-line

unsetopt flowcontrol # By default, ^S freezes terminal output, only needed if keybinding is ^S
bindkey "^S" "insert-fzy-path-in-command-line"

Clone this wiki locally