weehong a révisé ce gist 2 months ago. Aller à la révision
2 files changed, 69 insertions, 23 deletions
README.md
| @@ -21,6 +21,9 @@ Replace `<GIST>` with the raw base of this Gist (everything up to and including | |||
| 21 | 21 | # macOS / Ubuntu (default profile) | |
| 22 | 22 | curl -sSL https://opengist.rmrf.online/weehong/b2a7c0a2ae6d40e8a14f8d85964a9186/raw/HEAD/install.sh | bash | |
| 23 | 23 | ||
| 24 | + | # Install recommendation plugin to a specific profile | |
| 25 | + | ./install.sh -p "Frontend-Stack" -f "https://opengist.rmrf.online/weehong/b2a7c0a2ae6d40e8a14f8d85964a9186/raw/HEAD/typescript_react_recommendation.json" | |
| 26 | + | ||
| 24 | 27 | # named profile | |
| 25 | 28 | bash <(curl -sSL https://opengist.rmrf.online/weehong/b2a7c0a2ae6d40e8a14f8d85964a9186/raw/HEAD/install.sh) --profile "WorkSetup" | |
| 26 | 29 | ``` | |
install.sh
| @@ -3,34 +3,27 @@ | |||
| 3 | 3 | # VS Code extension installer for macOS and Linux (Ubuntu). | |
| 4 | 4 | # | |
| 5 | 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. | |
| 6 | + | # ./install.sh # looks for .vscode/extensions.json | |
| 7 | + | # ./install.sh -f extensions.json # specify a local JSON file | |
| 8 | + | # ./install.sh -f https://link-to-your/ext.json # specify a remote URL directly | |
| 9 | + | # ./install.sh -p "MyProfile" -f <source> # install into a named profile | |
| 12 | 10 | ||
| 13 | 11 | set -euo pipefail | |
| 14 | 12 | IFS=$'\n\t' | |
| 15 | 13 | ||
| 16 | - | readonly EXTENSIONS=( | |
| 17 | - | "docker.docker" | |
| 18 | - | "github.github-vscode-theme" | |
| 19 | - | "ms-vscode-remote.vscode-remote-extensionpack" | |
| 20 | - | "pkief.material-icon-theme" | |
| 21 | - | ) | |
| 22 | - | ||
| 23 | 14 | PROFILE="" | |
| 15 | + | SOURCE="" | |
| 24 | 16 | ||
| 25 | 17 | usage() { | |
| 26 | 18 | cat <<EOF | |
| 27 | - | Usage: $(basename "$0") [--profile "ProfileName"] | |
| 19 | + | Usage: $(basename "$0") [--profile "ProfileName"] [--file "extensions.json" | "https://..."] | |
| 28 | 20 | ||
| 29 | - | Installs a curated list of VS Code extensions on macOS or Linux. | |
| 21 | + | Installs a curated list of VS Code extensions on macOS or Linux from a local JSON file or URL. | |
| 30 | 22 | ||
| 31 | 23 | Options: | |
| 32 | 24 | -p, --profile <name> Install into the named VS Code profile. | |
| 33 | - | VS Code creates the profile if it doesn't exist. | |
| 25 | + | -f, --file <path/url> Path or URL to the JSON file containing recommendations. | |
| 26 | + | Defaults to .vscode/extensions.json if it exists. | |
| 34 | 27 | -h, --help Show this help and exit. | |
| 35 | 28 | EOF | |
| 36 | 29 | } | |
| @@ -45,6 +38,14 @@ while [[ $# -gt 0 ]]; do | |||
| 45 | 38 | PROFILE="$2" | |
| 46 | 39 | shift 2 | |
| 47 | 40 | ;; | |
| 41 | + | -f|--file) | |
| 42 | + | if [[ $# -lt 2 || -z "${2:-}" ]]; then | |
| 43 | + | echo "Error: --file requires a non-empty value." >&2 | |
| 44 | + | exit 2 | |
| 45 | + | fi | |
| 46 | + | SOURCE="$2" | |
| 47 | + | shift 2 | |
| 48 | + | ;; | |
| 48 | 49 | -h|--help) | |
| 49 | 50 | usage | |
| 50 | 51 | exit 0 | |
| @@ -66,25 +67,65 @@ case "$OS" in | |||
| 66 | 67 | ;; | |
| 67 | 68 | esac | |
| 68 | 69 | ||
| 70 | + | # 1. Check for 'code' command | |
| 69 | 71 | if ! command -v code >/dev/null 2>&1; then | |
| 70 | 72 | cat >&2 <<'EOF' | |
| 71 | 73 | Error: the 'code' command is not on your PATH. | |
| 72 | - | ||
| 73 | - | macOS: open VS Code, press Cmd+Shift+P, run | |
| 74 | - | "Shell Command: Install 'code' command in PATH". | |
| 75 | - | Linux: install VS Code from https://code.visualstudio.com/ | |
| 76 | - | (or: sudo snap install --classic code), then reopen your shell. | |
| 77 | 74 | EOF | |
| 78 | 75 | exit 1 | |
| 79 | 76 | fi | |
| 80 | 77 | ||
| 78 | + | # 2. Check for 'jq' command | |
| 79 | + | if ! command -v jq >/dev/null 2>&1; then | |
| 80 | + | echo "Error: 'jq' is not installed. (Ubuntu: sudo apt-get install jq)" >&2 | |
| 81 | + | exit 1 | |
| 82 | + | fi | |
| 83 | + | ||
| 84 | + | # 3. Resolve JSON Source (Local File vs URL) | |
| 85 | + | JSON_FILE="" | |
| 86 | + | TEMP_JSON_FILE="" | |
| 87 | + | ||
| 88 | + | if [[ -z "$SOURCE" ]]; then | |
| 89 | + | if [[ -f ".vscode/extensions.json" ]]; then | |
| 90 | + | JSON_FILE=".vscode/extensions.json" | |
| 91 | + | else | |
| 92 | + | echo "Error: No JSON file specified and .vscode/extensions.json not found." >&2 | |
| 93 | + | usage >&2 | |
| 94 | + | exit 2 | |
| 95 | + | fi | |
| 96 | + | elif [[ "$SOURCE" =~ ^https?:// ]]; then | |
| 97 | + | if ! command -v curl >/dev/null 2>&1; then | |
| 98 | + | echo "Error: 'curl' is required to download remote JSON files." >&2 | |
| 99 | + | exit 1 | |
| 100 | + | fi | |
| 101 | + | echo "Downloading JSON from URL..." | |
| 102 | + | JSON_FILE="$(mktemp -t vscode-json.XXXXXX)" | |
| 103 | + | TEMP_JSON_FILE="$JSON_FILE" | |
| 104 | + | curl -sSL "$SOURCE" -o "$JSON_FILE" | |
| 105 | + | else | |
| 106 | + | JSON_FILE="$SOURCE" | |
| 107 | + | if [[ ! -f "$JSON_FILE" ]]; then | |
| 108 | + | echo "Error: File '$JSON_FILE' does not exist." >&2 | |
| 109 | + | exit 1 | |
| 110 | + | fi | |
| 111 | + | fi | |
| 112 | + | ||
| 113 | + | # 4. Extract extensions from JSON using jq | |
| 114 | + | mapfile -t EXTENSIONS < <(jq -r '.recommendations[]?' "$JSON_FILE") | |
| 115 | + | ||
| 116 | + | if [[ ${#EXTENSIONS[@]} -eq 0 ]]; then | |
| 117 | + | echo "Error: No extensions found under the 'recommendations' key." >&2 | |
| 118 | + | exit 1 | |
| 119 | + | fi | |
| 120 | + | ||
| 81 | 121 | declare -a CODE_ARGS=() | |
| 82 | 122 | if [[ -n "$PROFILE" ]]; then | |
| 83 | 123 | CODE_ARGS+=("--profile" "$PROFILE") | |
| 84 | 124 | fi | |
| 85 | 125 | ||
| 126 | + | # Trap to clean up logs and temporary downloaded JSON files | |
| 86 | 127 | LOG_FILE="$(mktemp -t vscode-install.XXXXXX)" | |
| 87 | - | trap 'rm -f "$LOG_FILE"' EXIT | |
| 128 | + | trap 'rm -f "$LOG_FILE" $TEMP_JSON_FILE' EXIT | |
| 88 | 129 | ||
| 89 | 130 | header="Installing ${#EXTENSIONS[@]} extension(s)" | |
| 90 | 131 | [[ -n "$PROFILE" ]] && header+=" into profile '$PROFILE'" | |
| @@ -96,6 +137,8 @@ failed=0 | |||
| 96 | 137 | declare -a FAILED_LIST=() | |
| 97 | 138 | ||
| 98 | 139 | for ext in "${EXTENSIONS[@]}"; do | |
| 140 | + | [[ -z "$ext" ]] && continue | |
| 141 | + | ||
| 99 | 142 | printf ' -> %-55s ' "$ext" | |
| 100 | 143 | if code "${CODE_ARGS[@]}" --install-extension "$ext" --force >"$LOG_FILE" 2>&1; then | |
| 101 | 144 | echo "ok" | |
| @@ -117,4 +160,4 @@ if (( failed > 0 )); then | |||
| 117 | 160 | echo " - $f" >&2 | |
| 118 | 161 | done | |
| 119 | 162 | exit 1 | |
| 120 | - | fi | |
| 163 | + | fi | |
weehong a révisé ce gist 2 months ago. Aller à la révision
1 file changed, 20 insertions
typescript_react_recommendation.json(fichier créé)
| @@ -0,0 +1,20 @@ | |||
| 1 | + | { | |
| 2 | + | "recommendations": [ | |
| 3 | + | "dsznajder.es7-react-js-snippets", | |
| 4 | + | "planbcoding.vscode-react-refactor", | |
| 5 | + | "bradlc.vscode-tailwindcss", | |
| 6 | + | "WallabyJs.console-ninja", | |
| 7 | + | "ms-vscode.vscode-typescript-next", | |
| 8 | + | "yoavbls.pretty-ts-errors", | |
| 9 | + | "christian-kohler.path-intellisense", | |
| 10 | + | "christian-kohler.npm-intellisense", | |
| 11 | + | "dbaeumer.vscode-eslint", | |
| 12 | + | "esbenp.prettier-vscode", | |
| 13 | + | "usernamehw.errorlens", | |
| 14 | + | "eamodio.gitlens", | |
| 15 | + | "rangav.vscode-thunder-client", | |
| 16 | + | "formulahendry.auto-rename-tag", | |
| 17 | + | "GitHub.copilot", | |
| 18 | + | "Codeium.codeium" | |
| 19 | + | ] | |
| 20 | + | } | |
weehong a révisé ce gist 2 months ago. Aller à la révision
1 file changed, 20 deletions
typescript_react.json (fichier supprimé)
| @@ -1,20 +0,0 @@ | |||
| 1 | - | { | |
| 2 | - | "recommendations": [ | |
| 3 | - | "dsznajder.es7-react-js-snippets", | |
| 4 | - | "planbcoding.vscode-react-refactor", | |
| 5 | - | "bradlc.vscode-tailwindcss", | |
| 6 | - | "WallabyJs.console-ninja", | |
| 7 | - | "ms-vscode.vscode-typescript-next", | |
| 8 | - | "yoavbls.pretty-ts-errors", | |
| 9 | - | "christian-kohler.path-intellisense", | |
| 10 | - | "christian-kohler.npm-intellisense", | |
| 11 | - | "dbaeumer.vscode-eslint", | |
| 12 | - | "esbenp.prettier-vscode", | |
| 13 | - | "usernamehw.errorlens", | |
| 14 | - | "eamodio.gitlens", | |
| 15 | - | "rangav.vscode-thunder-client", | |
| 16 | - | "formulahendry.auto-rename-tag", | |
| 17 | - | "GitHub.copilot", | |
| 18 | - | "Codeium.codeium" | |
| 19 | - | ] | |
| 20 | - | } | |
weehong a révisé ce gist 2 months ago. Aller à la révision
1 file changed, 20 insertions
typescript_react.json(fichier créé)
| @@ -0,0 +1,20 @@ | |||
| 1 | + | { | |
| 2 | + | "recommendations": [ | |
| 3 | + | "dsznajder.es7-react-js-snippets", | |
| 4 | + | "planbcoding.vscode-react-refactor", | |
| 5 | + | "bradlc.vscode-tailwindcss", | |
| 6 | + | "WallabyJs.console-ninja", | |
| 7 | + | "ms-vscode.vscode-typescript-next", | |
| 8 | + | "yoavbls.pretty-ts-errors", | |
| 9 | + | "christian-kohler.path-intellisense", | |
| 10 | + | "christian-kohler.npm-intellisense", | |
| 11 | + | "dbaeumer.vscode-eslint", | |
| 12 | + | "esbenp.prettier-vscode", | |
| 13 | + | "usernamehw.errorlens", | |
| 14 | + | "eamodio.gitlens", | |
| 15 | + | "rangav.vscode-thunder-client", | |
| 16 | + | "formulahendry.auto-rename-tag", | |
| 17 | + | "GitHub.copilot", | |
| 18 | + | "Codeium.codeium" | |
| 19 | + | ] | |
| 20 | + | } | |
weehong a révisé ce gist 2 months ago. Aller à la révision
Aucun changement
weehong a révisé ce gist 2 months ago. Aller à la révision
1 file changed, 1 insertion, 1 deletion
install-jetbrains.sh
| @@ -29,7 +29,7 @@ readonly PLUGIN_CATALOG=( | |||
| 29 | 29 | "izhangzhihao.rainbow.brackets|Rainbow Brackets" | |
| 30 | 30 | "IdeaVIM|IdeaVim" | |
| 31 | 31 | "org.sonarlint.idea|SonarQube for IDE (SonarLint)" | |
| 32 | - | "'Key Promoter X'|Key Promoter X" | |
| 32 | + | "Key Promoter X|Key Promoter X" | |
| 33 | 33 | "net.ashald.envfile|EnvFile" | |
| 34 | 34 | "org.intellij.qodana|Qodana" | |
| 35 | 35 | ) | |
weehong a révisé ce gist 2 months ago. Aller à la révision
1 file changed, 1 insertion, 1 deletion
install-jetbrains.sh
| @@ -29,7 +29,7 @@ readonly PLUGIN_CATALOG=( | |||
| 29 | 29 | "izhangzhihao.rainbow.brackets|Rainbow Brackets" | |
| 30 | 30 | "IdeaVIM|IdeaVim" | |
| 31 | 31 | "org.sonarlint.idea|SonarQube for IDE (SonarLint)" | |
| 32 | - | "9792|Key Promoter X" | |
| 32 | + | "'Key Promoter X'|Key Promoter X" | |
| 33 | 33 | "net.ashald.envfile|EnvFile" | |
| 34 | 34 | "org.intellij.qodana|Qodana" | |
| 35 | 35 | ) | |
weehong a révisé ce gist 2 months ago. Aller à la révision
1 file changed, 2 insertions, 2 deletions
install-jetbrains.sh
| @@ -500,7 +500,7 @@ handle_single_instance_abort() { | |||
| 500 | 500 | shift 2 | |
| 501 | 501 | echo | |
| 502 | 502 | echo " ! '${ide_label}' is still running. Skipping remaining plugins for this IDE." >&2 | |
| 503 | - | echo " ! Close the IDE and re-run the script to finish." >&2 | |
| 503 | + | echo " ! Close the IDE and re-run the script to finish." >&2 | |
| 504 | 504 | # Mark current and remaining-for-this-IDE plugins as failed. | |
| 505 | 505 | local mark_from=0 p | |
| 506 | 506 | for p in "${SELECTED_PLUGIN_IDS[@]}"; do | |
| @@ -520,7 +520,7 @@ for ide_label in "${SELECTED_IDES[@]}"; do | |||
| 520 | 520 | ide_aborted=0 | |
| 521 | 521 | for pid in "${SELECTED_PLUGIN_IDS[@]}"; do | |
| 522 | 522 | (( ide_aborted )) && break | |
| 523 | - | printf ' %-34s ' "$pid" | |
| 523 | + | printf ' %-34s ' "$pid" | |
| 524 | 524 | rc=0 | |
| 525 | 525 | case "$itype" in | |
| 526 | 526 | ide|remotedev) | |
weehong a révisé ce gist 3 months ago. Aller à la révision
Aucun changement
weehong a révisé ce gist 3 months ago. Aller à la révision
Aucun changement