DEV Community

loading...

Discussion on: 10 tiny helper scripts for devs!

Collapse
moopet profile image
Ben Sinclair

A few thoughts -

1 might be better named "git-uncommit" because "undo" implies reverting whatever the last action was, not specifically the last commit.

2, 3 and 4 don't need a shebang. They need to be sourced rather than executed else they'll do nothing.

4 doesn't need the function keyword, and has two commands on the same line separated with a semicolon which is not great for readability.

6 and 7 would be better off using $() than backticks.

8 and 9 mix a lot of styles and seems like they could be made more readable by sticking to printf instead of echo and consistently using double-quotes.

8 and 9 rely on the main branch being called "master" which is less and less likely to be the case nowadays. If you're using git-flow, you can use this hack to get the name of the "master" branch:

main_branch=$(git config --local --get gitflow.branch.master)
Enter fullscreen mode Exit fullscreen mode

They also expect certain conventions for other branches such as "unstable" and the principle remote to be called "origin", which is not always the case.

Collapse
benwinding profile image
Ben Winding Author

Thanks Fellow Ben,
Cheers for the feedback, you seem to have some knowledge of shell code, do you have your own library of snippets too? If not you should consider starting a dotfiles git repo 👍
Cheers

Collapse
moopet profile image
Ben Sinclair

I have one! And it has a few git tools in it.

I had the same alias as you for "undo" but as a git alias and just updated it to be "uncommit" rather than my rather dumb, "oops" command. I never used "oops" for exactly the reason I put in my comment. I remembered I had it but not what it did and couldn't be bothered to check. Now maybe I will...

github.com/moopet/dotfiles

Thread Thread
benwinding profile image
Ben Winding Author

Thanks for sharing, yeah personally I like to name functions as an extension of the original command e.g; git-uncommit is longer but it's easily discoverable when you're typing git and tab-completion makes it fairly easy to type.

I like your alias alias gti='git' I always mistype that!