1#!/bin/bash 2set -euo pipefail 3 4function find_workspace_root() { 5 local original_wd=$(pwd) 6 7 while true; do 8 if [ $(pwd) = "/" ]; then 9 break 10 fi 11 12 if [ -d ".vscode" ]; then 13 pwd 14 break 15 fi 16 17 cd .. 18 done 19 20 cd "$original_wd" 21} 22 23SCRIPT_PATH=$(realpath "$0") 24SCRIPT_FOLDER=$(dirname "$SCRIPT_PATH") 25 26WORKSPACE_ROOT=$(find_workspace_root) 27if [ -z "$WORKSPACE_ROOT" ]; then 28 echo "Could not find .vscode/ folder. Please create one in the root of your" 29 echo "workspace and re-run this script." 30 exit 1 31fi 32 33VSCODE_FOLDER="$WORKSPACE_ROOT/.vscode" 34REPO_FOLDER="$WORKSPACE_ROOT/.repo" 35if ! [ -d "$REPO_FOLDER" ]; then 36 echo ".repo/ folder is not in the same location as .vscode/ - this will" 37 echo "cause problems." 38 echo "Exiting..." 39 exit 1 40fi 41 42if ! command -v code > /dev/null; then 43 echo "Could not find 'code' command." 44 echo "" 45 echo "1. Open VSCode" 46 echo "2. Open the command palette (View > Command Palette)" 47 echo "3. Type 'install' and select 'Shell Command: Install code command in PATH'" 48 echo "4. Restart your shell" 49 exit 1 50fi 51 52echo "Installing LLDB VSCode extension" 53code --install-extension 'vadimcn.vscode-lldb@1.7.3' 54 55function files_equal() { 56 local file_a="$1" 57 local file_b="$2" 58 59 if ! [ -f "$file_a" ]; then 60 false 61 return 62 fi 63 64 if ! [ -f "$file_b" ]; then 65 false 66 return 67 fi 68 69 local md5_a=$(md5sum $file_a | cut -d' ' -f1) 70 local md5_b=$(md5sum $file_b | cut -d' ' -f1) 71 72 [[ "$md5_a" == "$md5_b" ]] 73} 74 75function copy_file() { 76 local file="$1" 77 local source="$SCRIPT_FOLDER/$file" 78 local dest="$VSCODE_FOLDER/$file" 79 80 if files_equal "$source" "$dest"; then 81 echo "Skipping copying of $file" 82 return 83 fi 84 85 if [ -f "$dest" ]; then 86 echo "Backing up previous $file to $file.old" 87 mv "$dest" "$dest.old" 88 fi 89 90 echo "Copying $file" 91 cp "$source" "$dest" 92} 93 94copy_file 'tasks.json' 95copy_file 'launch.json' 96 97echo "Done!" 98