Skip to content

Instantly share code, notes, and snippets.

@IanMejias
Created March 20, 2025 23:34
Show Gist options
  • Select an option

  • Save IanMejias/1d7a571b70f1770f89db9c18772b47e8 to your computer and use it in GitHub Desktop.

Select an option

Save IanMejias/1d7a571b70f1770f89db9c18772b47e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Como `git grep`, pero Imprime una tabla solo con el nombre de las funciones
# que ocupan la expresion.
#
# Copyright (C) 2025 Ian Mejias
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
git grep --show-function --full-name -n $@ \
| awk '
function repeat(str, n) {
ans = str;
for (i=1; i<n; i++) ans = ans""str;
return ans;
}
function longest(list, field) {
lgst = 0
for (i in list) {
l = length(list[i][field])
lgst = l > lgst ? l : lgst
}
return lgst
}
function truncar(str, n) {
if (length(str) > n) return substr(str, 0, n - 5)" ...";
return str
}
/^([/.-_[:alnum:]]+=){2}/ {
counter++;
FS = "=";
$0 = $0;
file = 1
line = 2
who = 3
matches[counter]["file"] = $file
matches[counter]["line"] = $line
matches[counter]["who"] = $who
}
END {
lgst_file = longest(matches, "file") + 1
lgst_who = longest(matches, "who") + 1
lgst_who = lgst_who > 50 ? 50 : lgst_who
fmt = "|%-"lgst_file"s|%5s|%-"lgst_who"s|\n"
printf fmt, "File", "Line", "Who";
printf fmt, repeat("-", lgst_file), repeat("-", 5), repeat("-", lgst_who);
for (i in matches) {
printf fmt, matches[i]["file"], matches[i]["line"], truncar(matches[i]["who"], lgst_who);
}
}
'
# vim:sw=2:et:sts=-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment