Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions vscode-dotfiles/vscode_install.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
#!/bin/sh

SCRIPT_DIR=$(cd $(dirname $0) && pwd)
VSCODE_SETTING_DIR=~/Library/Application\ Support/Code/User

rm "$VSCODE_SETTING_DIR/settings.json"
ln -s "$SCRIPT_DIR/settings.json" "${VSCODE_SETTING_DIR}/settings.json"
# エディタ選択
echo "セットアップするエディタを選択してください:"
echo " 1) VS Code"
echo " 2) Cursor"
printf "選択 [1/2]: "
read choice

rm "$VSCODE_SETTING_DIR/keybindings.json"
ln -s "$SCRIPT_DIR/keybindings.json" "${VSCODE_SETTING_DIR}/keybindings.json"
case "$choice" in
1)
EDITOR_NAME="VS Code"
SETTING_DIR=~/Library/Application\ Support/Code/User
EDITOR_CMD="code"
;;
2)
EDITOR_NAME="Cursor"
SETTING_DIR=~/Library/Application\ Support/Cursor/User
EDITOR_CMD="cursor"
;;
*)
echo "Error: 無効な選択です。1 または 2 を入力してください。"
exit 1
;;
esac

# install extention
# code コマンドが見つからない場合は、インストール方法を案内して終了
if ! command -v code &> /dev/null; then
echo "Error: 'code' command not found."
echo "${EDITOR_NAME} のセットアップを開始します..."

# シンボリックリンクを作成
rm "$SETTING_DIR/settings.json" 2>/dev/null
ln -s "$SCRIPT_DIR/settings.json" "${SETTING_DIR}/settings.json"
echo " settings.json をリンクしました"

rm "$SETTING_DIR/keybindings.json" 2>/dev/null
ln -s "$SCRIPT_DIR/keybindings.json" "${SETTING_DIR}/keybindings.json"
echo " keybindings.json をリンクしました"

# install extension
# CLI コマンドが見つからない場合は、インストール方法を案内して終了
if ! command -v "$EDITOR_CMD" &> /dev/null; then
echo "Error: '${EDITOR_CMD}' command not found."
echo "Please install it by:"
echo " 1. Open VS Code"
echo " 1. Open ${EDITOR_NAME}"
echo " 2. Press Cmd+Shift+P"
echo " 3. Run 'Shell Command: Install 'code' command in PATH'"
echo " 3. Run 'Shell Command: Install '${EDITOR_CMD}' command in PATH'"
exit 1
fi

cat "$SCRIPT_DIR/extensions" | while read line
do
code --install-extension $line
"$EDITOR_CMD" --install-extension $line
done

code --list-extensions > "$SCRIPT_DIR/extensions"
"$EDITOR_CMD" --list-extensions > "$SCRIPT_DIR/extensions"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared extensions file causes cross-editor contamination

Medium Severity

The script reads from and writes to a single shared extensions file for both VS Code and Cursor. When a user runs the script for one editor, it overwrites the extensions file with that editor's installed extensions. Running the script later for the other editor will use the wrong extension list and then overwrite it again. This causes unintended cross-contamination between the two editors' extension configurations.

Additional Locations (1)

Fix in Cursor Fix in Web


echo "${EDITOR_NAME} のセットアップが完了しました!"