diff --git a/.config/nvim/ftplugin/markdown.lua b/.config/nvim/ftplugin/markdown.lua deleted file mode 100644 index 5db866a..0000000 --- a/.config/nvim/ftplugin/markdown.lua +++ /dev/null @@ -1 +0,0 @@ -vim.wo.wrap = true diff --git a/.config/nvim/ftplugin/markdown.lua b/.config/nvim/ftplugin/markdown.lua new file mode 120000 index 0000000..6f7c94b --- /dev/null +++ b/.config/nvim/ftplugin/markdown.lua @@ -0,0 +1 @@ +asciidoc.lua \ No newline at end of file diff --git a/.scripts/fetch_installed_packages.xsh b/.scripts/fetch_installed_packages.py similarity index 68% rename from .scripts/fetch_installed_packages.xsh rename to .scripts/fetch_installed_packages.py index 2bd27f1..7990f33 100644 --- a/.scripts/fetch_installed_packages.xsh +++ b/.scripts/fetch_installed_packages.py @@ -1,11 +1,21 @@ -#!/usr/bin/env xonsh - -import os import json +import subprocess +from os import environ from pathlib import Path + +def run(command, **kwargs): + return subprocess.run(command, shell=True, check=True, **kwargs) + + +def cap_run(command, **kwargs): + return run( + command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, **kwargs + ).stdout + + def rpm_ostree_packages(output_dir): - out = $(rpm-ostree status --json) + out = cap_run("rpm-ostree status --json") json_out = json.loads(out) deployments = json_out["deployments"] @@ -25,8 +35,9 @@ def rpm_ostree_packages(output_dir): dict = {"Removed": removals, "Added": additions} json.dump(dict, f, indent=4) + def npm_packages(output_dir): - out = $(npm list --json -g) + out = cap_run("npm list --json -g") json_out = json.loads(out) deps = json_out["dependencies"].keys() @@ -35,8 +46,9 @@ def npm_packages(output_dir): for dep in deps: f.write(dep + "\n") + def pipx_packages(output_dir): - out = $(pipx list --json) + out = cap_run("pipx list --json") json_out = json.loads(out) venvs = json_out["venvs"] @@ -51,16 +63,17 @@ def pipx_packages(output_dir): file = output_dir / "pipx.json" with file.open("w") as f: dict = {p: i for p, i in zip(packages, injections)} - json.dump(dict, f, indent = 4) + json.dump(dict, f, indent=4) -output_dir = Path(f"{$HOME}/bk/installed_packages_info") + +output_dir = Path(f"{environ['HOME']}/bk/installed_packages_info") output_dir.mkdir(parents=True, exist_ok=True) rpm_ostree_packages(output_dir) -flatpak list --app --columns=name,application,origin >@(output_dir)/flatpak.csv +run(f"flatpak list --app --columns=name,application,origin > {output_dir}/flatpak.csv") -cargo install --list | rg '(.+) .+:.*' -r '$1' >@(output_dir)/cargo.txt +run(f"cargo install --list | rg '(.+) .+:.*' -r '$1' > {output_dir}/cargo.txt") pipx_packages(output_dir) diff --git a/.scripts/update.py b/.scripts/update.py new file mode 100644 index 0000000..68294cc --- /dev/null +++ b/.scripts/update.py @@ -0,0 +1,58 @@ +import subprocess +from getpass import getpass +from sys import argv + + +def run(command, **kwargs): + return subprocess.run(command, shell=True, **kwargs) + + +def cap_live_lines(command, **kwargs): + lines = [] + with subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, text=True, **kwargs + ) as proc: + for line in proc.stdout: + print(line, end="") + lines.append(line.strip()) + + return lines + + +def press_to_exit(): + getpass("Exit") + + +def main(input): + if input == "rpm-ostree": + lines = cap_live_lines("rpm-ostree upgrade") + + if "no upgrade" not in lines[-1].lower(): + press_to_exit() + elif input == "flatpak": + lines = cap_live_lines("flatpak update -y") + done_updates = "nothing to do" not in lines[-1].lower() + + run("flatpak remove --delete-data --unused") + + if done_updates: + press_to_exit() + elif input == "pipx": + lines = cap_live_lines("pipx upgrade-all --include-injected") + + if "did not change" not in out[-1].lower(): + press_to_exit() + elif input == "cargo": + lines = cap_live_lines("cargo install-update -a") + + if "no packages need updating" not in lines[-2].lower(): + press_to_exit() + elif input == "npm": + run("npm update -g") + elif input == "nvim": + run('nvim -c "autocmd User PackerComplete quitall" -c "PackerSync"') + else: + print(f"Input {input} not valid!") + + +main(argv[1]) diff --git a/.scripts/update.xsh b/.scripts/update.xsh deleted file mode 100644 index cd61a07..0000000 --- a/.scripts/update.xsh +++ /dev/null @@ -1,49 +0,0 @@ -#!/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()