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': ' ',
|
||||
},
|
||||
}
|
59
bash/.bash_aliases
Normal file
59
bash/.bash_aliases
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
# General Aliases
|
||||
alias ll='ls -la'
|
||||
alias update='sudo apt update && sudo apt upgrade -y && flatpak update -y'
|
||||
alias R='cd ~/Repos/'
|
||||
|
||||
# Git Config User
|
||||
function gitConfigUser() {
|
||||
git config user.email $1
|
||||
git config user.name "Kendall Whitman"
|
||||
}
|
||||
|
||||
alias gcp='gitConfigUser "kendall@kendallwhitman.dev"'
|
||||
alias gcw='gitConfigUser "kendall.whitman@nbcuni.com"'
|
||||
|
||||
# Git Formatter
|
||||
alias gft='python3 ~/.git-formatter/main.py'
|
||||
|
||||
# Git Aliases
|
||||
alias ga='git add'
|
||||
alias gaa='git add .'
|
||||
alias gb='git branch'
|
||||
alias gc='git clone'
|
||||
alias gcb='git checkout -b'
|
||||
alias gco='git checkout'
|
||||
alias gcmsg='gft -m'
|
||||
alias gd='git diff'
|
||||
alias gf='git fetch'
|
||||
alias gl='git pull'
|
||||
alias gp='git push'
|
||||
alias gpu='git push -u origin $(git branch --show-current)'
|
||||
alias grs='git restore --staged'
|
||||
alias gst='git status'
|
||||
alias gwa='gft -i'
|
||||
alias gwr='gft -r'
|
||||
|
||||
#NBC Aliases
|
||||
alias nbc='tmuxp load phoenix ramen amp amped-up hfs omega'
|
||||
alias p='cd ~/Repos/NBC/WEB.Phoenix.git/'
|
||||
alias r='cd ~/Repos/NBC/nextjs-ramen.git/'
|
||||
alias h='cd ~/Repos/NBC/header-footer-service.git/'
|
||||
alias o='cd ~/Repos/NBC/omega-player.git/'
|
||||
alias amp='cd ~/Repos/NBC/WEB.AMP.git/'
|
||||
alias amped='cd ~/Repos/NBC/amped-up.git/'
|
||||
|
||||
# NPM Alias
|
||||
alias ns='nvm use && npm start'
|
||||
alias nd='nvm use && npm run dev'
|
||||
|
||||
# OpenRGB
|
||||
alias rgb='sudo /media/kendall/1TB/AppImages/OpenRGB/OpenRGB.AppImage'
|
||||
|
||||
# Bash Prompt
|
||||
function bashPrompt() {
|
||||
PS1=$(python3 ~/.dotfiles/bash/.bash-prompt/main.py)
|
||||
}
|
||||
|
||||
PROMPT_COMMAND=bashPrompt
|
36
bash/.git-formatter/config.py
Normal file
36
bash/.git-formatter/config.py
Normal file
@@ -0,0 +1,36 @@
|
||||
NBC = {
|
||||
'branch_format': "BRANCH_TYPE/BRANCH_ID",
|
||||
'commit_format': "BRANCH_ID",
|
||||
'types': {
|
||||
'Feature': 'feature',
|
||||
'Fix': 'fix',
|
||||
'Refactor': 'refactor',
|
||||
'Release': 'release',
|
||||
'Documentation': 'docs',
|
||||
}
|
||||
}
|
||||
|
||||
DEFAULT = {
|
||||
'branch_format': "BRANCH_TYPE(BRANCH_ID)",
|
||||
'commit_format': "BRANCH_TYPE(BRANCH_ID)",
|
||||
'types': {
|
||||
'Feature': 'feat',
|
||||
'Fix': 'fix',
|
||||
'Refactor': 'refactor',
|
||||
'Release': 'release',
|
||||
'Documentation': 'docs',
|
||||
}
|
||||
}
|
||||
|
||||
REPO_FORMATS = {
|
||||
'amped-up.git': NBC,
|
||||
'nextjs-ramen.git': NBC,
|
||||
'omega-player.git': DEFAULT,
|
||||
'WEB.AMP.git': NBC,
|
||||
'WEB.Phoenix.git': NBC,
|
||||
'header-footer-service.git': NBC,
|
||||
'ham-search': DEFAULT,
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
REPO_FORMATS
|
98
bash/.git-formatter/main.py
Normal file
98
bash/.git-formatter/main.py
Normal file
@@ -0,0 +1,98 @@
|
||||
import argparse
|
||||
import sys
|
||||
from scripts import (
|
||||
add_worktree,
|
||||
remove_worktree,
|
||||
add_commit,
|
||||
new_branch,
|
||||
)
|
||||
|
||||
|
||||
def help_menu():
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
description="Git Formatter",
|
||||
prog="gft",
|
||||
formatter_class=argparse.RawTextHelpFormatter
|
||||
)
|
||||
|
||||
worktree_group = parser.add_argument_group('Worktree Options')
|
||||
branch_group = parser.add_argument_group('Branch Options')
|
||||
commit_group = parser.add_argument_group('Commit Options')
|
||||
options_group = parser.add_argument_group('General Options')
|
||||
|
||||
worktree_group.add_argument(
|
||||
'-a',
|
||||
default=False,
|
||||
metavar="worktree",
|
||||
nargs='?',
|
||||
help="Create a git worktree",
|
||||
)
|
||||
|
||||
worktree_group.add_argument(
|
||||
'-i',
|
||||
default=False,
|
||||
metavar="worktree",
|
||||
nargs='?',
|
||||
help="Create a git worktree and automatically install npm packages",
|
||||
)
|
||||
|
||||
worktree_group.add_argument(
|
||||
'-r',
|
||||
default=False,
|
||||
metavar="worktree",
|
||||
nargs='?',
|
||||
help="Remove a git worktree",
|
||||
)
|
||||
|
||||
branch_group.add_argument(
|
||||
'-b',
|
||||
default=False,
|
||||
metavar="branch",
|
||||
nargs='?',
|
||||
help="Create a branch",
|
||||
)
|
||||
|
||||
commit_group.add_argument(
|
||||
'-m',
|
||||
default=False,
|
||||
metavar="message",
|
||||
nargs='?',
|
||||
help="Commit changes with a formatted message",
|
||||
)
|
||||
|
||||
options_group.add_argument(
|
||||
'-h',
|
||||
'--help',
|
||||
action='help',
|
||||
help='Show this help menu'
|
||||
)
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
parser.print_help()
|
||||
exit(0)
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = help_menu()
|
||||
|
||||
if args.a is not False:
|
||||
add_worktree(args.a)
|
||||
|
||||
if args.i is not False:
|
||||
add_worktree(args.i, True)
|
||||
|
||||
if args.r is not False:
|
||||
remove_worktree(args.r)
|
||||
|
||||
if args.b is not False:
|
||||
new_branch()
|
||||
|
||||
if args.m is not False:
|
||||
add_commit(args.m)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
8
bash/.git-formatter/scripts/__init__.py
Normal file
8
bash/.git-formatter/scripts/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from .worktree import (
|
||||
add_worktree,
|
||||
remove_worktree,
|
||||
)
|
||||
from .commit import add_commit
|
||||
from .branch import (
|
||||
new_branch,
|
||||
)
|
9
bash/.git-formatter/scripts/branch.py
Normal file
9
bash/.git-formatter/scripts/branch.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from utils.branch_details import branch_details
|
||||
from utils.format import format_branch
|
||||
from utils.git_commands import git_checkout_branch
|
||||
|
||||
|
||||
def new_branch():
|
||||
branch_type, branch_id = branch_details()
|
||||
branch_name = format_branch(branch_type, branch_id)
|
||||
git_checkout_branch(branch_name)
|
19
bash/.git-formatter/scripts/commit.py
Normal file
19
bash/.git-formatter/scripts/commit.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from utils.format import format_commit
|
||||
from utils.git_commands import git_commit
|
||||
from utils.messages import (
|
||||
title,
|
||||
instructions,
|
||||
commit_instructions,
|
||||
)
|
||||
|
||||
|
||||
def add_commit(message=''):
|
||||
commit_title = f"{format_commit()}: "
|
||||
commit_message = message
|
||||
|
||||
if commit_message == '':
|
||||
title("Commit Message")
|
||||
instructions(commit_instructions)
|
||||
commit_message = input(commit_title)
|
||||
|
||||
git_commit(f"{commit_title}{commit_message}")
|
60
bash/.git-formatter/scripts/worktree.py
Normal file
60
bash/.git-formatter/scripts/worktree.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import os
|
||||
import subprocess
|
||||
from .branch import branch_details
|
||||
from utils.format import format_branch
|
||||
from utils.git_commands import (
|
||||
git_add_worktree,
|
||||
git_remove_worktree,
|
||||
)
|
||||
from utils.messages import (
|
||||
title,
|
||||
instructions,
|
||||
worktree_instructions,
|
||||
)
|
||||
|
||||
|
||||
def add_worktree(worktree=None, auto_install=False):
|
||||
|
||||
# Check for bare repo
|
||||
try:
|
||||
with open('config') as git_config:
|
||||
content = ' '.join(git_config.readlines())
|
||||
if 'bare = true' in content:
|
||||
|
||||
# Ask for worktree folder name
|
||||
|
||||
if worktree is None:
|
||||
title('Create Worktree')
|
||||
instructions(worktree_instructions)
|
||||
worktree = input('Worktree Directory Name: ')
|
||||
|
||||
# Get branch details
|
||||
branch_type, branch_id = branch_details()
|
||||
|
||||
# Format branch name
|
||||
branch_name = format_branch(
|
||||
branch_type,
|
||||
branch_id,
|
||||
worktree,
|
||||
)
|
||||
|
||||
# Create worktree
|
||||
git_add_worktree(worktree, branch_name)
|
||||
|
||||
# Install NPM packages after worktree creation
|
||||
if auto_install:
|
||||
os.chdir(f"./{worktree}")
|
||||
|
||||
subprocess.run(['/bin/bash', '-i', '-c', 'nvm use'])
|
||||
subprocess.run(['npm', 'i'])
|
||||
|
||||
exit(0)
|
||||
|
||||
except Exception:
|
||||
print('No worktree found')
|
||||
exit(1)
|
||||
|
||||
|
||||
def remove_worktree(worktree):
|
||||
worktree_name = worktree if worktree else input('Worktree to remove: ')
|
||||
git_remove_worktree(worktree_name)
|
30
bash/.git-formatter/utils/__init__.py
Normal file
30
bash/.git-formatter/utils/__init__.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from .repo_format import (
|
||||
branch_format,
|
||||
branch_types,
|
||||
commit_format,
|
||||
repo_format,
|
||||
)
|
||||
|
||||
from .format import (
|
||||
format_branch,
|
||||
format_commit,
|
||||
)
|
||||
|
||||
from .git_commands import (
|
||||
git_add_worktree,
|
||||
git_branches,
|
||||
git_checkout_branch,
|
||||
git_commit,
|
||||
git_current_branch,
|
||||
git_remove_worktree,
|
||||
)
|
||||
|
||||
from .messages import (
|
||||
title,
|
||||
instructions,
|
||||
worktree_instructions,
|
||||
commit_instructions,
|
||||
)
|
||||
|
||||
from .repo_name import repo_name
|
||||
from .branch_details import branch_details
|
24
bash/.git-formatter/utils/branch_details.py
Normal file
24
bash/.git-formatter/utils/branch_details.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from utils.messages import (
|
||||
title,
|
||||
instructions,
|
||||
worktree_instructions,
|
||||
)
|
||||
from utils.repo_format import branch_types
|
||||
|
||||
|
||||
def branch_details():
|
||||
|
||||
# Ask for branch type
|
||||
for idx, type in enumerate(branch_types):
|
||||
print(f"[{idx + 1}] {type}")
|
||||
|
||||
title("Branch Types")
|
||||
instructions(worktree_instructions)
|
||||
branch_type: str = input('Branch Type: ')
|
||||
branch_type_idx: int = int(branch_type) - 1
|
||||
branch_type_value: str = list(branch_types.values())[branch_type_idx]
|
||||
|
||||
# Ask for branch id
|
||||
branch_id: str = input('Branch ID: ').upper()
|
||||
|
||||
return branch_type_value, branch_id
|
36
bash/.git-formatter/utils/format.py
Normal file
36
bash/.git-formatter/utils/format.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import re
|
||||
from .git_commands import git_current_branch
|
||||
from .repo_format import (
|
||||
branch_format,
|
||||
commit_format,
|
||||
)
|
||||
|
||||
|
||||
def format_branch(branch_type, branch_id, worktree_name=''):
|
||||
if branch_type != '' and branch_id != '':
|
||||
return (
|
||||
branch_format
|
||||
.replace('BRANCH_TYPE', branch_type)
|
||||
.replace('BRANCH_ID', branch_id)
|
||||
)
|
||||
|
||||
if branch_type == '' and branch_id == '' and worktree_name != '':
|
||||
return worktree_name
|
||||
|
||||
if branch_type == '' and branch_id != '':
|
||||
return branch_id
|
||||
|
||||
return 'Error: Something went wrong'
|
||||
|
||||
|
||||
def format_commit():
|
||||
branch_list = re.findall(r'([a-zA-Z0-9-]+)', git_current_branch())
|
||||
|
||||
if len(branch_list) == 1:
|
||||
return branch_list[0]
|
||||
elif len(branch_list) > 1:
|
||||
return (
|
||||
commit_format
|
||||
.replace('BRANCH_TYPE', branch_list[0])
|
||||
.replace('BRANCH_ID', branch_list[1])
|
||||
)
|
53
bash/.git-formatter/utils/git_commands.py
Normal file
53
bash/.git-formatter/utils/git_commands.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import subprocess
|
||||
|
||||
git_branches = subprocess.run(
|
||||
['git', 'branch'],
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
).stdout.strip()
|
||||
|
||||
|
||||
def git_add_worktree(worktree_name, branch_name, git_branches=git_branches):
|
||||
# FIXME: This should check for the exact branch name.
|
||||
# If NGAV-1000 already exists, an error is thrown when
|
||||
# NGAV-100 tries to be created
|
||||
existing_branch = branch_name in git_branches
|
||||
|
||||
subprocess.run([
|
||||
'git',
|
||||
'worktree',
|
||||
'add',
|
||||
worktree_name,
|
||||
'--checkout' if existing_branch else '-b',
|
||||
branch_name
|
||||
])
|
||||
|
||||
|
||||
def git_remove_worktree(worktree_name):
|
||||
subprocess.run([
|
||||
'git',
|
||||
'worktree',
|
||||
'remove',
|
||||
worktree_name
|
||||
])
|
||||
|
||||
|
||||
def git_checkout_branch(branch_name):
|
||||
subprocess.run([
|
||||
'git',
|
||||
'checkout',
|
||||
'-b',
|
||||
branch_name
|
||||
])
|
||||
|
||||
|
||||
def git_current_branch():
|
||||
return subprocess.run(
|
||||
['git', 'branch', '--show-current'],
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
).stdout
|
||||
|
||||
|
||||
def git_commit(commit_message):
|
||||
subprocess.run(['git', 'commit', '-m', commit_message])
|
14
bash/.git-formatter/utils/messages.py
Normal file
14
bash/.git-formatter/utils/messages.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def title(text) -> None:
|
||||
border_char = '='
|
||||
print(f"\n{text}\n{border_char * len(text)}")
|
||||
|
||||
|
||||
def instructions(text) -> None:
|
||||
print(f"{text}\n")
|
||||
|
||||
|
||||
worktree_instructions = """Name the worktree directory.
|
||||
This can be different than your branch name.
|
||||
"""
|
||||
|
||||
commit_instructions = """Some great commit instructions..."""
|
7
bash/.git-formatter/utils/repo_format.py
Normal file
7
bash/.git-formatter/utils/repo_format.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from config import REPO_FORMATS
|
||||
from .repo_name import repo_name
|
||||
|
||||
repo_format = REPO_FORMATS[repo_name()]
|
||||
branch_types = repo_format['types']
|
||||
branch_format = repo_format['branch_format']
|
||||
commit_format = repo_format['commit_format']
|
11
bash/.git-formatter/utils/repo_name.py
Normal file
11
bash/.git-formatter/utils/repo_name.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import os
|
||||
from config import REPO_FORMATS
|
||||
|
||||
|
||||
def repo_name() -> str:
|
||||
for repo in REPO_FORMATS:
|
||||
if repo in os.getcwd():
|
||||
return repo
|
||||
|
||||
print("Sorry, this repo isn't setup to use Git Formatter")
|
||||
exit(1)
|
Reference in New Issue
Block a user