Skip to content

Instantly share code, notes, and snippets.

@vmiheer
Last active August 24, 2022 23:20
Show Gist options
  • Save vmiheer/60eff7feee0e6725ef8ac1b7cacaae5a to your computer and use it in GitHub Desktop.
Save vmiheer/60eff7feee0e6725ef8ac1b7cacaae5a to your computer and use it in GitHub Desktop.
Split command to array to plug in vscode launch.json
#!/usr/bin/env python3
import shlex
import shutil
import sys
import os
import os.path
from pathlib import Path
args = shlex.split(sys.argv[1])
prog = Path(os.path.expanduser(str(args[0])))
if not prog.is_file():
found_prog = shutil.which(str(prog))
if found_prog:
prog = found_prog
else: prog = ""
prog = str(prog)
args = [f"\"{x}\"" for x in args]
str = "\"args\": [{}],".format(", ".join(args[1:])) + \
"\n\"cwd\": \"{}\",".format(os.getcwd()) + f"\n\"program\": \"{prog}\","
try:
import pyperclip
pyperclip.copy(str)
except ImportError:
print("Consider: `pip install pyperclip`")
print(str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment