3

I am trying to write a command which commit's to the origin master for github, and on completion of that, shut's down the computer... Here is what I have, and it is pointing out a lot of syntax errors as I cannot find out how to have a multiline alias command... Thanks a lot and below is my function, apologies if this is a basic mistake as I am relatively new to the ZSH shell.

# Push to origin master and shut down
alias gitshut=
'
git add .;
git commit -m "Latest Commit";
git push -f origin master;
'

Thanks again, and i appreciate your help

oguz ismail
  • 1
  • 16
  • 47
  • 69
XtremeDevX
  • 1,482
  • 2
  • 13
  • 38

3 Answers3

4

Don't bother with an alias at all. Define a function.

gitshut () {
  git add .
  git commit -m "Latest Commit"
  git push -f origin master
}

Aside from having fewer quoting issues, this allows you to pass a better commit message as an argument, e.g.,

gitshut () {
  msg=${1:-Latest Commit}
  git add .
  git commit -m "$msg"
  git push -f origin master
}

Now you can use gitshut to use the default Latest Commit message, or gitshut "Fixed overflow bug" to provide something that actually describes what is being committed.

chepner
  • 497,756
  • 71
  • 530
  • 681
1

Your alias does not address the shutdown part, but you could rewrite it with:

alias gitshut='git add .;git commit -m "Latest Commit";git push -f origin master;'

Or possibly as:

alias gitshut='\
   git add .;\
   git commit -m "Latest Commit";\
   git push -f origin master;'

Using a function as in here might be easier.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Your command first defined an empty alias named gitshut. This is what the line

alias gitshut=

is doing. After this, you asked zsh run a command with the funny name \ngit add .;\ngit commit -m "Latest Commit";\ngit push -f origin master;\n (where the \n represent newline characters). Since such a file does not exist, you get an error message (likely zsh: command not found ....).

You could write it as

alias='git add .
  git commit -m "Latest Commit"
  git push -f origin master'

but honestly, doing it as a function introduces you more flexibility (for instance introducing an optional parameter which goes into the commit message).

user1934428
  • 19,864
  • 7
  • 42
  • 87