Last active
August 24, 2022 23:20
-
-
Save vmiheer/60eff7feee0e6725ef8ac1b7cacaae5a to your computer and use it in GitHub Desktop.
Split command to array to plug in vscode launch.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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