<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<title>Basetta&apos;s Website · fzf</title>
<id>https://basetta.bz/tags/fzf/atom.xml</id>
<link href="https://basetta.bz/tags/fzf/atom.xml" rel="self" type="application/atom+xml"/>
<link href="https://basetta.bz/"/>
<updated>2026-11-16T00:00:00.000Z</updated>
<author><name>Patrick Martini</name></author>
<entry>
<title>Moving from tmux to Rex: My Folder Picker Was Not Negotiable</title>
<id>https://basetta.bz/blog/rex-project-picker/</id>
<link href="https://basetta.bz/blog/rex-project-picker/"/>
<published>2026-11-16T00:00:00.000Z</published>
<updated>2026-11-16T00:00:00.000Z</updated>
<summary>How I moved a tmux project and Git-worktree picker to Rex, with fzf in a floating layer and automatic session switching.</summary>
<content type="html" xml:base="https://basetta.bz/blog/rex-project-picker/">&lt;p&gt;I am moving from tmux to &lt;a href=&quot;https://www.superlogical.com/rex/&quot; class=&quot;link-external&quot; rel=&quot;noopener&quot;&gt;Rex&lt;/a&gt;. My fingers were not consulted.&lt;/p&gt;
&lt;p&gt;They still press &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;A&lt;/kbd&gt;, then &lt;kbd&gt;F&lt;/kbd&gt;, and expect a list of project folders. Apparently, terminal migration requires their approval.&lt;/p&gt;
&lt;p&gt;In tmux, that sequence opened an &lt;code&gt;fzf&lt;/code&gt; popup. I picked a project or Git worktree. The script reused its session or created a new one, then switched to it. I was so pleased with how it turned out that I &lt;a href=&quot;/blog/tmux-sessionizer/&quot; class=&quot;link-internal&quot;&gt;wrote about it&lt;/a&gt;. Shortly afterwards, I switched terminal multiplexers.&lt;/p&gt;
&lt;p&gt;Nothing fancy. Just one of those small conveniences that becomes a requirement the moment it disappears.&lt;/p&gt;
&lt;p&gt;I wanted the same thing in Rex:&lt;/p&gt;
&lt;pre data-language=&quot;text&quot;&gt;&lt;code&gt;Ctrl+A, F → choose folder → open its Rex session&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Rex already has a session picker under &lt;code&gt;Cmd+K&lt;/code&gt;. Great. Except it lists &lt;strong&gt;sessions&lt;/strong&gt;, and I wanted &lt;strong&gt;folders&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Those are related, but not interchangeable. A repository does not become a session just because I look at it with sufficient optimism.&lt;/p&gt;
&lt;p&gt;So I built a project picker. The finished version is pleasantly small. Getting there involved more terminal configuration than choosing a folder should reasonably require.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/blog/rex-project-picker/folder-picker.png&quot; class=&quot;link-internal&quot;&gt;&lt;img src=&quot;/blog/rex-project-picker/folder-picker.png&quot; alt=&quot;A floating fzf popup in Rex filters project folders and Git worktrees above the current terminal.&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The finished picker. All I wanted was a folder list. The worktrees came too.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Open the picker:&lt;/strong&gt; press &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;A&lt;/kbd&gt;, release both keys, then press &lt;kbd&gt;F&lt;/kbd&gt; (no Shift).&lt;/p&gt;
&lt;p&gt;Type to filter folders. Use &lt;kbd&gt;↑&lt;/kbd&gt; and &lt;kbd&gt;↓&lt;/kbd&gt; to choose one. Press &lt;kbd&gt;Enter&lt;/kbd&gt; to open its session, or &lt;kbd&gt;Esc&lt;/kbd&gt; to cancel.&lt;/p&gt;
&lt;h2 id=&quot;get-rex&quot;&gt;Get Rex&lt;/h2&gt;
&lt;p&gt;Start with the &lt;a href=&quot;https://www.superlogical.com/rex/&quot; class=&quot;link-external&quot; rel=&quot;noopener&quot;&gt;official Rex website&lt;/a&gt; for access and downloads. The &lt;a href=&quot;https://www.superlogical.com/rex/docs/installation&quot; class=&quot;link-external&quot; rel=&quot;noopener&quot;&gt;installation guide&lt;/a&gt; covers platform availability and setup. Rex is currently in beta; this setup uses the macOS app.&lt;/p&gt;
&lt;h2 id=&quot;four-requirements-surely-this-will-be-quick&quot;&gt;Four requirements. Surely this will be quick.&lt;/h2&gt;
&lt;p&gt;The picker must do four things.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;List folders below my project roots.&lt;/li&gt;
&lt;li&gt;Include registered Git worktrees.&lt;/li&gt;
&lt;li&gt;Open as a popup over the current terminal.&lt;/li&gt;
&lt;li&gt;Create or reuse a Rex session, then show it automatically.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;My project roots are:&lt;/p&gt;
&lt;pre data-language=&quot;text&quot;&gt;&lt;code&gt;~/projects
~/Sandbox/work/repos
~/Documents/Zk&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The specific roots are personal. The pattern is portable. The number of unfinished projects is not relevant to this tutorial.&lt;/p&gt;
&lt;h2 id=&quot;why-this-is-different-from-tmux&quot;&gt;Why this is different from tmux&lt;/h2&gt;
&lt;p&gt;A tmux sessionizer can inspect a session’s current path and switch its own client directly. Rex has a different model.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;session&lt;/strong&gt; is a workspace with one or more windows and blocks.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;window&lt;/strong&gt; is a tab.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;block&lt;/strong&gt; is a terminal pane.&lt;/li&gt;
&lt;li&gt;Rex server commands create and inspect sessions.&lt;/li&gt;
&lt;li&gt;Rex.app client actions control the visible application interface.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That distinction matters for the final step. Creating a session is a server operation. Making Rex.app display it is a client operation.&lt;/p&gt;
&lt;p&gt;I had asked for a folder list. I was now learning a client-server architecture. This is how a small configuration task becomes an afternoon.&lt;/p&gt;
&lt;h2 id=&quot;list-folders-and-worktrees&quot;&gt;List folders and worktrees&lt;/h2&gt;
&lt;p&gt;The shell script starts by scanning only the immediate children of each root. For every repository, it also asks Git for registered worktrees.&lt;/p&gt;
&lt;pre data-language=&quot;sh&quot;&gt;&lt;code&gt;project_directories() {
    local root directory record


    for root in &quot;$HOME/projects&quot; &quot;$HOME/Sandbox/work/repos&quot; &quot;$HOME/Documents/Zk&quot;; do
        [[ -d &quot;$root&quot; ]] || continue


        while IFS= read -r -d &apos;&apos; directory; do
            if [[ &quot;$directory&quot; == *__worktrees ]]; then
                find &quot;$directory&quot; -mindepth 1 -maxdepth 1 -type d -print0
                continue
            fi


            printf &apos;%s\0&apos; &quot;$directory&quot;


            while IFS= read -r -d &apos;&apos; record; do
                [[ &quot;$record&quot; == &apos;worktree &apos;* ]] &amp;amp;&amp;amp; printf &apos;%s\0&apos; &quot;${record#worktree }&quot;
            done &amp;lt; &amp;lt;(git -C &quot;$directory&quot; worktree list --porcelain -z 2&amp;gt;/dev/null || true)
        done &amp;lt; &amp;lt;(find &quot;$root&quot; -mindepth 1 -maxdepth 1 -type d -print0)
    done
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The discovery step uses NUL-delimited paths, so spaces do not split a folder name into several arguments. The display rows later use tabs and newlines, so names containing those characters remain a limitation.&lt;/p&gt;
&lt;p&gt;Some tools store worktrees in a sibling directory ending in &lt;code&gt;__worktrees&lt;/code&gt;. That directory is a container, not a project. The script lists its children instead.&lt;/p&gt;
&lt;p&gt;The resulting paths are canonicalized and deduplicated before they are displayed:&lt;/p&gt;
&lt;pre data-language=&quot;sh&quot;&gt;&lt;code&gt;folder_rows() {
    while IFS= read -r directory; do
        printf &apos;%s\t%s\n&apos; &quot;${directory##*/}&quot; &quot;$directory&quot;
    done &amp;lt; &amp;lt;(
        while IFS= read -r -d &apos;&apos; directory; do
            canonical_path &quot;$directory&quot; || true
        done &amp;lt; &amp;lt;(project_directories) | LC_ALL=C sort -u
    )
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each row contains a display name and its full path. &lt;code&gt;fzf&lt;/code&gt; displays both fields and returns the exact selected path.&lt;/p&gt;
&lt;h2 id=&quot;run-fzf-in-a-rex-floating-layer&quot;&gt;Run fzf in a Rex floating layer&lt;/h2&gt;
&lt;p&gt;The early attempts included a split and a separate tab. Neither delivered the popup interaction I wanted.&lt;/p&gt;
&lt;p&gt;We also confused tests inside an agent’s command runner with tests inside an interactive terminal. Those are not the same environment. A failed &lt;code&gt;fzf&lt;/code&gt; test there does not prove that Rex splits lack a terminal.&lt;/p&gt;
&lt;p&gt;The least useful experiment sent test text into my active pane. That demonstrated text delivery. It did not demonstrate good judgment.&lt;/p&gt;
&lt;p&gt;The right primitive was already in Rex: a &lt;strong&gt;floating layer&lt;/strong&gt;. It creates a terminal block above the current window. In other words, a popup. Exactly the thing I had asked for before the sightseeing tour.&lt;/p&gt;
&lt;p&gt;The key binding is defined in &lt;code&gt;~/.config/rex/init.lua&lt;/code&gt;:&lt;/p&gt;
&lt;pre data-language=&quot;lua&quot;&gt;&lt;code&gt;rex.action{
  name = &quot;project_picker&quot;,
  title = &quot;Open Project Picker…&quot;,
  run = function(ctx, args)
    local result, err = rex.session.new_layer{
      session_id = ctx.session_id,
      bounds = { 0.12, 0.15, 0.76, 0.70 },
      focus = true,
      layout = rex.layout.block{
        flavor = &quot;com.superlogical.terminal.shell&quot;,
        options = {
          command = {
            &quot;bash&quot;,
            os.getenv(&quot;HOME&quot;) .. &quot;/.config/scripts/rex-project-picker&quot;,
          },
          shell = &quot;none&quot;,
        },
      },
    }
    if result == nil then error(err, 0) end
  end,
}


rex.bind(&quot;ctrl+a&amp;gt;f&quot;, &quot;project_picker&quot;)&lt;/code&gt;&lt;span class=&quot;sage-lang&quot; aria-hidden=&quot;true&quot;&gt;Lua&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The four values in &lt;code&gt;bounds&lt;/code&gt; are fractions of the current window:&lt;/p&gt;
&lt;pre data-language=&quot;text&quot;&gt;&lt;code&gt;x, y, width, height&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This example places the picker with a margin around it. Rex focuses the new layer, so keyboard input goes to &lt;code&gt;fzf&lt;/code&gt;. After selection, the script handles the session switch and exits. Rex then closes the popup. Cancelling exits without creating a session.&lt;/p&gt;
&lt;p&gt;I kept &lt;code&gt;Ctrl+A, F&lt;/code&gt; because it preserves my tmux muscle memory. In my configuration, it leaves Rex’s &lt;code&gt;Cmd+K&lt;/code&gt; session picker unchanged. My fingers accepted this compromise.&lt;/p&gt;
&lt;h2 id=&quot;fzf-is-installed-the-popup-would-like-proof&quot;&gt;fzf is installed. The popup would like proof.&lt;/h2&gt;
&lt;p&gt;Rex starts the popup terminal without my interactive shell startup files. This is deliberate and prevents unrelated shell configuration from changing command execution.&lt;/p&gt;
&lt;p&gt;It also means the popup may not have Homebrew’s &lt;code&gt;bin&lt;/code&gt; directory in &lt;code&gt;PATH&lt;/code&gt;. The first result was therefore not a folder list:&lt;/p&gt;
&lt;pre data-language=&quot;text&quot;&gt;&lt;code&gt;fzf: command not found&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A minimalist interface, but missing a few features.&lt;/p&gt;
&lt;p&gt;On my Mac, &lt;code&gt;fzf&lt;/code&gt; is installed here:&lt;/p&gt;
&lt;pre data-language=&quot;text&quot;&gt;&lt;code&gt;/opt/homebrew/bin/fzf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The script uses that explicit path:&lt;/p&gt;
&lt;pre data-language=&quot;sh&quot;&gt;&lt;code&gt;export PATH=&quot;/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:$PATH&quot;
fzf_bin=&quot;/opt/homebrew/bin/fzf&quot;


[[ -x &quot;$fzf_bin&quot; ]] || {
    printf &apos;fzf was not found at %s\n&apos; &quot;$fzf_bin&quot; &amp;gt;&amp;amp;2
    exit 1
}


choice=$(folder_rows | &quot;$fzf_bin&quot; \
    --delimiter=$&apos;\t&apos; --with-nth=1,2 \
    --layout=reverse --border --no-preview \
    --prompt=&apos;Project &amp;gt; &apos; \
    --header=&apos;Enter: create Rex session · Esc: cancel&apos;) || exit 0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If your &lt;code&gt;fzf&lt;/code&gt; executable is elsewhere, change &lt;code&gt;fzf_bin&lt;/code&gt; to its absolute path. Adding a directory to &lt;code&gt;PATH&lt;/code&gt; will not change this explicit executable path.&lt;/p&gt;
&lt;h2 id=&quot;create-a-stable-session-name&quot;&gt;Create a stable session name&lt;/h2&gt;
&lt;p&gt;Two unrelated projects can share a directory name. Reusing a session only by basename would open the wrong project in that case.&lt;/p&gt;
&lt;p&gt;I derive the Rex session label from the basename plus a checksum of the full canonical path:&lt;/p&gt;
&lt;pre data-language=&quot;sh&quot;&gt;&lt;code&gt;base=$(basename -- &quot;$selected&quot; | tr &apos;.:&apos; &apos;__&apos;)
checksum=$(printf &apos;%s&apos; &quot;$selected&quot; | cksum | awk &apos;{print $1}&apos;)
label=&quot;${base}-${checksum}&quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result looks like this:&lt;/p&gt;
&lt;pre data-language=&quot;text&quot;&gt;&lt;code&gt;api-243857219&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Not beautiful. Neither is opening the wrong &lt;code&gt;api&lt;/code&gt; repository.&lt;/p&gt;
&lt;p&gt;The label stays stable for one path and distinguishes typical same-basename projects. A checksum is not a guarantee of uniqueness, though. This is a lightweight naming scheme, not an identity database. Renaming the session manually also prevents lookup by that generated label.&lt;/p&gt;
&lt;p&gt;The script lists Rex sessions, reuses a matching label, or creates a session with the selected directory as its working directory:&lt;/p&gt;
&lt;pre data-language=&quot;sh&quot;&gt;&lt;code&gt;created=$(&quot;$rex_bin&quot; new &quot;$label&quot; -c &quot;$selected&quot; --json)
session_id=$(printf &apos;%s&apos; &quot;$created&quot; |
    python3 -c &apos;import json,sys; print(json.load(sys.stdin)[&quot;session_id&quot;])&apos;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;rex new -c&lt;/code&gt; creates the session and starts its first terminal in the selected folder.&lt;/p&gt;
&lt;h2 id=&quot;switch-rexapp-automatically&quot;&gt;Switch Rex.app automatically&lt;/h2&gt;
&lt;p&gt;Creating a session does not automatically make Rex.app show it. That is a deliberate boundary in Rex.&lt;/p&gt;
&lt;p&gt;The session existed. I just could not see it yet. Technically successful; emotionally incomplete.&lt;/p&gt;
&lt;p&gt;Rex server commands can manage sessions. Client actions can control the visible app interface, such as selecting a session. Rex protects client actions behind &lt;strong&gt;Remote Control&lt;/strong&gt;, which is disabled by default.&lt;/p&gt;
&lt;p&gt;To enable automatic switching:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open &lt;strong&gt;Rex Settings&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Open &lt;strong&gt;Rex Server&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enable &lt;strong&gt;Remote Control&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Then the script finds the connected Rex.app client and asks it to select the new or existing session:&lt;/p&gt;
&lt;pre data-language=&quot;sh&quot;&gt;&lt;code&gt;client_id=$(&quot;$rex_bin&quot; client ls -s &quot;$REX_SESSION&quot; --json | python3 -c &quot;
import json, sys
for client in json.load(sys.stdin).get(&apos;clients&apos;, []):
    if client.get(&apos;info&apos;, {}).get(&apos;kind&apos;) == &apos;app&apos;:
        print(client[&apos;client_id&apos;])
        break
&quot;)


exec &quot;$rex_bin&quot; -C &quot;$client_id&quot; do session.select &quot;session_id=$session_id&quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This permission does &lt;strong&gt;not&lt;/strong&gt; grant the picker access to folders. The script already runs with the permissions of the user who started it.&lt;/p&gt;
&lt;p&gt;Remote Control permits client actions such as selecting a session. It is broader than a permission for this picker alone, so enable it only if you want scripts to control Rex.app.&lt;/p&gt;
&lt;p&gt;The example chooses the first attached app client. That suits my single-app setup. With multiple app clients, pass the intended client explicitly.&lt;/p&gt;
&lt;h2 id=&quot;the-final-flow&quot;&gt;The final flow&lt;/h2&gt;
&lt;p&gt;The complete interaction is now short:&lt;/p&gt;
&lt;pre data-language=&quot;text&quot;&gt;&lt;code&gt;Ctrl+A, F
  → floating fzf folder picker
  → select a project or worktree
  → create or reuse its Rex session
  → Rex.app opens that session&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Cmd+K&lt;/code&gt; remains useful for navigating sessions that already exist. The custom binding solves a different problem: starting from a project folder rather than from a session name.&lt;/p&gt;
&lt;p&gt;Use the built-in picker for sessions. Use the custom popup for projects.&lt;/p&gt;
&lt;p&gt;I moved from tmux to Rex. My folder picker moved with me. My fingers still believe nothing has changed.&lt;/p&gt;
&lt;p&gt;For once, everybody is happy with the migration.&lt;/p&gt;
</content>
<category term="tech"/>
<category term="rex"/>
<category term="fzf"/>
</entry>
</feed>