kovidgoyal / kitty-fosshack2024

Projects for FOSSHack 2024
GNU General Public License v3.0
9 stars 5 forks source link

FZF like navigation for tabs #1

Open kovidgoyal opened 2 months ago

kovidgoyal commented 2 months ago

Write a kitten that allows switching between tabs in kitty with a few keystrokes like FZF.

kitty issue: https://github.com/kovidgoyal/kitty/issues/1303

Notes for implementation:

There is an existing select_tab action that allows selecting tabs based on their titles. This is works well when there are <= 20 tabs. But for more tabs or for people that prefer a fzf like interface it would be good to create a select_tab_fzf action. The implementation would be a kitten written in Go. See the existing themes kitten for an example of selecting from a ist of names using a fzf like interface.

The output from the kitten would be handled similarly to how the existing select_tab action works.

Mostly Go code with a little bit of python glue code.

jamesb93 commented 1 month ago

I didn't necessarily follow the guidance here but managed to hack something together using the remote scripts.

#!/bin/bash

# Get all tabs, including their ids and focused status
tab_info=$(kitty @ ls | /opt/homebrew/bin/jq -r '.[].tabs[] | "\(.id)|\(.is_focused)|\(.title)"')

# Filter out the focused tab and prepare the list for fzf
# Format: "last_directory (id: tab_id) | full_path | tab_id"
tab_titles=$(echo "$tab_info" | awk -F'|' '$2 == "false" {
    split($3, path, "/")
    last_dir = path[length(path)]
    if (last_dir == "") last_dir = "/"
    print last_dir " (id: " $1 ") | " $3 " | " $1
}')

# Use fzf to fuzzy search the tab titles
selected=$(echo "$tab_titles" | /opt/homebrew/bin/fzf --prompt="Select tab: " \
    --height=60% \
    --layout=reverse \
    --border=rounded \
    --margin=10%,10% \
    --padding=1 \
    --with-nth=1 \
    --delimiter=' | ' \
    --preview='echo {2}' \
    --preview-window=up:1 \
    --color='bg:237,bg+:235,border:240')

# If a tab was selected, focus on that tab using its ID
if [ -n "$selected" ]; then
    tab_id=$(echo "$selected" | awk -F' \\| ' '{print $3}')
    kitty @ focus-tab --match id:"$tab_id"
else
    echo "No tab selected or operation cancelled."
fi

It might be a point of departure for a more fully fledged kitten.

VarshaVasanth240 commented 1 month ago

Hlo @kovidgoyal Our team would like to work upon this issue under FOSShack 2024 please assign this issue to us

kovidgoyal commented 1 month ago

done