diff --git a/setup.sh b/setup.sh index b331bc9..66960f8 100755 --- a/setup.sh +++ b/setup.sh @@ -53,3 +53,6 @@ elif [ $remove -eq 0 ]; then fi done fi + +# install vscode configs +source vscode.sh diff --git a/vscode.sh b/vscode.sh new file mode 100755 index 0000000..ec6edac --- /dev/null +++ b/vscode.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +set -e + +### +### Install a base of vscode extensions I expect to have in all installations and install settings +### and keybindings config files. +### + +# determine OS / vscode path & executable +case "$OSTYPE" in + linux-gnu*) + VSCODE_CONFIG_PATH="$HOME/.var/app/com.visualstudio.code/config/Code/User" + VSCODE_BINARY=(flatpak run com.visualstudio.code) + ;; + darwin*) + VSCODE_CONFIG_PATH="$HOME/Library/Application Support/Code/User" + VSCODE_BINARY=('/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code') + ;; + cygwin|msys|win32) + # TODO: implement this later + # windows + ;; + *) + # unknown + echo 'Unknown OS, skipping vscode setup' + return + ;; +esac + +if [[ ! -d "$VSCODE_CONFIG_PATH" ]]; then + echo "Could not locate vscode config path (expected at '$VSCODE_CONFIG_PATH')" + return 1 +elif ! type "${VSCODE_BINARY[0]}" >/dev/null 2>/dev/null; then + echo "Could not identify vscode binary (expected '${VSCODE_BINARY[*]}')" + return 2 +fi + +# install extensions +while read -r line; do + "${VSCODE_BINARY[@]}" --install-extension "$line" +done < vscode/extensions + +# backup settings/keybinds files, then create symlinks +# TODO: do the same for snippets dir files +for file in settings.json keybindings.json; do + source="$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )/vscode/$file" + target="$VSCODE_CONFIG_PATH/$file" + if [[ -h "$target" ]] && [[ "$source" == "$(readlink -f "$target")" ]]; then + echo "Skipping '$source' -> '$target' link as it is already linked" + elif [[ -f "$target" ]]; then + mv "$target" "$target.bak" + echo "Backed up existing $file to $target.bak" + else + ln -sv "$source" "$target" + fi +done diff --git a/vscode/extensions b/vscode/extensions new file mode 100644 index 0000000..5018b35 --- /dev/null +++ b/vscode/extensions @@ -0,0 +1,2 @@ +EditorConfig.EditorConfig +timonwong.shellcheck diff --git a/vscode/keybindings.json b/vscode/keybindings.json new file mode 100644 index 0000000..d629ccc --- /dev/null +++ b/vscode/keybindings.json @@ -0,0 +1,47 @@ +// Place your key bindings in this file to override the defaults +[ + { + "key": "ctrl+shift+tab", + "command": "-workbench.action.quickOpenLeastRecentlyUsedEditorInGroup", + "when": "!activeEditorGroupEmpty", + }, + { + "key": "ctrl+shift+tab", + "command": "-workbench.action.quickOpenNavigatePreviousInEditorPicker", + "when": "inEditorsPicker && inQuickOpen", + }, + { + "key": "ctrl+shift+tab", + "command": "workbench.action.previousEditor", + }, + { + "key": "ctrl+tab", + "command": "-workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup", + "when": "!activeEditorGroupEmpty", + }, + { + "key": "ctrl+tab", + "command": "-workbench.action.quickOpenNavigateNextInEditorPicker", + "when": "inEditorsPicker && inQuickOpen", + }, + { + "key": "ctrl+tab", + "command": "workbench.action.nextEditor", + }, + { + "key": "ctrl+shift+alt+,", + "command": "workbench.action.openSettingsJson", + }, + { + "key": "ctrl+shift+cmd+,", + "command": "workbench.action.openSettingsJson", + }, + { + "key": "ctrl+shift+alt+.", + "command": "workbench.action.openGlobalKeybindingsFile", + }, + { + "key": "ctrl+shift+cmd+.", + "command": "workbench.action.openGlobalKeybindingsFile", + }, +] diff --git a/vscode/settings.json b/vscode/settings.json new file mode 100644 index 0000000..2599a97 --- /dev/null +++ b/vscode/settings.json @@ -0,0 +1,34 @@ +{ + // custom settings + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/usr/bin/flatpak-spawn", + "args": ["--host", "--env=TERM=xterm-256color", "/bin/bash"] + }, + }, + + // settings managed by VS Code UI changes, etc. + "diffEditor.ignoreTrimWhitespace": false, + "editor.fontFamily": "'Fira Code', 'Droid Sans Mono', 'Courier New', Menlo, Monaco, Consolas, monospace, 'Droid Sans Fallback'", + "editor.fontLigatures": true, + "editor.insertSpaces": false, + "editor.minimap.maxColumn": 100, + "editor.renderWhitespace": "all", + "editor.tabSize": 4, + "explorer.autoReveal": false, + "explorer.confirmDragAndDrop": false, + "files.autoSave": "afterDelay", + "files.enableTrash": false, + "html.autoCreateQuotes": false, + "python.analysis.typeCheckingMode": "strict", + "workbench.startupEditor": "none", + "[markdown]": { + "editor.rulers": [120], + "editor.wordWrap": "off", + }, + "[shellscript]": { + "editor.tabSize": 2, + "files.eol": "\n", + }, +}