Skip to content

Commit

Permalink
Update 2022-02-28_fzf-for-the-win.md
Browse files Browse the repository at this point in the history
fix typos
  • Loading branch information
csaez committed Feb 28, 2022
1 parent e5fa821 commit e6eebe3
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions content/posts/2022-02-28_fzf-for-the-win.md
@@ -1,7 +1,7 @@
---

title: FZF for the win!
description: If you spend any time in the terminal, then you probably will like fzf.
description: If you spend time in the terminal, then you probably will like fzf.
date: 2022-02-28
categories: [Tutorials]
tags: [thoughts]
Expand All @@ -13,54 +13,57 @@ toc: false

Hi there!

It has been a long time sinse the last time I posted something here.

A lot has happened: for starters I moved to London, got married, worked at
DNEG for a while and then switched to my current job in the research department (real time) at Foundry.
My day to day job is also a bit different, nowadays I find myself working on c++ projects developing
prototypes and/or experimental extensions to Foundry products.
It has been a long time since the last time I posted something here.

A lot has happened: for starters I moved to London, got married, worked at DNEG for a while and
then switched to my current job in the research department (real time) at Foundry. My day to day
job is also a bit different, nowadays I find myself working on c++ projects developing prototypes
and/or experimental extensions to Foundry products.

Now, back to the topic... What's that `fzf` thingy I wanted to share about?

Well, I work a lot on the terminal (Linux) and during the years I have treassured quite a collection
Well, I work a lot on the terminal (Linux) and during the years I have treasured quite a collection
of useful little tools to make my workflow nicer, one of them is FZF!

https://github.com/junegunn/fzf

`FZF` is a command line fuzzy finder written in go, very handy to find files and what not.. but the coolest
part is how easy it is to integrate it into all sort of workflows, just pipe the content to be filtered
into it!
`FZF` is an interactive Unix filter for command-line written in go, very handy to find files and
what not... The coolest part is how easy it is to integrate all sort of workflows into it, just
pipe the content to be filtered into `fzf` and you are ready to go!

## Executable launcher

A very useful thing I do a lot with `fzf` is to run a particular executable of the project I'm
working on (yes, there might be many executables on a given cmake project).
working on (yes, there might be many executables on a given `cmake` project).

Here a breakdown of how I have this setup:
Here's a breakdown of how I have this setup:

### Finding executables

First we need to find all executables in the project, for that I do a recursive find starting on the
current directory (usually the root of the project) + a few greps further filtering things.
First we need to find all executables in the project, for that I do a recursive find starting on
the current directory (usually the root of the project) + a few greps further filtering things.

I usually create a `build` folder within the project containing the generated project out of cmake
where things get built, so this should cover that use case.
I usually create a `build` folder within the project containing the generated project out of
`cmake` where things get built, so this should cover that use case.

i.e. `~/bin/fx`

```bash
#!/bin/env bash
find . -type f -executable -exec file {} \; | grep -wE executable | grep -Po ".*(?=:)"
```

### Selecting the executable in `fzf`

Now we can simply pipe the results into `fzf` in order to filter the results and launch the executable!
Now we can simply pipe the results into `fzf` in order to filter the results and launch the
executable!

In my case I change directory to the executable directory and run it from there,
I do this because I work on projects that need to run on multiple platforms and there's a bit of
cross platform `rpath` "fun" involved leading to this decision :see_no_evil:.
In my case I change directory to the executable directory and run it from there, I do this because
I work on projects that need to run on multiple platforms and there's a bit of cross platform
`rpath` "fun" involved leading to this decision :see_no_evil:.

i.e. `~/bin/xx`

```bash
#!/bin/env bash
result=$( fx | fzf )
Expand All @@ -71,7 +74,8 @@ pushd $(dirname $result) > /dev/null
./$(basename $result)
```

We are done! type `xx` on the terminal and enjoy your fancy selector to launch executables within your project!
We are done! Simply type `xx` on your terminal and enjoy your fancy selector to launch executables
within your project!

### Wait, what about debugging?

Expand All @@ -90,7 +94,9 @@ gdb ./$(basename $result)

### What about doing this from the IDE/code-editor?

I use neovim as my code editor, one of the cool things is the tight integration with the terminal allowing to reuse some of the little scripts we have been talking about. Here my setup (using the `fzf` plugin for the case of debugging)
I use `neovim` as my code editor, one of the cool things is the tight integration with the terminal
allowing to reuse some of the little scripts we have been talking about. Here's my setup (using the
`fzf` plugin for the case of debugging).

```lua
local noremap = { noremap=true, silent=true }
Expand All @@ -108,9 +114,10 @@ Whaaaaat!? Exactly! :exploding_head:

---

Regardless of this particular setup, I think the beauty of it is on the simple interface, allowing to quickly
create all sorts of throw away scripts adding a fancy selector to all sort of things (i.e. want to pimp up your
git workflow? take a look at how [forgit](https://github.com/wfxr/forgit) uses `fzf` for inspiration).
Regardless of this particular setup, I think the beauty of it is on the simple interface, allowing
to quickly create all sorts of throw away scripts adding a fancy selector to all sort of things
(i.e. Do you want to pimp up your git workflow? Take a look at how
[forgit](https://github.com/wfxr/forgit) uses `fzf` for inspiration).


Cheers!

0 comments on commit e6eebe3

Please sign in to comment.