Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active September 17, 2025 10:25
Show Gist options
  • Save Konfekt/44adf3d3ca3b1dd1b19b37063168deb8 to your computer and use it in GitHub Desktop.
Save Konfekt/44adf3d3ca3b1dd1b19b37063168deb8 to your computer and use it in GitHub Desktop.
smart-case capable git-grep
#!/usr/bin/env perl
use strict;
use warnings;
my ($pattern, $grabnext);
for (@ARGV) {
if ($grabnext or not /^-/) {
$pattern = $_;
last;
} elsif (/^--$/) {
$grabnext = 1;
}
}
# Accept a --no-smart-case flag to disable our smarts
my @args = grep { not /^(-s|--case-?sensitive|--no-smart-?case)$/ } @ARGV;
my $do_smart_case = @ARGV == @args;
# Prepend -i to match case-insensitively when the pattern contains no uppercase
unshift @args, "--ignore-case"
if $pattern eq lc $pattern and $do_smart_case;
exec "git", "grep", @args
or die "exec failed: $!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment