summaryrefslogtreecommitdiff
path: root/.local/bin/update
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/update')
-rwxr-xr-x.local/bin/update46
1 files changed, 36 insertions, 10 deletions
diff --git a/.local/bin/update b/.local/bin/update
index fc02143..990f0cc 100755
--- a/.local/bin/update
+++ b/.local/bin/update
@@ -8,10 +8,16 @@ 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}')
@@ -24,20 +30,40 @@ if os.path.exists(lock_file):
open(lock_file, 'a').close()
-log('Running `nvim \'+PlugUpdate\'`...')
-subprocess.run(['nvim', '+PlugUpdate'])
+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']),
+ ]
-log('Running `sudo pacman -Syu`...')
-subprocess.run(['sudo', 'pacman', '-Syu'])
+ if not args.noconfirm:
+ for command in commands_confirm:
+ command()
+ else:
+ for command in commands_noconfirm:
+ command()
-log('Running `aur sync -unr`...')
-subprocess.run(['aur', 'sync', '-unr'])
+ log('Running `nix-channel --update`...')
+ subprocess.run(['nix-channel', '--update'])
-log('Running `nix-channel --update`...')
-subprocess.run(['nix-channel', '--update'])
+ log('Running `nix-env -u`...')
+ subprocess.run(['nix-env', '-u'])
-log('Running `nix-env -u`...')
-subprocess.run(['nix-env', '-u'])
+except (KeyboardInterrupt):
+ pass
log('Cleaning up...')
os.remove(lock_file)