Skip to content

Instantly share code, notes, and snippets.

@allefeld
Created January 13, 2026 08:48
Show Gist options
  • Select an option

  • Save allefeld/df65a9d74f48259cc09bc6c78ab2bafa to your computer and use it in GitHub Desktop.

Select an option

Save allefeld/df65a9d74f48259cc09bc6c78ab2bafa to your computer and use it in GitHub Desktop.
Better Quarto Preview for VS Code
{
"key": "ctrl+shift+k",
"command": "runCommands",
"args": {
"commands": [
{
"command": "workbench.action.tasks.runTask",
"args": "Better Quarto Preview"
},
"simpleBrowser.show"
]
},
"when": "editorTextFocus && editorLangId == 'quarto'"
}
{
"label": "Better Quarto Preview",
"type": "shell",
"command": "quarto-preview '${file}'",
"isBackground": true,
"presentation": {
"reveal": "always",
"panel": "dedicated",
"clear": true
},
"runOptions": {
"instanceLimit": 1,
"instancePolicy": "terminateOldest"
}
}
#!/bin/bash
# `quarto preview` wrapper to encode URLs
# for VS Code task
copied=false
quarto preview "$1" --no-browser --port 4242 2>&1 | \
while IFS= read -r line
do
echo "$line"
# remove escape sequences
line=$(echo "$line" | sed -r 's/\x1b\[[0-9;]*[mK]//g')
if ! $copied && [[ $line =~ http:(.*) ]]
then
# if there is an http URL, encode spaces and copy to clipboard
url="${BASH_REMATCH[1]}"
url="${url// /%20}" # replace spaces with %20
echo "http:$url" | xclip -selection clipboard
copied=true
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment