simplify/complicate vscode ext wrapper

This commit is contained in:
Daylin Morgan 2022-08-05 11:42:07 -05:00
parent fcdc946511
commit 641227a316
7 changed files with 259 additions and 232 deletions

View File

@ -1,43 +0,0 @@
general:
- ms-vscode-remote.remote-ssh
- ms-vscode-remote.remote-ssh-edit
- ms-vscode-remote.remote-wsl
- vscodevim.vim
misc-tools:
- Shan.code-settings-sync
- janisdd.vscode-edit-csv
- cssho.vscode-svgviewer
- naumovs.color-highlight
- antfu.slidev
web-dev:
- bradlc.vscode-tailwindcss
- ritwickdey.liveserver
styling:
- johnpapa.vscode-peacock
- PKief.material-icon-theme
- Thomaz.preparing
- dracula-theme.theme-dracula
code-help:
- christian-kohler.path-intellisense
- aaron-bond.better-comments
- streetsidesoftware.code-spell-checker
- vsls-contrib.gistfs
- mhutchie.git-graph
- Github.copilot
python:
- ms-python.python
- ms-toolsai.jupyter
- njpwerner.autodocstring
- snakemake.snakemake-lang
language-support:
- lextudio.restructuredtext
- Ikuyadeu.r
- James-Yu.latex-workshop
- budparr.language-hugo-vscode
- tht13.rst-vscode
- skellock.just
- neilding.language-liquid
- snakemake.snakemake-lang
- voorjaar.windicss-intellisense
- eww-yuck.yuck
- bungcip.better-toml

View File

@ -1,66 +0,0 @@
import yaml
from pathlib import Path
FRONTMATTER = """
VS Code Extensions install script
Author: Daylin Morgan
DO NOT EDIT MANUALLY!
Regenerate with generate_install_scripts.py
"""
FILE_DIR = Path(__file__).parent
def shell_script_writer(extensions_dict, filename):
with Path(filename).open("w") as f:
f.write("#!/bin/bash\n")
f.write(FRONTMATTER.replace("\n", "\n# ")[:-2])
f.write('\n\necho "Installing VS Code Extensions"\n')
for section, extensions in extensions_dict.items():
f.write(f"\n# {section} extensions")
f.write("\n# " + "-" * len(section) + "-" * 11)
for extension in extensions:
f.write(f"\ncode --install-extension {extension} --force")
f.write("\n")
f.write('\necho "Extension installation compeleted!"')
def batch_script_writer(extensions_dict, filename):
with Path(filename).open("w") as f:
f.write("echo off\n")
f.write(FRONTMATTER.replace("\n", "\n:: ")[:-3])
f.write('\n\necho "Installing VS Code Extensions"\necho.\n')
for section, extensions in extensions_dict.items():
f.write(f"\n:: {section} extensions")
f.write("\n:: " + "-" * len(section) + "-" * 11)
for extension in extensions:
f.write(f"\ncall code --install-extension {extension} --force")
f.write("\n")
f.write('\necho "Extension installation compeleted!"')
def main():
print("Generating shell and batch scripts with extensions.yml")
extensions_yml = FILE_DIR / "extensions.yml"
with extensions_yml.open("r") as f:
extensions_dict = yaml.load(f, Loader=yaml.FullLoader)
shell_script_writer(extensions_dict, "install-extensions.sh")
batch_script_writer(extensions_dict, "install-extensions.bat")
if __name__ == "__main__":
main()

View File

@ -1,45 +0,0 @@
#!/usr/bin/env bash
YAMLDOC="extensions.yml"
# check for yq
if ! command -v yq &>/dev/null; then
echo "yq could not be found"
echo "to install w/ eget"
echo "eget mikefarah/yq"
exit
fi
readarray sections < <(yq e 'keys | .[]' $YAMLDOC)
get_extensions() {
for section in "${sections[@]}"; do
echo $section
readarray exts < <(key=$section yq e '.[env(key)] | .[]' $YAMLDOC)
echo ${exts[@]}
for ext in "${exts[@]}"; do
write_bat $ext
write_sh $ext
done
done
}
write_bat() {
echo "call code --install-extension $1 --force" >>install-extensions.bat
}
write_sh() {
echo "code --install-extension $1 --force" >>install-extensions.sh
}
# clean up old files
rm -f install-extensions.{sh,bat}
echo "echo off" >install-extensions.bat
echo >>install-extensions.bat
echo "echo Installing VSCode extensions" >>install-extensions.bat
echo "#!/usr/bin/env bash" >install-extensions.sh
echo >>install-extensions.sh
echo "echo Installing VSCode extensions" >>install-extensions.sh
# read extensions and write install scripts
get_extensions

View File

@ -1,39 +0,0 @@
echo off
echo Installing VSCode extensions
call code --install-extension ms-vscode-remote.remote-ssh --force
call code --install-extension ms-vscode-remote.remote-ssh-edit --force
call code --install-extension ms-vscode-remote.remote-wsl --force
call code --install-extension vscodevim.vim --force
call code --install-extension Shan.code-settings-sync --force
call code --install-extension janisdd.vscode-edit-csv --force
call code --install-extension cssho.vscode-svgviewer --force
call code --install-extension naumovs.color-highlight --force
call code --install-extension antfu.slidev --force
call code --install-extension bradlc.vscode-tailwindcss --force
call code --install-extension ritwickdey.liveserver --force
call code --install-extension johnpapa.vscode-peacock --force
call code --install-extension PKief.material-icon-theme --force
call code --install-extension Thomaz.preparing --force
call code --install-extension dracula-theme.theme-dracula --force
call code --install-extension christian-kohler.path-intellisense --force
call code --install-extension aaron-bond.better-comments --force
call code --install-extension streetsidesoftware.code-spell-checker --force
call code --install-extension vsls-contrib.gistfs --force
call code --install-extension mhutchie.git-graph --force
call code --install-extension Github.copilot --force
call code --install-extension ms-python.python --force
call code --install-extension ms-toolsai.jupyter --force
call code --install-extension njpwerner.autodocstring --force
call code --install-extension snakemake.snakemake-lang --force
call code --install-extension lextudio.restructuredtext --force
call code --install-extension Ikuyadeu.r --force
call code --install-extension James-Yu.latex-workshop --force
call code --install-extension budparr.language-hugo-vscode --force
call code --install-extension tht13.rst-vscode --force
call code --install-extension skellock.just --force
call code --install-extension neilding.language-liquid --force
call code --install-extension snakemake.snakemake-lang --force
call code --install-extension voorjaar.windicss-intellisense --force
call code --install-extension eww-yuck.yuck --force
call code --install-extension bungcip.better-toml --force

View File

@ -1,39 +0,0 @@
#!/usr/bin/env bash
echo Installing VSCode extensions
code --install-extension ms-vscode-remote.remote-ssh --force
code --install-extension ms-vscode-remote.remote-ssh-edit --force
code --install-extension ms-vscode-remote.remote-wsl --force
code --install-extension vscodevim.vim --force
code --install-extension Shan.code-settings-sync --force
code --install-extension janisdd.vscode-edit-csv --force
code --install-extension cssho.vscode-svgviewer --force
code --install-extension naumovs.color-highlight --force
code --install-extension antfu.slidev --force
code --install-extension bradlc.vscode-tailwindcss --force
code --install-extension ritwickdey.liveserver --force
code --install-extension johnpapa.vscode-peacock --force
code --install-extension PKief.material-icon-theme --force
code --install-extension Thomaz.preparing --force
code --install-extension dracula-theme.theme-dracula --force
code --install-extension christian-kohler.path-intellisense --force
code --install-extension aaron-bond.better-comments --force
code --install-extension streetsidesoftware.code-spell-checker --force
code --install-extension vsls-contrib.gistfs --force
code --install-extension mhutchie.git-graph --force
code --install-extension Github.copilot --force
code --install-extension ms-python.python --force
code --install-extension ms-toolsai.jupyter --force
code --install-extension njpwerner.autodocstring --force
code --install-extension snakemake.snakemake-lang --force
code --install-extension lextudio.restructuredtext --force
code --install-extension Ikuyadeu.r --force
code --install-extension James-Yu.latex-workshop --force
code --install-extension budparr.language-hugo-vscode --force
code --install-extension tht13.rst-vscode --force
code --install-extension skellock.just --force
code --install-extension neilding.language-liquid --force
code --install-extension snakemake.snakemake-lang --force
code --install-extension voorjaar.windicss-intellisense --force
code --install-extension eww-yuck.yuck --force
code --install-extension bungcip.better-toml --force

53
vscode/spec.md Normal file
View File

@ -0,0 +1,53 @@
# VS Code Extensions
## general
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode-remote.remote-wsl
vscodevim.vim
## misc-tools
Shan.code-settings-sync
janisdd.vscode-edit-csv
naumovs.color-highlight
davidhouchin.whitespace-plus
dlasagno.rasi
antfu.slidev
## web-dev
bradlc.vscode-tailwindcss
ritwickdey.liveserver
esbenp.prettier-vscode
## styling
johnpapa.vscode-peacock
PKief.material-icon-theme
Thomaz.preparing
catppuccin.catppuccin-vsc
## code-help
metaseed.metajump
christian-kohler.path-intellisense
aaron-bond.better-comments
streetsidesoftware.code-spell-checker
eamodio.gitlens
vsls-contrib.gistfs
mhutchie.git-graph
## python
ms-python.python
ms-toolsai.jupyter
ms-python.vscode-pylance
ms-toolsai.jupyter-keymap
ms-toolsai.jupyter-renderers
njpwerner.autodocstring
quarto.quarto
## language-support
budparr.language-hugo-vscode
skellock.just
snakemake.snakemake-lang
voorjaar.windicss-intellisense
eww-yuck.yuck
bungcip.better-toml

206
vscode/vsext Executable file
View File

@ -0,0 +1,206 @@
#!/usr/bin/env python3
import argparse
import shlex
import subprocess
import sys
from pathlib import Path
from shutil import which
def is_tool(name):
"""Check whether `name` is on PATH and marked as executable."""
if not which(name):
print(f"ERROR: {name} is not found in your PATH")
sys.exit(1)
def run(cmd, capture=True, returncode=False):
result = subprocess.run(
shlex.split(cmd),
stdout=subprocess.PIPE if capture else None,
text=True,
shell=False,
)
if returncode:
return result.returncode
elif capture:
return result.stdout.strip()
class Gum:
def __init__(self):
is_tool("gum")
def confirm(self, question):
return not run(
"gum confirm "
"--selected.bold "
"--selected.background 11 "
"--selected.foreground 8 "
f"'{question}'",
returncode=True,
)
def color(self, text, color):
return run(f'gum style --foreground {color} "{text}"')
def header(self, text, color=11):
run(
"gum style "
"--foreground 212 --border-foreground 212 --border rounded "
'--align center --width 30 --margin "1 4" '
f"'{self.color(text,color)}'",
capture=False,
)
def choose(self, options):
if isinstance(options, str):
options = options.split("")
if isinstance(options, list):
options = "".join([f"'{i}'" for i in options])
return run(f"gum choose {options}")
def input(self, placeholder, value):
run(
"gum input" + f"--placeholder {placeholder}"
if placeholder
else "" + f"--value {value}"
if value
else ""
)
def spinner(self, placeholder, cmd):
run(f"gum spin -s points --title '{placeholder}'" + cmd)
gum = Gum()
def pprint(text, color):
print(gum.color(text, color))
def parse_exts(mdfile):
with Path(mdfile).open("r") as f:
md = f.read()
md = md.split("##")[1:]
exts = {}
all = []
for section in md:
head = section.splitlines()[0].strip()
exts[head] = []
for line in section.splitlines()[1:]:
if line == "":
continue
exts[head].append(line.strip())
all.append(line.strip())
return exts, sorted(all)
class SubcommandHelpFormatter(argparse.RawDescriptionHelpFormatter):
def _format_action(self, action):
parts = super(argparse.RawDescriptionHelpFormatter, self)._format_action(action)
if action.nargs == argparse.PARSER:
parts = "\n".join(parts.split("\n")[1:])
return parts
def get_args():
p = argparse.ArgumentParser(formatter_class=SubcommandHelpFormatter)
sp = p.add_subparsers(title="commands", metavar="", dest="command",required=True)
check = sp.add_parser(
"check",
help="check the extensions which have already been installed",
aliases = ['c']
)
install = sp.add_parser(
"install",
help="install the extensions from the spec",
aliases =['i']
)
install.add_argument(
"-f", "--force", help="force the installation of exts", action="store_true"
)
remove = sp.add_parser(
"remove",
help="remove all extra packages",
aliases = ['r']
)
p.add_argument(
"-s",
"--spec",
help="mardown spec list (default ~/.dotfiles/vscode/spec.md)",
default=Path.home() / ".dotfiles" / "vscode" / "spec.md",
)
if len(sys.argv) < 2:
# p.print_usage()
p.print_help()
sys.exit(1)
return p.parse_args()
def get_extra_exts(spec, installed):
# sanitize lists
spec = [ext.lower() for ext in spec]
installed = [ext.lower() for ext in installed]
return [ext for ext in spec if ext not in installed], [
ext for ext in installed if ext not in spec
]
def code(flag, exts, force=False):
cmd = "code " + " ".join([f"{flag} {ext}" for ext in exts])
if force:
cmd +=" --force"
run(cmd, capture=False)
def main():
args = get_args()
gum.header("VS Code Extensions Installer")
spec_sections, spec_list = parse_exts(args.spec)
not_installed, extra_installed = get_extra_exts(
spec_list, run("code --list-extensions").splitlines()
)
if args.command == "check" or args.command == "c":
for head, exts in spec_sections.items():
pprint(f"## {head}", 11)
for ext in exts:
if ext.lower() in not_installed:
pprint(ext, 9)
else:
print(ext)
if extra_installed:
pprint("\nExtra installed extensions:", 11)
print("\n".join(extra_installed))
elif args.command == "install" or args.command =='i':
pprint("Installing extensions from spec list", 11)
code("--install-extension", spec_list, args.force)
elif args.command == "remove" or args.command == "r":
pprint("Removing extensions I don't know about", 11)
print("\n".join(extra_installed) + "\n")
if gum.confirm(f"Remove the above {len(extra_installed)} packages"):
print("bye bye packages")
code("--uninstall-extension", extra_installed)
if __name__ == "__main__":
main()