-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (26 loc) · 845 Bytes
/
main.py
File metadata and controls
38 lines (26 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import shutil
import subprocess
import sys
def get_terminal_height():
return shutil.get_terminal_size().lines
def is_output_redirected():
return not sys.stdout.isatty()
def main():
args = sys.argv[1:]
if is_output_redirected():
command = ["git", "--no-pager", "log"] + args
else:
command = ["git", "--no-pager", "log", "--color=always", "--decorate"] + args
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT, text=True)
except subprocess.CalledProcessError as e:
print(e.output, file=sys.stderr)
sys.exit(e.returncode)
lines = output.count("\n")
term_height = get_terminal_height()
if lines <= term_height:
print(output, end="")
else:
subprocess.run(["git", "log"] + args)
if __name__ == "__main__":
main()