Introduction
NoGit is a Python script that prevents the unnecessary repetition of the git keyword. It opens a shell CLI where you can input git commands without typing the git
keyword before every instruction. I wrote this script as an answer to a question on StackOverflow.
After calling ./nogit, a CLI (similar to the MySQL shell) should appear:
git>
Note: Given that NoGit is a wrapper around Git, it provides all of the features of the Git VCS.
Documentation
%undo
deletes the last command from the stack%run
executes all commands in the stack and deletes it when done%exit
closes the CLI without doing anythingctrl+c
has the same effect as executing%run; %exit
or%run
and%exit
- Command history gets saved to a file called
nogit.history
in the same folder as the script - You can add multiple commands in one line using a semi-colon
- You can use the
git
keyword because the script doesn't add thegit
keyword if it already exists
Demonstration
init
add -A
stage -A
status
commit -m "initial commit"
%run; %exit
Installation
To run NoGit, you need Python 3 installed on your system. You can download it from the official Github Repository or copy the source code below.
Note: The script depends on the sys, os, signal, atexit, readline and subprocess modules.
Installation notes (Linux)
If you want you can remove the .py
extension and convert it into an executable:
mv nogit.py nogit
chmod +x ./nogit
./nogit # open the NoGit CLI
You can also move this script to your ./bin/
directory and create an alias for it to run it without a ./
:
sudo cp ./nogit /bin/nogit
sudo chmod +x /bin/nogit
alias nogit="/bin/nogit"
Alternatively you can copy the following command into your CLI:
sudo cp ./nogit /bin/nogit && sudo chmod +x /bin/nogit && alias nogit='/bin/nogit'
Source code
To install NoGit locally, copy and paste the following source code into a file named nogit.py
.
#!/usr/bin/env python
import sys, os, signal, atexit, readline, subprocess
commands, stop, history_file = [], False, os.path.join(os.getcwd(), "nogit.history")
def run_commands():
stop = True
for cmd in commands:
command = ["git" if not cmd.startswith("git ") else ""]
command = [cmd] if command[0] == "" else [command[0], cmd]
subprocess.Popen(command).communicate()
commands = []
def signal_handler(sig, frame):
run_commands()
sys.exit(0)
try:
readline.read_history_file(history_file)
signal.signal(signal.SIGINT, signal_handler)
while True:
if stop == True:
break
command = input("git> ")
if command == "%undo":
commands.pop()
elif command == "%run":
run_commands()
elif command == "%exit":
sys.exit(0)
else:
commands += [cmd.strip() for cmd in command.split(";")]
signal.pause()
readline.set_history_length(-1)
except IOError:
pass
atexit.register(readline.write_history_file, history_file)