Skip to content

Instantly share code, notes, and snippets.

@bdowling
Last active February 8, 2023 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdowling/c42cb00397eff0d8f8ed625146ead676 to your computer and use it in GitHub Desktop.
Save bdowling/c42cb00397eff0d8f8ed625146ead676 to your computer and use it in GitHub Desktop.
#!/bin/sh
# This script helps you find something if you have tons of open panes...
#
#
# $0 '[a]bcdef'
notthispane=$TMUX_PANE
if [ "$1" = "-a" ]; then
notthispane=''
shift
fi
if [ -z "$*" ]; then
cat <<EOT
Usage:
$0 <options> [arguments to grep to find something in any open tmux pane]"
Options:
-a include the current pane (not included by default because you could just search backwards...)
e.g.
$0 -Pi '[f]oo.*bar\d+'
Tip: The use of brackets around a single char avoids finding your own attempt at finding something,
at until you start showing the found history in this pane.
EOT
exit 1
fi
for pane in $( tmux list-panes -a|grep -Po '%\d+' ); do
if [ -n "$notthispane" -a "$notthispane" = "$pane" ]; then
continue
fi
if tmux capture-pane -S - -p -t $pane |grep "$@"; then
echo ""
echo "------ Pane: $(tmux list-panes -a |grep -w $pane) ------"
fi
done
@bdowling
Copy link
Author

bdowling commented Feb 8, 2023

If you find yourself with a lot of tmux window panes open, and you can't remember where you ran a particular command or had some output you needed to capture, you can use this to find it. Hope you find it useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment