Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export Installed Visual Studio Code Extensions in a Form of Installation Script
#!/usr/bin/env zsh
#
# This script generates and writes to file another bash-script (output_script)
# that implements "vscodeInstallExtensions" function which installs all
# Visual Studio Code extensions that were originally installed on your machine
# at the moment of generation output_script by running
# "vscodeUpdateExtensionsInstallationScript" function that is implemented here below.
#
# # How to use
#
# 0. Edit SCRIPT_PATH specifying the directory you want to generate output_script in.
# Optionally you can change "OUTPUT_FILE_NAME" specifying the name of output_script.
# Don't forget that "OUTPUT_FILE_NAME" should match "*.sh\" name format
#
# 1. source the script in your terminal:
# ``` bash
# source "./updateVSCodeExtensionsInstallationScript.sh"
# ```
#
# 2. source the generated script:
# ``` bash
# source "$SCRIPT_PATH/OUTPUT_FILE_NAME"
# ```
#
# 3. To install your extensions run:
# ``` bash
# vscodeInstallExtensions
# ```
SCRIPT_PATH="$zshConfig/VSCode"
OUTPUT_FILE_NAME="$installVSCodeExtensionsAction"
INSTALLATION_COMMAND_FOR_ONE_EXTENSION=""
SCRIPT_BODY=""
vscodeUpdateExtensionsInstallationScript(){
interpreterRef="#!/usr/bin/env zsh"
updateTimeInfo="\# Last updated on:\n\# "`date`
composeScriptBody
installationFunctionName="vscodeInstallExtensions"
resultScript="${interpreterRef} \n\n${updateTimeInfo} \n\n${installationFunctionName}() \{$SCRIPT_BODY\n\}"
print "$resultScript" > "${SCRIPT_PATH}/${OUTPUT_FILE_NAME}"
print "InstallationScript of VSCodeExtensions updated successfully."
print
print "To check the output file, run"
print "cat $SCRIPT_PATH/$OUTPUT_FILE_NAME"
}
composeScriptBody(){
scriptBody=""
scriptBodySuffix="; print \"\\\n\""
for extension in `code --list-extensions`
do
composeInstallationCommandForOneExtension $extension
scriptBody="${scriptBody}\n ${INSTALLATION_COMMAND_FOR_ONE_EXTENSION}${scriptBodySuffix}"
done
scriptBody="${scriptBody%$scriptBodySuffix}"
SCRIPT_BODY="$scriptBody"
}
composeInstallationCommandForOneExtension(){
installationCommandPrefix="code --install-extension "
extension="$1"
command="${installationCommandPrefix}${extension}"
INSTALLATION_COMMAND_FOR_ONE_EXTENSION="$command"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment