Skip to content

Updated the usage of the grep utility#12

Merged
yankeexe merged 2 commits intoyankeexe:masterfrom
kamilgryniewicz:unify-mac-linux-grep
Sep 25, 2022
Merged

Updated the usage of the grep utility#12
yankeexe merged 2 commits intoyankeexe:masterfrom
kamilgryniewicz:unify-mac-linux-grep

Conversation

@kamilgryniewicz
Copy link
Copy Markdown

Updated the usage of the grep utility 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

Updated the usage of the `grep` utility so it works both on Linux and
BSD (MacOS)
@yankeexe
Copy link
Copy Markdown
Owner

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-)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilgryniewicz yeah it makes sense, let's go with that approach! 👌

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yankeexe Updated, please take a look.

@yankeexe yankeexe merged commit bf510eb into yankeexe:master Sep 25, 2022
@yankeexe
Copy link
Copy Markdown
Owner

@kamil tested, looks good, thank you! 🎉

@kamilgryniewicz
Copy link
Copy Markdown
Author

@yankeexe my pleasure, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants