Updated the usage of the grep utility#12
Conversation
Updated the usage of the `grep` utility so it works both on Linux and BSD (MacOS)
1a19b23 to
7012d2a
Compare
|
Hey @kamilgryniewicz thank you for the contribution! I will check it out on both Mac and Linux. |
wt
Outdated
|
|
||
| goto_main_worktree() { | ||
| main_worktree=$(git worktree list --porcelain | awk '{print $0; exit}' | grep -oP '(?<=worktree ).*') | ||
| main_worktree=$(git worktree list --porcelain | awk '{print $0; exit}' | grep -E 'worktree ' | cut -d ' ' -f2-) |
There was a problem hiding this comment.
Hey @kamilgryniewicz I tested it out on both Linux and Mac, it works great!
We don't need to pipe the value of awk to grep anymore. We can update it to:
main_worktree=$(git worktree list --porcelain | awk '{print $0; exit}' | cut -d ' ' -f2-)
Same with the one on line 102.
There was a problem hiding this comment.
Hey @yankeexe. Thanks for your comment. I suggest keeping grep so there are no incorrect results when a parameter passed to a line 102 will be HEAD or bare or anything else from the non-worktree lines. git worktree list --porcelain produces multiple lines per worktree. We are interested only in ones starting with worktree and then we are looking for a parameter (a worktree name) and then we are looking at the second part of the single line result (a worktree path). Maybe it would be better to call grep before awk like so:
git worktree list --porcelain | grep -E 'worktree ' | awk '{print $0; exit}' | cut -d ' ' -f2-
What do you think?
There was a problem hiding this comment.
@kamilgryniewicz yeah it makes sense, let's go with that approach! 👌
|
@kamil tested, looks good, thank you! 🎉 |
|
@yankeexe my pleasure, thanks! |
Updated the usage of the
greputility so it works both on Linux and BSD (MacOS).Tested on Mac using:
grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
ggrep (GNU grep) 3.8
Not tested on Linux