import subprocess from getpass import getpass from sys import argv def run(command, **kwargs): return subprocess.run(command, shell=True, **kwargs) def cap_live_lines(command, **kwargs): lines = [] with subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, text=True, **kwargs ) as proc: for line in proc.stdout: print(line, end="") lines.append(line.strip()) return lines def press_to_exit(): getpass("Exit") def main(input): if input == "rpm-ostree": lines = cap_live_lines("rpm-ostree upgrade") if "no upgrade" not in lines[-1].lower(): press_to_exit() elif input == "flatpak": lines = cap_live_lines("flatpak update -y") done_updates = "nothing to do" not in lines[-1].lower() run("flatpak remove --delete-data --unused") if done_updates: press_to_exit() elif input == "pipx": lines = cap_live_lines("pipx upgrade-all --include-injected") if "did not change" not in out[-1].lower(): press_to_exit() elif input == "cargo": lines = cap_live_lines("cargo install-update -a") if "no packages need updating" not in lines[-2].lower(): press_to_exit() elif input == "npm": run("npm update -g") elif input == "nvim": run('nvim -c "autocmd User PackerComplete quitall" -c "PackerSync"') else: print(f"Input {input} not valid!") main(argv[1])