1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/usr/bin/env python3
"""
nvim '+PlugUpdate'
sudo pacman -Syu
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 `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)
|