Introduction:
If you want you can just create your own CLI for git
, I wrote a script to solve this exact problem. NoGit is a simple python script to prevent the unnecessary repetition of the "git" keyword.
Update (23/06/2022):
At the time of this update, this answer was 3 years, 1 week, and 6 days old. I've since come back and fixed a conflict error caused by NoGit's ./git
executable and the actual git
executable and made some minor changes to the behaviour of the .history
file. The GitHub page for the project and it's associated article (linked on the project's GitHub page) have also been updated.
Installation:
To run NoGit, you need Python 3 installed on your system. You can download the script from the official 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:
git /bin/nogit && sudo chmod +x /bin/nogit && alias nogit='/bin/nogit'
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 anything
ctrl+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 the git
keyword if it already exists
Demonstration:
init
add -A
stage -A
status
commit -m "initial commit"
%run; %exit
Source code:
#!/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)