-
-
Save graezykev/b7c981c4966d49e580cf1fddc0c52559 to your computer and use it in GitHub Desktop.
Install VS Code CLI. Detect OS and ARCH automatically.
This file contains 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
#!/bin/bash | |
# To run this on Windows, install Cygwin or MSYS2 or any other Unix-like shell environment | |
# Detect OS | |
OS="$(uname -s)" | |
ARCH="$(uname -m)" | |
# Determine the download URL based on OS and architecture | |
case "$OS" in | |
Linux*) | |
case "$ARCH" in | |
x86_64) | |
URL="https://update.code.visualstudio.com/latest/linux-deb-x64/stable" | |
;; | |
arm64) | |
URL="https://update.code.visualstudio.com/latest/linux-deb-arm64/stable" | |
;; | |
arm*) | |
URL="https://update.code.visualstudio.com/latest/linux-deb-armhf/stable" | |
;; | |
*) | |
echo "Unsupported architecture: $ARCH" | |
exit 1 | |
;; | |
esac | |
;; | |
Darwin*) | |
case "$ARCH" in | |
x86_64) | |
URL="https://update.code.visualstudio.com/latest/darwin/stable" | |
;; | |
arm64) | |
URL="https://update.code.visualstudio.com/latest/darwin-arm64/stable" | |
;; | |
*) | |
echo "Unsupported architecture: $ARCH" | |
exit 1 | |
;; | |
esac | |
;; | |
MINGW*|MSYS*|CYGWIN*) | |
case "$ARCH" in | |
x86_64) | |
URL="https://update.code.visualstudio.com/latest/win32-x64-user/stable" | |
;; | |
arm64) | |
URL="https://update.code.visualstudio.com/latest/win32-arm64-user/stable" | |
;; | |
*) | |
echo "Unsupported architecture: $ARCH" | |
exit 1 | |
;; | |
esac | |
;; | |
*) | |
echo "Unsupported OS: $OS" | |
exit 1 | |
;; | |
esac | |
# Download and install | |
TEMP_FILE="$(mktemp)" | |
curl -Lo "$TEMP_FILE" "$URL" | |
if [ "$OS" = "Linux" ]; then | |
sudo dpkg -i "$TEMP_FILE" | |
elif [ "$OS" = "Darwin" ]; then | |
hdiutil attach "$TEMP_FILE" | |
cp -R "/Volumes/Visual Studio Code/Visual Studio Code.app" /Applications | |
hdiutil detach "/Volumes/Visual Studio Code" | |
elif [[ "$OS" == "MINGW"* || "$OS" == "MSYS"* || "$OS" == "CYGWIN"* ]]; then | |
POWERSHELL_CMD="Start-Process -FilePath $TEMP_FILE -ArgumentList '/silent /verysilent /suppressmsgboxes /norestart' -Wait" | |
powershell.exe -Command "$POWERSHELL_CMD" | |
fi | |
rm -f "$TEMP_FILE" | |
# Install VS Code CLI | |
if [ "$OS" = "Linux" ]; then | |
sudo ln -s /usr/share/code/bin/code /usr/local/bin/code | |
elif [ "$OS" = "Darwin" ]; then | |
ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/code | |
elif [[ "$OS" == "MINGW"* || "$OS" == "MSYS"* || "$OS" == "CYGWIN"* ]]; then | |
CODE_PATH="/c/Users/$(whoami)/AppData/Local/Programs/Microsoft VS Code/bin/code" | |
if [ -f "$CODE_PATH" ]; then | |
ln -s "$CODE_PATH" "/usr/local/bin/code" | |
else | |
echo "VS Code CLI installation path not found. Please ensure VS Code is installed." | |
fi | |
fi | |
echo "VS Code CLI installation complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment