Add simple-git-push script.
This commit is contained in:
		
							parent
							
								
									3a17571bdd
								
							
						
					
					
						commit
						cb899efa7f
					
				| 
						 | 
					@ -14,6 +14,7 @@ alias gd="git diff"
 | 
				
			||||||
alias gdc="git diff --cached"
 | 
					alias gdc="git diff --cached"
 | 
				
			||||||
alias gl="git log"
 | 
					alias gl="git log"
 | 
				
			||||||
alias gls="git log --all --decorate --oneline --graph"
 | 
					alias gls="git log --all --decorate --oneline --graph"
 | 
				
			||||||
 | 
					alias gp="simple-git-push"
 | 
				
			||||||
alias gs="git status"
 | 
					alias gs="git status"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
alias clipboard-to-file="xclip -sel clip -o > $1"
 | 
					alias clipboard-to-file="xclip -sel clip -o > $1"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,43 @@
 | 
				
			||||||
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import argparse
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					import typing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def main() -> None:
 | 
				
			||||||
 | 
					    available_remotes = git_remote()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if len(available_remotes) == 0:
 | 
				
			||||||
 | 
					        print("No remotes found")
 | 
				
			||||||
 | 
					        sys.exit(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Parse any extra arguments passed to use them in git_push, this way
 | 
				
			||||||
 | 
					    # simple-git-push acts like an aliased command.
 | 
				
			||||||
 | 
					    extra_args = argparse.ArgumentParser(add_help=False).parse_known_args()[1]
 | 
				
			||||||
 | 
					    remotes_to_push = ["origin", "github"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for remote in available_remotes:
 | 
				
			||||||
 | 
					        if remote in remotes_to_push:
 | 
				
			||||||
 | 
					            git_push(remote, extra_args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def git_remote() -> typing.List[str]:
 | 
				
			||||||
 | 
					    """Run `git remote` and return found remote names."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    command = ["git", "remote"]
 | 
				
			||||||
 | 
					    output = subprocess.run(command, capture_output=True, encoding="utf8")
 | 
				
			||||||
 | 
					    return output.stdout.splitlines()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def git_push(remote: str, extra_args: typing.List[str]) -> None:
 | 
				
			||||||
 | 
					    """Run `git push` for the given remote."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    command = ["git", "push", "--follow-tags", remote, *extra_args]
 | 
				
			||||||
 | 
					    print(f"""Pushing: {" ".join(command)}""")
 | 
				
			||||||
 | 
					    subprocess.run(command)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    main()
 | 
				
			||||||
		Reference in New Issue