Bash function to search git repository for a filename that matches regex -
I'm trying to apply (which has a comment on it) in my .bashrc file in the form of a bash function In.
: & lt; & Lt; COMMENT Search for the commitments in the current GIT repository for all files that match a regular expression Usage: GITF & lt; Reggae & gt; Parameter is required, and must have at least one non-whitepress character. GitHub Gist- written Handyman5 - https://stackoverflow.com/users/459089/handyman5 by https://gist.github.com/anonymous/62d981890eccb48a99dc by stack overflow users based on this SO question: - https: //stackoverflow.com/questions/372506/how-can-i-search-git-branches-for-a-file-or-directory/372654#372654 brief Description: GITF_DESC comment stored in #GITF_DESC: the "aliaf" command GITF_DESC = "gitf [searchterm]: searches for the current GIT repository for the file name that matches the regular expression (with an 'F') with a new line . \ N " Function body:
If no parameters are provided, then gitf () {set + x #Exit} ( If it is empty string) ultimate = $ (echo "$ 1" | trim) to echo "$ param" if [-z "$ param"] #http: //tldp.org/LDP/abs/html/ Comparison-ops.html then "missing required parameters." Cancel "; Return to FI = Found =" 0 "; LOC = refs / remotes / origin #: 'refs / heads' for reference ="% (refname) "for each branch for GIT - In the format = '$ ref' $ LOC`; What found = $ (git ls-tree -r --name-only $ branch | grep "$ param") If [$? -E 0 0]; Then echo "$ {branch # $ LOC /}": $ ref: ";" $ mile "was echoed =" 1 "; if" [$$ Found "-q 0]; then" this repository match "No files" in '$ param' Fi set -x} I am committed to minimizing it, so I can see it quickly. But despite the echo it is printing only the file path.
$ gitf "05" + gitf 05 +> set + x 05 master: Non_jenj_fail / Wardpres_post / Bild_jwa / Bildprti05kjawa Non_dijenj_fail / Wardpres_post / template / 05_login_remember_me.html [1: Command not found ++ History-A I'm pretty sure the last two lines are an unrelated .bashrc or .inputrc issue, but I am including them, if They are relevant. @SquepSwashbuckles: Thank you for my work, basically for me (I am new to both Bash and Git, so I really say). Output is now very clear and useful I think this is missing some hits. For example here (2 MB ZIP) to search for "05"
$ gitf 05 05 Master: 14e5cdd: non_django_files / wordpress_posts / build_java / buildpart05.java non_django_files / wordpress_posts / templates / 05_login_remember_me.html Master: 2efdeb1: searching for non_django_files / wordpress_posts /build_java/BuildPart05.java non_django_files / wordpress_posts / templates / 05_login_remember_me.html If the mean of these two things the Recent two are 05_login_remember_me.html also at least f87540e (first commit), 3a7dac9 , and 3c5e4ec is present.
The script is just fine as it is just being searched through the branches like it looks like You want to find it in branches and all the orders of those branches require you to add another to the loop on your script which you repeat on all the branches which you are searching for. Something like this:
for each rif - format = "$ ref" $ `` in git for `LOC; For the commitment to 'Git rev-list $ branch', Grep -oP ^. \ {7 \} `; What found = $ (git ls-tree -r --name-only $ commit | grep "$ param") If [$? -E 0 0]; Then "$ {branch # $ LOC /}: $ commit:"; "$ Mile" was found echo = "1"; Fi You can clear the output of your script by inducing paths to files and by adding locations between different commands. In this way:
for each floor in the branch 'git' - format = "$ ref" $ LOC`; For the commitment to 'Git rev-list $ branch', Grep -oP ^. \ {7 \} `; What found = $ (git ls-tree -r --name-only $ commit | grep "$ param") If [$? -E 0 0]; Then "$ {branch # $ LOC /}: $ commit:" read the line; Do "echo" line "lounge" & Lt; (The echo "got $$") = ok = "1"; And, as mentioned in the comments, you have to add the location after the brackets of your if statement and after that. Like it: if ["$$ was", = 0];
Comments
Post a Comment