Skip to content

Commit

Permalink
Absolute paths support added
Browse files Browse the repository at this point in the history
  • Loading branch information
jasursadikov committed Sep 10, 2024
1 parent 1324efd commit 71edb65
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def run(self) -> None:
return
# Checks for available updates
elif sys.argv[1] in UPDATE:
utils.check_updates(True)
utils.update(True)
return
# Runs configuration wizard
elif sys.argv[1] in CONFIGURE:
Expand Down
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def load(self, file_path: str) -> None:
reader = csv.reader(tsvfile, delimiter='\t')
for row in reader:
path = row[0]

if path.startswith('~'):
path = os.path.expanduser(path)

if not os.path.isdir(path):
utils.print_error(f'Invalid path {BOLD}{path}{RESET}.')
continue
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if __name__ == '__main__':
try:
utils.settings = settings.Settings(utils.SETTINGS_FILE_NAME)
utils.set_up()
utils.setup()
mud = App()
mud.run()
except KeyboardInterrupt:
Expand Down
14 changes: 13 additions & 1 deletion runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ def _get_table() -> PrettyTable:

@staticmethod
def _get_formatted_path(path: str) -> str:
simplify_branches = utils.settings.config['mud'].getboolean('simplify_branches')
if os.path.isabs(path):
home = os.path.expanduser('~')
if path.startswith(home):
path = path.replace(home, '~', 1)
if path.startswith('/'):
path = path[1:]
parts = path.split('/')
return DIM + WHITE + ('/'.join([p[0] for p in parts[:-1]] + [RESET + DIM + parts[-1]]) if simplify_branches else '/'.join(
[p for p in parts[:-1]] + [(parts[-1][:10] + '..' if len(parts[-1]) > 10 else parts[-1])])) + RESET

return f'{DIM}{path}{RESET}'

@staticmethod
Expand Down Expand Up @@ -354,8 +365,9 @@ def _get_formatted_branches(branches: List[str], current_branch: str) -> str:
if len(branches) == 0:
return ''

simplify_branches = utils.settings.config['mud'].getboolean('simplify_branches') is True
simplify_branches = utils.settings.config['mud'].getboolean('simplify_branches')
output = ''

for branch in branches:
is_origin = branch.startswith('origin/')
branch = branch.replace('origin/', '') if is_origin else branch
Expand Down
24 changes: 12 additions & 12 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
settings: Settings


def set_up():
def setup():
global GLYPHS
GLYPHS = ICON_GLYPHS if settings.mud_settings['nerd_fonts'] else TEXT_GLYPHS

if settings.config['mud'].getboolean('ask_updates') and check_updates():
if settings.config['mud'].getboolean('ask_updates') and update():
sys.exit()


Expand All @@ -85,7 +85,7 @@ def version() -> None:
''')


def check_updates(explicit: bool = False) -> bool:
def update(explicit: bool = False) -> bool:
target_directory = os.getcwd()
os.chdir(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -123,17 +123,18 @@ def check_updates(explicit: bool = False) -> bool:
os.chdir(target_directory)
return False


def configure():
settings.config['mud']['run_async'] = str(ask('Do you want to run commands simultaneously for multiple repositories?'))
settings.config['mud']['run_table'] = str(ask('Do you want to see command execution progress in table view? This will limit output content.'))
settings.config['mud']['ask_updates'] = str(ask(f'Do you want to get information about latest updates?'))
settings.config['mud']['nerd_fonts'] = str(ask(f'Do you want to use {BOLD}nerd-fonts{RESET}?'))
settings.config['mud']['simplify_branches'] = str(ask(f'Do you want to simplify branches? (ex. {BOLD}feature/name{RESET} -> {BOLD}f/name{RESET}'))
try:
settings.config['mud']['run_table'] = str(ask('Do you want to see command execution progress in table view? This will limit output content.'))
settings.config['mud']['run_async'] = str(ask('Do you want to run commands simultaneously for multiple repositories?'))
settings.config['mud']['simplify_branches'] = str(ask(f'Do you want to simplify branches? (ex. {BOLD}feature/name{RESET} -> {BOLD}f/name{RESET}'))
settings.config['mud']['nerd_fonts'] = str(ask(f'Do you want to use {BOLD}nerd-fonts{RESET}?'))
settings.config['mud']['ask_updates'] = str(ask(f'Do you want to get information about latest updates?'))
except KeyboardInterrupt:
return

settings.save()
print('Your settings are updated!')
pass


def ask(text: str) -> bool:
print(f'{text} [Y/n] ', end='', flush=True)
Expand All @@ -153,7 +154,6 @@ def ask(text: str) -> bool:
print()
return response in ['y', '\r', '\n']


def print_error(text: str, code: int = 255) -> None:
print(f'{RED}Error:{RESET} {text}')
sys.exit(code)

0 comments on commit 71edb65

Please sign in to comment.