Skip to content

Instantly share code, notes, and snippets.

@sushidub
Last active August 19, 2021 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sushidub/ef901c7d49a71f50a8f6aa69fb5608e1 to your computer and use it in GitHub Desktop.
Save sushidub/ef901c7d49a71f50a8f6aa69fb5608e1 to your computer and use it in GitHub Desktop.
Convert a directory into a VSCode workspace from the macOS command line
#!/usr/bin/env bash
# Convert a directory into a VSCode workspace from the macOS command line
# Usage
# 1. `cd` into a directory containing all the files you'd like to capture within a VSCode workspace
# 2. run `$ MakeVSCodeWorkspace`
# 3. the command will print the following json snippet in a new .code-workspace file
# using the name of the current directory for both the name of the newly created workspace file
# and the 'path' value within
#
# {
# "folders": [
# {
# "path": "/Users/<username>/<current directory name>"
# }
# ]
# }
function MakeVSCodeWorkspace() {
directory=$(pwd)
echo "$directory"
folder=$(echo "${directory}" | sed 's/.*\///g');
echo "$folder"
printf "{\n\t\"folders\": [\n\t\t{\n\t\t\t\"path\": \"%s\"\n\t\t}\n\t]\n}" "$directory" >> "${folder}.code-workspace"
echo "Open ${folder}.code-workspace in VSCode now? [y|n]"
read -r RESPONSE
case $RESPONSE in
[y]* ) open "${folder}.code-workspace";;
[n]* ) echo > /dev/null 2>&1;;
* ) echo > /dev/null 2>&1;;
esac
}
export -f MakeVSCodeWorkspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment