> fzf

Get fuzzy

Why?

  • Ergonomic way to get input in shell commands
    • -> improves your efficiency with a Terminal
  • Generic tool
  • Easy to extend

What is fuzzy finding?

src/client/dummy.js                                            scdjs

src/server/makes-sense.css                                            sserversense

What does fzf do?

One thing. It fuzzy finds.

Actually, it finds files by default.

Default features:

  • fzf
  • kill <TAB>
  • cat <CTRL-T>
  • vim <CTRL-T>
  • anything <CTRL-T>

Use cases examples

  • Git: fuzzy find commits
  • Git: start interactive rebase on fuzzy found commit
  • Docker: start a bash on a container
  • Docker: restart a container
  • Vim (with plugin): open a file
  • Open a recent file (using fasd)
  • ...
  • Many more: https://github.com/junegunn/fzf/wiki/examples

Create custom commands

How to do it:

  • Give proper input:
    • one line = one element
  • Format output properly
    • needs to match your program's needs
d3f2acf4 Fix typo
faad34df lol
f4adcd69 Fix tests
bcad0e69 wip
d3f2acf4 Fix typo
d3f2acf4

git log --pretty=oneline

fzf

git show

post-treatment

pre-treatment

Git commands

Fuzzy find commits:

git log --pretty=oneline
  | fzf -n 2..
  | awk '{print $1}'
  | xargs git show

Git commands

Fuzzy interactive rebase:

git log --pretty=oneline
  | fzf -n 2..
  | awk '{print $1\"^\"}'
  | xargs git rebase -i

Docker commands

Launch bash on a docker container

dbash() {
  CONTAINER=$(docker ps | awk '{print $1, $2}' 
                        | awk 'NR > 1' 
                        | fzf -n 2..
                        | awk '{print $1}')

  # Cleaner and more generic solution:
  # docker ps --format '{{.ID}} {{.Names}}' 
  #  | fzf -n 2..
  #  | awk '{print $1}'

  if [ ! -z "$CONTAINER" ]
  then
    docker exec -it $CONTAINER bash
  fi
}

Questions?

Made with Slides.com