From df9a93704cf1b5d7c88c3bb3fdf3256a1fb7afa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Fri, 10 Nov 2023 21:00:55 +0300 Subject: [PATCH] Add script to toggle VS Code theme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferit Yiğit BALABAN --- utility/toggle_vscode_theme.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 utility/toggle_vscode_theme.sh diff --git a/utility/toggle_vscode_theme.sh b/utility/toggle_vscode_theme.sh new file mode 100755 index 0000000..664494a --- /dev/null +++ b/utility/toggle_vscode_theme.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# +# Ferit Yiğit BALABAN, +# toggle_vscode_theme.sh, 2023 +# + +path_settings="$HOME/.config/Code/User/settings.json" +preferred_dark=$(grep -o '"workbench.preferredDarkColorTheme": *"[^"]*"' < "$path_settings" | cut -d '"' -f4) +preferred_light=$(grep -o '"workbench.preferredLightColorTheme": *"[^"]*"' < "$path_settings" | cut -d '"' -f4) + +if ! command -v code &> /dev/null; then + echo "VS Code is not installed. Please install it and try again." + exit 1 +fi + +case $1 in + 'light' | l) + sed -i "s/\"workbench.colorTheme\": \"[^\"]*\"/\"workbench.colorTheme\": \"$preferred_light\"/" "$path_settings";; + 'dark' | d) + sed -i "s/\"workbench.colorTheme\": \"[^\"]*\"/\"workbench.colorTheme\": \"$preferred_dark\"/" "$path_settings";; + *) + echo "Invalid argument. Please provide either 'light' or 'dark'." + exit 1;; +esac \ No newline at end of file