install.ps1
· 3.2 KiB · PowerShell
Неформатований
<#
.SYNOPSIS
Install a curated list of VS Code extensions on Windows.
.DESCRIPTION
Installs the bundled extension list using the VS Code 'code' CLI.
Sets the current process's ExecutionPolicy to RemoteSigned (no machine-wide
change) so the script can run on a default Windows configuration.
.PARAMETER ProfileName
Optional VS Code profile name. If supplied, extensions are installed into
that profile. VS Code creates the profile if it doesn't already exist.
Quote names that contain spaces.
.EXAMPLE
PS> .\install.ps1
.EXAMPLE
PS> .\install.ps1 -ProfileName "WorkSetup"
.NOTES
If PowerShell refuses to run the file, invoke it as:
powershell -ExecutionPolicy Bypass -File .\install.ps1
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $false, Position = 0)]
[string]$ProfileName = ""
)
# Loosen execution policy for THIS process only (no persisted change).
try {
$current = Get-ExecutionPolicy -Scope Process -ErrorAction Stop
if ($current -in @('Restricted', 'AllSigned', 'Undefined')) {
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned -Force -ErrorAction Stop
}
} catch {
Write-Verbose ("Could not adjust process execution policy: {0}" -f $_.Exception.Message)
}
$ErrorActionPreference = 'Stop'
$Extensions = @(
'docker.docker',
'github.copilot-chat',
'github.github-vscode-theme',
'ms-vscode-remote.vscode-remote-extensionpack',
'pkief.material-icon-theme'
)
$codeCmd = Get-Command code -ErrorAction SilentlyContinue
if (-not $codeCmd) {
Write-Host ""
Write-Host "Error: the 'code' command is not on your PATH." -ForegroundColor Red
Write-Host " Install VS Code from https://code.visualstudio.com/ and make sure" -ForegroundColor Yellow
Write-Host ' "Add to PATH" was checked during setup, then re-open your terminal.' -ForegroundColor Yellow
exit 1
}
$extraArgs = @()
if (-not [string]::IsNullOrWhiteSpace($ProfileName)) {
$extraArgs += @('--profile', $ProfileName)
}
$header = "Installing $($Extensions.Count) extension(s)"
if ($ProfileName) { $header += " into profile '$ProfileName'" }
Write-Host ("{0}..." -f $header) -ForegroundColor Cyan
Write-Host ""
$installed = 0
$failed = 0
$failedList = @()
foreach ($ext in $Extensions) {
Write-Host -NoNewline (" -> {0,-55} " -f $ext)
try {
$output = & code @extraArgs --install-extension $ext --force 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host "ok" -ForegroundColor Green
$installed++
} else {
Write-Host "FAILED" -ForegroundColor Red
$failed++
$failedList += $ext
$output | ForEach-Object { Write-Host " $_" -ForegroundColor DarkRed }
}
} catch {
Write-Host "FAILED" -ForegroundColor Red
$failed++
$failedList += $ext
Write-Host (" {0}" -f $_.Exception.Message) -ForegroundColor DarkRed
}
}
Write-Host ""
Write-Host ("Done. Installed: {0}, Failed: {1}" -f $installed, $failed)
if ($failed -gt 0) {
Write-Host "Failed extensions:" -ForegroundColor Red
foreach ($f in $failedList) {
Write-Host (" - {0}" -f $f) -ForegroundColor Red
}
exit 1
}
| 1 | <# |
| 2 | .SYNOPSIS |
| 3 | Install a curated list of VS Code extensions on Windows. |
| 4 | |
| 5 | .DESCRIPTION |
| 6 | Installs the bundled extension list using the VS Code 'code' CLI. |
| 7 | Sets the current process's ExecutionPolicy to RemoteSigned (no machine-wide |
| 8 | change) so the script can run on a default Windows configuration. |
| 9 | |
| 10 | .PARAMETER ProfileName |
| 11 | Optional VS Code profile name. If supplied, extensions are installed into |
| 12 | that profile. VS Code creates the profile if it doesn't already exist. |
| 13 | Quote names that contain spaces. |
| 14 | |
| 15 | .EXAMPLE |
| 16 | PS> .\install.ps1 |
| 17 | |
| 18 | .EXAMPLE |
| 19 | PS> .\install.ps1 -ProfileName "WorkSetup" |
| 20 | |
| 21 | .NOTES |
| 22 | If PowerShell refuses to run the file, invoke it as: |
| 23 | powershell -ExecutionPolicy Bypass -File .\install.ps1 |
| 24 | #> |
| 25 | |
| 26 | [CmdletBinding()] |
| 27 | param( |
| 28 | [Parameter(Mandatory = $false, Position = 0)] |
| 29 | [string]$ProfileName = "" |
| 30 | ) |
| 31 | |
| 32 | # Loosen execution policy for THIS process only (no persisted change). |
| 33 | try { |
| 34 | $current = Get-ExecutionPolicy -Scope Process -ErrorAction Stop |
| 35 | if ($current -in @('Restricted', 'AllSigned', 'Undefined')) { |
| 36 | Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned -Force -ErrorAction Stop |
| 37 | } |
| 38 | } catch { |
| 39 | Write-Verbose ("Could not adjust process execution policy: {0}" -f $_.Exception.Message) |
| 40 | } |
| 41 | |
| 42 | $ErrorActionPreference = 'Stop' |
| 43 | |
| 44 | $Extensions = @( |
| 45 | 'docker.docker', |
| 46 | 'github.copilot-chat', |
| 47 | 'github.github-vscode-theme', |
| 48 | 'ms-vscode-remote.vscode-remote-extensionpack', |
| 49 | 'pkief.material-icon-theme' |
| 50 | ) |
| 51 | |
| 52 | $codeCmd = Get-Command code -ErrorAction SilentlyContinue |
| 53 | if (-not $codeCmd) { |
| 54 | Write-Host "" |
| 55 | Write-Host "Error: the 'code' command is not on your PATH." -ForegroundColor Red |
| 56 | Write-Host " Install VS Code from https://code.visualstudio.com/ and make sure" -ForegroundColor Yellow |
| 57 | Write-Host ' "Add to PATH" was checked during setup, then re-open your terminal.' -ForegroundColor Yellow |
| 58 | exit 1 |
| 59 | } |
| 60 | |
| 61 | $extraArgs = @() |
| 62 | if (-not [string]::IsNullOrWhiteSpace($ProfileName)) { |
| 63 | $extraArgs += @('--profile', $ProfileName) |
| 64 | } |
| 65 | |
| 66 | $header = "Installing $($Extensions.Count) extension(s)" |
| 67 | if ($ProfileName) { $header += " into profile '$ProfileName'" } |
| 68 | Write-Host ("{0}..." -f $header) -ForegroundColor Cyan |
| 69 | Write-Host "" |
| 70 | |
| 71 | $installed = 0 |
| 72 | $failed = 0 |
| 73 | $failedList = @() |
| 74 | |
| 75 | foreach ($ext in $Extensions) { |
| 76 | Write-Host -NoNewline (" -> {0,-55} " -f $ext) |
| 77 | try { |
| 78 | $output = & code @extraArgs --install-extension $ext --force 2>&1 |
| 79 | if ($LASTEXITCODE -eq 0) { |
| 80 | Write-Host "ok" -ForegroundColor Green |
| 81 | $installed++ |
| 82 | } else { |
| 83 | Write-Host "FAILED" -ForegroundColor Red |
| 84 | $failed++ |
| 85 | $failedList += $ext |
| 86 | $output | ForEach-Object { Write-Host " $_" -ForegroundColor DarkRed } |
| 87 | } |
| 88 | } catch { |
| 89 | Write-Host "FAILED" -ForegroundColor Red |
| 90 | $failed++ |
| 91 | $failedList += $ext |
| 92 | Write-Host (" {0}" -f $_.Exception.Message) -ForegroundColor DarkRed |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | Write-Host "" |
| 97 | Write-Host ("Done. Installed: {0}, Failed: {1}" -f $installed, $failed) |
| 98 | |
| 99 | if ($failed -gt 0) { |
| 100 | Write-Host "Failed extensions:" -ForegroundColor Red |
| 101 | foreach ($f in $failedList) { |
| 102 | Write-Host (" - {0}" -f $f) -ForegroundColor Red |
| 103 | } |
| 104 | exit 1 |
| 105 | } |
| 106 |
install.sh
· 2.7 KiB · Bash
Неформатований
#!/usr/bin/env bash
#
# VS Code extension installer for macOS and Linux (Ubuntu).
#
# Usage:
# ./install.sh # install into the default profile
# ./install.sh --profile "MyProfile" # install into a named profile
# ./install.sh --help
#
# If --profile is provided and the profile does not exist, VS Code creates
# it automatically. Quote names that contain spaces.
set -euo pipefail
IFS=$'\n\t'
readonly EXTENSIONS=(
"docker.docker"
"github.copilot-chat"
"github.github-vscode-theme"
"ms-vscode-remote.vscode-remote-extensionpack"
"pkief.material-icon-theme"
)
PROFILE=""
usage() {
cat <<EOF
Usage: $(basename "$0") [--profile "ProfileName"]
Installs a curated list of VS Code extensions on macOS or Linux.
Options:
-p, --profile <name> Install into the named VS Code profile.
VS Code creates the profile if it doesn't exist.
-h, --help Show this help and exit.
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
-p|--profile)
if [[ $# -lt 2 || -z "${2:-}" ]]; then
echo "Error: --profile requires a non-empty value." >&2
exit 2
fi
PROFILE="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Error: unknown argument '$1'." >&2
usage >&2
exit 2
;;
esac
done
OS="$(uname -s)"
case "$OS" in
Darwin|Linux) ;;
*)
echo "Error: unsupported OS '$OS'. Use install.ps1 on Windows." >&2
exit 1
;;
esac
if ! command -v code >/dev/null 2>&1; then
cat >&2 <<'EOF'
Error: the 'code' command is not on your PATH.
macOS: open VS Code, press Cmd+Shift+P, run
"Shell Command: Install 'code' command in PATH".
Linux: install VS Code from https://code.visualstudio.com/
(or: sudo snap install --classic code), then reopen your shell.
EOF
exit 1
fi
declare -a CODE_ARGS=()
if [[ -n "$PROFILE" ]]; then
CODE_ARGS+=("--profile" "$PROFILE")
fi
LOG_FILE="$(mktemp -t vscode-install.XXXXXX)"
trap 'rm -f "$LOG_FILE"' EXIT
header="Installing ${#EXTENSIONS[@]} extension(s)"
[[ -n "$PROFILE" ]] && header+=" into profile '$PROFILE'"
echo "$header..."
echo
installed=0
failed=0
declare -a FAILED_LIST=()
for ext in "${EXTENSIONS[@]}"; do
printf ' -> %-55s ' "$ext"
if code "${CODE_ARGS[@]}" --install-extension "$ext" --force >"$LOG_FILE" 2>&1; then
echo "ok"
installed=$((installed + 1))
else
echo "FAILED"
failed=$((failed + 1))
FAILED_LIST+=("$ext")
sed 's/^/ /' "$LOG_FILE" >&2 || true
fi
done
echo
echo "Done. Installed: ${installed}, Failed: ${failed}"
if (( failed > 0 )); then
echo "Failed extensions:" >&2
for f in "${FAILED_LIST[@]}"; do
echo " - $f" >&2
done
exit 1
fi
| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # VS Code extension installer for macOS and Linux (Ubuntu). |
| 4 | # |
| 5 | # Usage: |
| 6 | # ./install.sh # install into the default profile |
| 7 | # ./install.sh --profile "MyProfile" # install into a named profile |
| 8 | # ./install.sh --help |
| 9 | # |
| 10 | # If --profile is provided and the profile does not exist, VS Code creates |
| 11 | # it automatically. Quote names that contain spaces. |
| 12 | |
| 13 | set -euo pipefail |
| 14 | IFS=$'\n\t' |
| 15 | |
| 16 | readonly EXTENSIONS=( |
| 17 | "docker.docker" |
| 18 | "github.copilot-chat" |
| 19 | "github.github-vscode-theme" |
| 20 | "ms-vscode-remote.vscode-remote-extensionpack" |
| 21 | "pkief.material-icon-theme" |
| 22 | ) |
| 23 | |
| 24 | PROFILE="" |
| 25 | |
| 26 | usage() { |
| 27 | cat <<EOF |
| 28 | Usage: $(basename "$0") [--profile "ProfileName"] |
| 29 | |
| 30 | Installs a curated list of VS Code extensions on macOS or Linux. |
| 31 | |
| 32 | Options: |
| 33 | -p, --profile <name> Install into the named VS Code profile. |
| 34 | VS Code creates the profile if it doesn't exist. |
| 35 | -h, --help Show this help and exit. |
| 36 | EOF |
| 37 | } |
| 38 | |
| 39 | while [[ $# -gt 0 ]]; do |
| 40 | case "$1" in |
| 41 | -p|--profile) |
| 42 | if [[ $# -lt 2 || -z "${2:-}" ]]; then |
| 43 | echo "Error: --profile requires a non-empty value." >&2 |
| 44 | exit 2 |
| 45 | fi |
| 46 | PROFILE="$2" |
| 47 | shift 2 |
| 48 | ;; |
| 49 | -h|--help) |
| 50 | usage |
| 51 | exit 0 |
| 52 | ;; |
| 53 | *) |
| 54 | echo "Error: unknown argument '$1'." >&2 |
| 55 | usage >&2 |
| 56 | exit 2 |
| 57 | ;; |
| 58 | esac |
| 59 | done |
| 60 | |
| 61 | OS="$(uname -s)" |
| 62 | case "$OS" in |
| 63 | Darwin|Linux) ;; |
| 64 | *) |
| 65 | echo "Error: unsupported OS '$OS'. Use install.ps1 on Windows." >&2 |
| 66 | exit 1 |
| 67 | ;; |
| 68 | esac |
| 69 | |
| 70 | if ! command -v code >/dev/null 2>&1; then |
| 71 | cat >&2 <<'EOF' |
| 72 | Error: the 'code' command is not on your PATH. |
| 73 | |
| 74 | macOS: open VS Code, press Cmd+Shift+P, run |
| 75 | "Shell Command: Install 'code' command in PATH". |
| 76 | Linux: install VS Code from https://code.visualstudio.com/ |
| 77 | (or: sudo snap install --classic code), then reopen your shell. |
| 78 | EOF |
| 79 | exit 1 |
| 80 | fi |
| 81 | |
| 82 | declare -a CODE_ARGS=() |
| 83 | if [[ -n "$PROFILE" ]]; then |
| 84 | CODE_ARGS+=("--profile" "$PROFILE") |
| 85 | fi |
| 86 | |
| 87 | LOG_FILE="$(mktemp -t vscode-install.XXXXXX)" |
| 88 | trap 'rm -f "$LOG_FILE"' EXIT |
| 89 | |
| 90 | header="Installing ${#EXTENSIONS[@]} extension(s)" |
| 91 | [[ -n "$PROFILE" ]] && header+=" into profile '$PROFILE'" |
| 92 | echo "$header..." |
| 93 | echo |
| 94 | |
| 95 | installed=0 |
| 96 | failed=0 |
| 97 | declare -a FAILED_LIST=() |
| 98 | |
| 99 | for ext in "${EXTENSIONS[@]}"; do |
| 100 | printf ' -> %-55s ' "$ext" |
| 101 | if code "${CODE_ARGS[@]}" --install-extension "$ext" --force >"$LOG_FILE" 2>&1; then |
| 102 | echo "ok" |
| 103 | installed=$((installed + 1)) |
| 104 | else |
| 105 | echo "FAILED" |
| 106 | failed=$((failed + 1)) |
| 107 | FAILED_LIST+=("$ext") |
| 108 | sed 's/^/ /' "$LOG_FILE" >&2 || true |
| 109 | fi |
| 110 | done |
| 111 | |
| 112 | echo |
| 113 | echo "Done. Installed: ${installed}, Failed: ${failed}" |
| 114 | |
| 115 | if (( failed > 0 )); then |
| 116 | echo "Failed extensions:" >&2 |
| 117 | for f in "${FAILED_LIST[@]}"; do |
| 118 | echo " - $f" >&2 |
| 119 | done |
| 120 | exit 1 |
| 121 | fi |
| 122 |