Bash Script to use for git commits
im not sure if my logic is correct but im working on converting powershell scripts over to bash. Does this look ok?
6 Replies
here is the code
it looks like you need to set some lower tab/space indents is what it looks like >.>;;
pew pew *walks out
here's the original powershell
I was using nano :3
so it looks to me like all the stuff with
$1
is doing nothing, as it simply throws an error if $1 is not a directory and then does nothing else that would require $1 to exist.
the gitDir
section is a little verbose, you can simply if [[ -d "./.git" ]]
. Notice that if[[ -d "$gitDir" = ""]]
is invalid, you can either do a -d
check, or an equality check, but not both at once.
Also, you need to ensure there's a space between the if
and the [[
else bash will try to do a property index.
you don't need that exit
at the end, bash will infer it automatically from EoF.
be sure when you are using exit that you provide a code, exit 0
means "end successfully", while any other code is "exit with error", same as JS's process.exit()
I've made some changes and this is what I got;
The $1 should be a check if it's actually a directory
Being the only argument
It should be if $1 is not a directory
I just posted https://discord.com/channels/436251713830125568/1074411022514921543/1076004353485307924
Which lets me do:
t this is my commit message
.
In general, why do you want to commit a directory from outside it. You ought to be in the directory making sure you're including anything new and making sure you don't put anything in by accident.
Commits require at least a little involvement lest you accidentally reveal keys or leave something out.
Also, you'll frequently be committing from a subdirectory of the root, so your check for the .git
directory's gonna fail.