Announcing pick

Calle Erlandsson and Mike Burns

pick is a fuzzy search tool for the command-line. It is used to select an entry from a list.

pick reads a list of choices on stdin and outputs the selected choice on stdout. Therefore it is easily used both in shell pipelines and subshells.

pick serves the same purpose as selecta but is faster and utilizes the alternate screen terminal feature to not leave choices on screen after the program finishes execution.

Here are some things we use this for:

Switch between git branches

This is especially helpful for those long-running projects with far too many local branches.

git checkout $(git branch | cut -c 3- | pick)

Demo

Change to an arbitrary subdirectory

cd $(find . -type d | pick)

Demo

Find and kill a process

kill $(ps -e | awk '{if(NR!=1) { print $4, $1 }}' | pick -do | tail -n +2)

Demo

Find and edit a file containing a specific word

vim $(ag -l WORD | pick)

Demo

Change Ruby version

chruby $(chruby | sed -n 's/.*-//p' | pick)

Demo

Run a Rake task

rake $(rake -T | cut -f2 -d' ' | pick)

Demo

Run a command from the history

$(history | cut -c8- | sort -u | pick)

Demo

Find a file to edit from within Vim

Pick can also easily be used from within Vim both using system() and !.

To make pick even easier to use from within Vim we have written the pick.vim Vim plugin.

To fuzzy-find a file to edit in Vim, install pick.vim and add this mapping to your .vimrc:

nnoremap <Leader>p :call PickFile()<CR>

Please see the pick.vim README for more examples of how to use it. For examples of how to call pick from within Vim, see the pick.vim source code.

Please note: pick requires a fully functional terminal to run and therefore cannot be run from within gvim or MacVim.

Demo

Installation

On OS X, you can install pick via Homebrew:

brew tap thoughtbot/formulae
brew install pick

If you’re running Arch Linux you can install it using the AUR package:

wget https://aur.archlinux.org/packages/pi/pick/pick.tar.gz
tar -xzf pick.tar.gz
cd pick
makepkg -s
pacman -U pick-VERSION-x86_64.pkg.tar.xz

You can also build pick from source:

wget https://github.com/thoughtbot/pick/releases/download/vVERSION/pick-VERSION.tar.gz
wget https://github.com/thoughtbot/pick/releases/download/vVERSION/pick-VERSION.tar.gz.asc
gpg --verify pick-VERSION.tar.gz.asc
tar -xzf pick-VERSION.tar.gz
cd pick-VERSION
./configure
make
make install

Don’t forget to check out the man page:

man pick

Contributing

Please report bugs via GitHub issues.

Pull requests are very welcome. Please, see the contributing instructions for more info on how to get started.