tmux-copycat icon indicating copy to clipboard operation
tmux-copycat copied to clipboard

Discussion: ideas for stored searches

Open bruno- opened this issue 9 years ago • 18 comments

As described in the defining new stored searches doc, this plugin enables you to define your own, custom searches.

Let's tap into the community ideas and see what others came up with or are missing.

Use this thread to:

  • share what "custom" searches you use (and in which situations)
  • request for something you'd like to search but can't (or don't know how)

Interesting searches will be added to Useful searches section.

bruno- avatar Nov 21 '14 15:11 bruno-

Get commit hash in git log set -g @copycat_search_WHATEVER '^commit[[:space:]]*'

ctjhoa avatar Nov 22 '14 13:11 ctjhoa

Amazon jobflow ID set -g @copycat_search_C-j 'j-[[:alnum:]]*'

justmytwospence avatar Jan 28 '15 07:01 justmytwospence

I have a stored search for quoted text: set -g @copycat_search_C-q '\"[^\"]*\"'

Frequently filenames, error messages and other important info are quoted in a program's output.

However, I'm unable to match single quotes, even escaping doesn't work. Is this a bug or am I doing it wrong?

AnAppAMonth avatar Mar 19 '15 15:03 AnAppAMonth

@AnAppAMonth, interesting idea. Thanks for the submission.

I think a single quote searches could have a bug! I also just tried it and got an error. Please open an issue with the description of what you tried. A pull request for this is also very welcome.

bruno- avatar Mar 20 '15 00:03 bruno-

@ctjhoa improved the regex to match SHA1 hashes in every output format. See #73

jbnicolai avatar May 27 '15 13:05 jbnicolai

Pull request for email address search over at #78

davidjb avatar Jun 18 '15 05:06 davidjb

Get the last entry of a line if it is standard filename.

set -g @copycat_search_C-l '[a-zA-Z0-9_-./]+$'

This works for filenames without any path (basename - as for example for ls -l) and for git status if you are not in the root of the repo.

konstantinstadler avatar Jun 14 '16 07:06 konstantinstadler

Often people have the pwd on their bash prompt like so (fish truncates all but the last paths to one letter):

endrebak@havpryd ~/c/c/workflows>

I'd like some way of avoiding those in the file search, but dunno if that is possible.

endrebak avatar Jun 21 '17 07:06 endrebak

Can we have these searches in a way similar to vim-text-objects? That would make it much easier to remember and increase the key-combination space available to reduce clashes.

alphaCTzo7G avatar May 26 '18 16:05 alphaCTzo7G

Match kubernetes objects e.g. "asdf-gk8nr" or "asdf-foo-7bdcf85cf5-97x64" set -g @copycat_search_C-k '[A-Za-z0-9-]+-[a-f0-9]{10}-[a-z0-9]{5}|[A-Za-z0-9-]+-[a-z0-9]{5}'

diepfote avatar Nov 04 '19 11:11 diepfote

Match 32 bit or 64 bit addresses e.g. "0xffffd53a", "0xffffd53affffd53a", "ffffd53a" or "ffffd53affffd53a" set -g @copycat_search_a '0x[A-Fa-f0-9]{8}|0x[A-Fa-f0-9]{16}|[A-Fa-f0-9]{8}|[A-Fa-f0-9]{16}' # 32 or 64 bit adresses

diepfote avatar Nov 10 '19 15:11 diepfote

The example here

set -g @copycat_search_G '\b[0-9a-f]{5,40}\b'

should be

set -g @copycat_search_G '\b[0-9a-f]{5}|[0-9a-f]{40}\b'

nilesh-akhade avatar Dec 02 '22 06:12 nilesh-akhade

The search goes from bottom to top. Is there any way to search only the last command output (preferably from top to bottom)?

nilesh-akhade avatar Dec 02 '22 06:12 nilesh-akhade

~~based on a quick search no. you would need to re-write or duplicate and change https://github.com/tmux-plugins/tmux-copycat/blob/master/scripts/copycat_generate_results.sh#L20~~

--

I guess you could use this somehow https://github.com/tmux-plugins/tmux-copycat/blob/master/scripts/copycat_jump.sh#L231 Use get_number_of_results to set initial jump position.

diepfote avatar Dec 02 '22 07:12 diepfote

The "last entry" file search didn't work for me. The order of the regex was causing an issue:

set -g @copycat_search_C-f '[a-zA-Z0-9_./-]+$'

For the future reader, here's the issue reporting the single quote breakage.

I was not able to get the quoting snippet to work:

set -g @copycat_search_C-q "\"[^\"]*\""

It always selected the quotes incorrectly for me (if anyone knows why, I'd love to hear it):

image

iloveitaly avatar May 20 '23 23:05 iloveitaly

@iloveitaly looks like you are on a mac. Maybe you are not using GNU grep?

$ grep --version
grep (GNU grep) 3.11
Packaged by Homebrew
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others; see
<https://git.savannah.gnu.org/cgit/grep.git/tree/AUTHORS>.

grep -P uses PCRE2 10.42 2022-12-11

diepfote avatar May 22 '23 06:05 diepfote

@iloveitaly I am on a mac, but changing the default grep installation would be a large-ish change since many other applications rely on the terrible grep version installed by default.

iloveitaly avatar Jun 10 '23 12:06 iloveitaly

@iloveitaly

if you are on an M1 chip just do export PATH=/opt/homebrew/opt/grep/libexec/gnubin/grep:$PATH"

on an x86-64 bit machine do export PATH=/usr/local/opt/grep/libexec/gnubin:$PATH"


you can check what to export at

$ brew info grep
==> grep: stable 3.11 (bottled), HEAD
GNU grep, egrep and fgrep
https://www.gnu.org/software/grep/
/opt/homebrew/Cellar/grep/3.11 (19 files, 1MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-07-04 at 11:37:53
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/grep.rb
License: GPL-3.0-or-later
==> Dependencies
Build: pkg-config (installed)
Required: pcre2 (installed)
==> Options
--HEAD
        Install HEAD version
==> Caveats
All commands have been installed with the prefix "g".
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
  PATH="/opt/homebrew/opt/grep/libexec/gnubin:$PATH"

diepfote avatar Jul 10 '23 10:07 diepfote