diff --git a/clir/utils/objects.py b/clir/utils/objects.py index 468f0f6..2c55056 100644 --- a/clir/utils/objects.py +++ b/clir/utils/objects.py @@ -5,6 +5,7 @@ import platform import subprocess from rich import box +from rich import print from rich.console import Console from rich.table import Table from rich.prompt import Prompt @@ -98,8 +99,9 @@ def run_command(self): if current_commands[c]["uid"] == uid: command = c - if uid: - print(f'Running command: {command}') + command = _replace_arguments(command) + if uid and command: + print(f'[bold green]Running command:[/bold green] {command}') os.system(command) def copy_command(self): @@ -253,4 +255,30 @@ def _get_commands(tag: str = "", grep: str = ""): sorted_commands = dict(sorted(current_commands.items(), key=lambda item: item[1]["tag"])) - return sorted_commands \ No newline at end of file + return sorted_commands + +def _get_user_input(arg): + return input(f"Enter value for '{arg}': ") + +def _replace_arguments(command): + # Use regex to find all arguments with underscores + matches = re.findall(r'_\w+', command) + + # Check that all arguments are unique + if len(matches) != len(set(matches)): + print("[bold red]Make sure that all arguments are unique[/bold red]") + return None + + # Prompt the user for values for each argument + replacements = {arg: _get_user_input(arg) for arg in matches} + + # Split the command into a list + command_list = command.split(" ") + + # Replace arguments in the command + for arg, value in replacements.items(): + for indx,term in enumerate(command_list): + if arg == term: + command_list[indx] = value + + return " ".join(command_list) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 8cd3d42..0f40099 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "clir" -version = "0.4.3" +version = "0.5.0" description = "A clear and fast way to store and recover your commands" authors = ["Elkin Aguas "] license = "MIT License"