diff --git a/Brewfile b/Brewfile index 4f32f13..0ba0c99 100644 --- a/Brewfile +++ b/Brewfile @@ -53,7 +53,7 @@ brew "wget" brew "wireguard-tools" brew "yq" -# Terminal +# Terminal utils brew "bash" brew "btop" brew "cmatrix" @@ -117,6 +117,7 @@ cask "another-redis-desktop-manager" cask "caffeine" cask "db-browser-for-sqlite" cask "dotnet-sdk" +cask "font-jetbrains-mono" cask "gimp" cask "google-drive" cask "google-cloud-sdk" diff --git a/README.md b/README.md index 40c0cf0..783f489 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,25 @@ Tmux plugin manager is installed along with the following plugins: In order to have the plugins installed, reload the config with `prefix + I`. This can also fix problems with the plugins not working. +### Pane text search + +Search text across tmux panes using fzf. Selecting a match switches to the pane +and scrolls to the matching line. Requires `fzf` and `tmux` to be installed. + +- `prefix + f` — search across all panes in all sessions (1000 lines scrollback) +- `prefix + F` — search panes in the current window only (10000 lines scrollback) + +Within the search popup: + +| Key | Action | +| --- | --- | +| `ctrl-w` | Toggle searching window/session names | +| `ctrl-/` | Toggle preview (surrounding context) | +| `ctrl-d` / `ctrl-u` | Half page down/up | +| `ctrl-f` / `ctrl-b` | Full page down/up | +| `ctrl-g` / `G` | Jump to first/last result | +| `ctrl-y` | Copy selected line to clipboard | + ## FAQ - No linting in Vim and no lint warning or error symbols in the margin? diff --git a/dotfiles/.functions b/dotfiles/.functions index c0406ad..38c6598 100644 --- a/dotfiles/.functions +++ b/dotfiles/.functions @@ -1,2 +1,36 @@ # Git rebase function grbh() { git rebase -i HEAD~"$1"; } + +# Search text across tmux panes with fzf, then jump to the matching pane +# Usage: tmux-pane-search [window] - 'window' limits to current window with deeper scrollback +tmux-pane-search() { + local list_flag='-a' scrollback=1000 prompt="Search all panes> " + if [ "$1" = "window" ]; then + list_flag='' scrollback=10000 prompt="Search window panes> " + fi + local preview_cmd=' + target=$(echo {} | cut -f1) + line=$(echo {} | cut -f3 | sed "s/^ *\([0-9]*\).*/\1/") + { tmux capture-pane -t "$target" -p -S -'"$scrollback"' 2>/dev/null + tmux capture-pane -t "$target" -p -a 2>/dev/null + } | nl -ba -w4 -s" " | awk -v l="$line" "NR>=l-10 && NR<=l+10 { if(NR==l) printf \"\033[1;32m>> %s\033[0m\n\", \$0; else print \" \" \$0 }" + ' + local result + result=$( + tmux list-panes $list_flag -F '#{session_name}:#{window_index}.#{pane_index} #{session_name}|#{window_index}(#{window_name})|#{pane_index}' | + while IFS=' ' read -r target label; do + { tmux capture-pane -t "$target" -p -S -"$scrollback" 2>/dev/null + tmux capture-pane -t "$target" -p -a 2>/dev/null + } | nl -ba -w4 -s' ' | sed -n '/..*/{s/^/'"$target"' ['"$label"'] /;p;}' + done | + fzf --exact --ansi --no-sort --with-nth=2.. --nth=2.. --delimiter=' ' --prompt="$prompt" \ + --color='hl:underline:bold:green,hl+:underline:reverse:green' \ + --preview="$preview_cmd" --preview-window='right:50%:hidden' \ + --bind='ctrl-/:toggle-preview,ctrl-d:half-page-down,ctrl-u:half-page-up,ctrl-f:page-down,ctrl-b:page-up,ctrl-g:first,G:last,ctrl-y:execute-silent(echo -n {3..} | pbcopy),ctrl-w:transform-nth[test "$FZF_NTH" = "2.." && echo ".." || echo "2.."]+transform-prompt[test "$FZF_NTH" = ".." && echo "Search window names only> " || echo "'"$prompt"'"]' + ) || return + local target text + target=$(printf '%s' "$result" | cut -f1) + text=$(printf '%s' "$result" | cut -f3- | sed 's/^ *[0-9]* //') + tmux switch-client -t "$target" \; select-window -t "$target" \; select-pane -t "$target" + tmux copy-mode -t "$target" \; send-keys -t "$target" -X search-backward "$text" +} diff --git a/dotfiles/.tmux.conf b/dotfiles/.tmux.conf index 3319468..95e8774 100644 --- a/dotfiles/.tmux.conf +++ b/dotfiles/.tmux.conf @@ -143,6 +143,11 @@ set -g @vim_navigator_prefix_mapping_clear_screen "" bind-key -n C-S-Left swap-window -t -1\; select-window -t -1 bind-key -n C-S-Right swap-window -t +1\; select-window -t +1 +# Search text across all panes/windows/sessions with fzf +bind f display-popup -E -w 80% -h 80% 'bash -c "source ~/.functions && tmux-pane-search"' +# Search text across panes in the current window only (deeper scrollback) +bind F display-popup -E -w 80% -h 80% 'bash -c "source ~/.functions && tmux-pane-search window"' + # Tmux PLugin Manager config set -g @plugin 'tmux-plugins/tpm' # https://github.com/tmux-plugins/tpm set -g @plugin 'tmux-plugins/tmux-continuum' # https://github.com/tmux-plugins/tmux-continuum