1
0
Fork 0
mirror of https://codeberg.org/Mo8it/dotfiles.git synced 2024-10-17 20:52:40 +00:00
dotfiles/.scripts/update.xsh

50 lines
1.2 KiB
Text
Raw Normal View History

2022-04-23 21:07:08 +00:00
#!/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()