diff options
author | EuAndreh <eu@euandre.org> | 2025-03-31 21:51:40 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-03-31 21:51:40 -0300 |
commit | 570ec471d1605318aeefb030cd78682ae442235b (patch) | |
tree | 51e17eabe37c6689f8799b55e6875c3480329a2c /src/content/tils/2020/08/28 | |
parent | Makefile, mkdeps.sh: Derive index.html and feed.xml from more static "sortdat... (diff) | |
download | euandre.org-570ec471d1605318aeefb030cd78682ae442235b.tar.gz euandre.org-570ec471d1605318aeefb030cd78682ae442235b.tar.xz |
src/content/: Update all files left to asciidoc
Diffstat (limited to 'src/content/tils/2020/08/28')
-rw-r--r-- | src/content/tils/2020/08/28/grep-online.adoc | 83 |
1 files changed, 38 insertions, 45 deletions
diff --git a/src/content/tils/2020/08/28/grep-online.adoc b/src/content/tils/2020/08/28/grep-online.adoc index 8b3b63f..cade066 100644 --- a/src/content/tils/2020/08/28/grep-online.adoc +++ b/src/content/tils/2020/08/28/grep-online.adoc @@ -1,31 +1,19 @@ ---- += Grep online repositories -title: Grep online repositories - -date: 2020-08-28 - -layout: post - -lang: en - -ref: grep-online-repositories - -eu_categories: git - ---- +:cgit: https://git.zx2c4.com/cgit/ I often find interesting source code repositories online that I want to grep for some pattern but I can't, because either: -- the repository is on [cgit][cgit] or a similar code repository that doesn't - allow search in files, or; -- the search function is really bad, and doesn't allow me to use regular expressions for searching patterns in the code. - -[cgit]: https://git.zx2c4.com/cgit/ +* the repository is on {cgit}[cgit] or a similar code repository that doesn't + allow search in files, or; +* the search function is really bad, and doesn't allow me to use regular + expressions for searching patterns in the code. Here's a simple script that allows you to overcome that problem easily: -```shell +[source,shell] +---- #!/usr/bin/env bash set -eu @@ -66,7 +54,7 @@ pushd "/tmp/git-search/${DIRNAME}" shift 3 || shift 2 # when "--" is missing git grep "${REGEX_PATTERN}" "${@}" -``` +---- It is a wrapper around `git grep` that downloads the repository when missing. Save in a file called `git-search`, make the file executable and add it to your @@ -74,33 +62,35 @@ path. Overview: -- *lines 1~2*: - - Bash shebang and the `set -eu` options to exit on error or undefined - variables. +* _lines 1~2_: ++ +Bash shebang and the `set -eu` options to exit on error or undefined +variables. -- *lines 4~30*: +* _lines 4~30_: ++ +Usage text to be printed when providing less arguments than expected. - Usage text to be printed when providing less arguments than expected. +* _line 33_: ++ +Extract the repository name from the URL, removing trailing slashes. -- *line 33*: +* _lines 34~37_: ++ +Download the repository when missing and go to the folder. - Extract the repository name from the URL, removing trailing slashes. +* _line 39_: ++ +Make the variable `$@` contain the rest of the unused arguments. -- *lines 34~37*: - - Download the repository when missing and go to the folder. - -- *line 39*: - - Make the variable `$@` contain the rest of the unused arguments. - -- *line 40*: - - Perform `git grep`, forwarding the remaining arguments from `$@`. +* _line 40_: ++ +Perform `git grep`, forwarding the remaining arguments from `$@`. Example output: -```shell + +[source,shell] +---- $ git search 'make get-git' https://git.zx2c4.com/cgit/ Clonage dans '/tmp/git-search/cgit'... remote: Enumerating objects: 542, done. @@ -116,12 +106,15 @@ README: $ make get-git $ git search 'make get-git' https://git.zx2c4.com/cgit/ /tmp/git-search/cgit ~/dev/libre/songbooks/docs README: $ make get-git -``` +---- -Subsequent greps on the same repository are faster because no download is needed. +Subsequent greps on the same repository are faster because no download is +needed. When no argument is provided, it prints the usage text: -```shell + +[source,shell] +---- $ git search Missing argument REGEX_PATTERN. @@ -136,4 +129,4 @@ Examples: Searching "make get-git" in cgit repository: git search 'make get-git' https://git.zx2c4.com/cgit/ git search 'make get-git' https://git.zx2c4.com/cgit/ -- $(git rev-list --all) -``` +---- |