Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: ideas for stored searches #57

Open
bruno- opened this issue Nov 21, 2014 · 18 comments
Open

Discussion: ideas for stored searches #57

bruno- opened this issue Nov 21, 2014 · 18 comments

Comments

@bruno-
Copy link
Member

bruno- commented Nov 21, 2014

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.

@ctjhoa
Copy link
Member

ctjhoa commented Nov 22, 2014

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

@justmytwospence
Copy link

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

@AnAppAMonth
Copy link

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?

@bruno-
Copy link
Member Author

bruno- commented Mar 20, 2015

@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.

@jbnicolai
Copy link
Member

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

@bruno- bruno- mentioned this issue May 28, 2015
@davidjb
Copy link

davidjb commented Jun 18, 2015

Pull request for email address search over at #78

@konstantinstadler
Copy link

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.

@endrebak
Copy link

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.

@alphaCTzo7G
Copy link

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.

@diepfote
Copy link

diepfote commented Nov 4, 2019

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
Copy link

diepfote commented Nov 10, 2019

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

@nilesh-akhade
Copy link

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
Copy link

nilesh-akhade commented Dec 2, 2022

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

@diepfote
Copy link

diepfote commented Dec 2, 2022

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.

@iloveitaly
Copy link

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

@diepfote
Copy link

@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

@iloveitaly
Copy link

@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.

@diepfote
Copy link

diepfote commented Jul 10, 2023

@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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests