1
0
Fork 0
mirror of https://codeberg.org/Mo8it/dotfiles.git synced 2024-12-29 19:53:41 +00:00

Add xonsh update script

This commit is contained in:
Mo8it 2022-04-23 23:07:08 +02:00
parent ec44964baa
commit d4c812980b

49
.scripts/update.xsh Normal file
View file

@ -0,0 +1,49 @@
#!/usr/bin/env xonsh
import re
def get_out(out_obj):
for line in out_obj:
print(line, end="")
return out_obj.out.split("\n")
def press_to_exit():
read -s -n 1 -p "Exit"
def main():
if $ARG1 == "rpm-ostree":
out = get_out(!(rpm-ostree upgrade | tee))
if out[-2] != "No upgrade available.":
press_to_exit()
elif $ARG1 == "flatpak":
flatpak update -y
flatpak remove --delete-data --unused
elif $ARG1 == "pipx":
out = get_out(!(pipx upgrade-all --include-injected | tee))
if "did not change" not in out[-2]:
press_to_exit()
elif $ARG1 == "cargo":
out = get_out(!(cargo install-update -a | tee))
pattern = r"updated (\d+) packages"
match = re.search(pattern, out[-2])
if match is None:
press_to_exit()
return
num_updated_packages = match.group(1)
if num_updated_packages != "0":
press_to_exit()
elif $ARG1 == "npm":
npm update -g
elif $ARG1 == "nvim":
nvim --headless -c "autocmd User PackerComplete quitall" -c "PackerSync"
else:
print(f"{$ARG1} not found!")
main()