Last active
September 17, 2025 10:25
-
-
Save Konfekt/44adf3d3ca3b1dd1b19b37063168deb8 to your computer and use it in GitHub Desktop.
smart-case capable git-grep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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