#!/usr/bin/env python3 """ nvim '+PlugUpdate' sudo pacman -Syu rustup update aur sync -unr nix-channel --update && nix-env -u """ import sys, os import argparse import subprocess from time import localtime, strftime parser = argparse.ArgumentParser(prog = 'update') parser.add_argument('--noconfirm', default = False, action = 'store_true') args = parser.parse_args() def log(message: str): print(f'[{strftime("%H:%M:%S", localtime())}] {message}') lock_file = 'update.lock' if os.path.exists(lock_file): log('Update already running') sys.exit(0) open(lock_file, 'a').close() try: commands_confirm = [ lambda: log('Running `nvim \'+PlugUpdate\'`...'), lambda: subprocess.run(['nvim', '+PlugUpdate']), lambda: log('Running `sudo pacman -Syu`...'), lambda: subprocess.run(['sudo', 'pacman', '-Syu']), lambda: log('Running `aur sync -unr`...'), lambda: subprocess.run(['aur', 'sync', '-unr']), ] commands_noconfirm = [ lambda: log('Running `aur sync -unr`...'), lambda: subprocess.run(['aur', 'sync', '-unr']), lambda: log('Running `sudo pacman -Syu`...'), lambda: subprocess.run(['sudo', 'pacman', '-Syu', '--noconfirm']), lambda: log('Running `nvim \'+PlugUpdate\'`...'), lambda: subprocess.run(['nvim', '+PlugUpdate', '+qall']), ] if not args.noconfirm: for command in commands_confirm: command() else: for command in commands_noconfirm: command() log('Running `rustup update`...') subprocess.run(['rustup', 'update']) log('Running `nix-channel --update`...') subprocess.run(['nix-channel', '--update']) log('Running `nix-env -u`...') subprocess.run(['nix-env', '-u']) except (KeyboardInterrupt): pass log('Cleaning up...') os.remove(lock_file)