initial commit
This commit is contained in:
42
bash/.bash-prompt/main.py
Normal file
42
bash/.bash-prompt/main.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from utils import (
|
||||
colors,
|
||||
status_indicators,
|
||||
)
|
||||
|
||||
BASH_PATH: str = fr"{colors.CYAN}{colors.BOLD}\w"
|
||||
POINTER: str = f"{colors.YELLOW}-> {colors.RESET}"
|
||||
|
||||
|
||||
def prompt() -> None:
|
||||
git_status: subprocess.CompletedProcess[str] = subprocess.run(
|
||||
['git', 'status'],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
|
||||
if not git_status.stderr.strip():
|
||||
git_branch: str = re.findall( r'([a-zA-Z0-9-\/()]+)', git_status.stdout.strip())[2]
|
||||
|
||||
for key in status_indicators.keys():
|
||||
if key in git_status.stdout.strip():
|
||||
color: str = status_indicators[key]['color']
|
||||
icon: str = status_indicators[key]['icon']
|
||||
|
||||
git_branch_color: str = f"{color}({git_branch}{icon})"
|
||||
print(f"{BASH_PATH} {git_branch_color} {POINTER}")
|
||||
exit(0)
|
||||
|
||||
print(f"{BASH_PATH} {POINTER}")
|
||||
exit(0)
|
||||
|
||||
|
||||
def main():
|
||||
prompt()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
2
bash/.bash-prompt/utils/__init__.py
Normal file
2
bash/.bash-prompt/utils/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .colors import *
|
||||
from .status_indicators import *
|
16
bash/.bash-prompt/utils/colors.py
Normal file
16
bash/.bash-prompt/utils/colors.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# ANSI color codes in bash format
|
||||
|
||||
def template(color_code: int) -> str:
|
||||
return fr"\[\033[{color_code}m\]"
|
||||
|
||||
|
||||
RESET = template(0)
|
||||
BOLD = template(1)
|
||||
RED = template(31)
|
||||
GREEN = template(32)
|
||||
YELLOW = template(33)
|
||||
BLUE = template(34)
|
||||
MAGENTA = template(35)
|
||||
CYAN = template(36)
|
||||
WHITE = template(37)
|
||||
DEFAULT = template(39)
|
29
bash/.bash-prompt/utils/status_indicators.py
Normal file
29
bash/.bash-prompt/utils/status_indicators.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from utils import colors
|
||||
from typing import Dict
|
||||
|
||||
status_indicators: Dict[str, Dict[str, str]] = {
|
||||
'working tree clean': {
|
||||
'color': colors.GREEN,
|
||||
'icon': '',
|
||||
},
|
||||
'not staged': {
|
||||
'color': colors.YELLOW,
|
||||
'icon': ' *',
|
||||
},
|
||||
'to be committed': {
|
||||
'color': colors.YELLOW,
|
||||
'icon': ' +',
|
||||
},
|
||||
'is behind': {
|
||||
'color': colors.YELLOW,
|
||||
'icon': ' ',
|
||||
},
|
||||
'is ahead': {
|
||||
'color': colors.YELLOW,
|
||||
'icon': ' ',
|
||||
},
|
||||
'fix conflicts': {
|
||||
'color': colors.RED,
|
||||
'icon': ' ',
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user