Add codium-extensions script.
This commit is contained in:
parent
38df1c81fe
commit
8f970a173a
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import pathlib
|
||||
import subprocess
|
||||
import typing
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Small Tauon remote control CLI")
|
||||
parser.add_argument(
|
||||
"action",
|
||||
choices=["install", "list", "list-saved", "save"],
|
||||
help="Which action should be performed.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--file",
|
||||
help="Use a different file than $HOME/.config/codium-extensions.txt.",
|
||||
default=pathlib.Path.home().joinpath(".config/codium-extensions.txt"),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.action == "install":
|
||||
print("Installing saved extensions")
|
||||
for extension in get_saved_extensions(args.file):
|
||||
subprocess.run(["codium", "--install-extension", extension])
|
||||
elif args.action == "list":
|
||||
print("Listing installed extensions")
|
||||
print("\n".join(get_installed_extensions()))
|
||||
elif args.action == "list-saved":
|
||||
with open(args.file, "r") as file:
|
||||
print("Listing saved extensions")
|
||||
print(file.read())
|
||||
elif args.action == "save":
|
||||
with open(args.file, "w") as file:
|
||||
extensions = get_installed_extensions()
|
||||
file.writelines("\n".join(extensions))
|
||||
print(f"Wrote {len(extensions)} extensions to {args.file}")
|
||||
|
||||
|
||||
def get_installed_extensions() -> typing.List[str]:
|
||||
extensions = subprocess.run(
|
||||
[
|
||||
"codium",
|
||||
"--list-extensions",
|
||||
],
|
||||
capture_output=True,
|
||||
check=True,
|
||||
encoding="utf8",
|
||||
)
|
||||
return extensions.stdout.splitlines()
|
||||
|
||||
|
||||
def get_saved_extensions(path: str) -> typing.List[str]:
|
||||
with open(path, "r") as file:
|
||||
return file.read().splitlines()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue