Add script to toggle VS Code theme

Signed-off-by: Ferit Yiğit BALABAN <fybalaban@fybx.dev>
This commit is contained in:
Ferit Yiğit BALABAN 2023-11-10 21:00:55 +03:00
parent 294e9616f5
commit df9a93704c
Signed by: fyb
GPG Key ID: E21FEB2C244CB7EB

24
utility/toggle_vscode_theme.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Ferit Yiğit BALABAN, <fybalaban@fybx>
# 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