Last active
October 20, 2022 11:15
-
-
Save devtooligan/a869bfbe6e6ad9d1a66ebee70d0e28c5 to your computer and use it in GitHub Desktop.
importVSCodeSettings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a bash function that will copy a vscode settings.json file into the current directory and randomly select a color scheme. | |
# Step 1: Create a settting.json file somewhere which at least contains this section. Feel free to add your favorite settings to this. | |
{ | |
"workbench.colorCustomizations": { | |
"titleBar.activeForeground": "FOREGROUND", | |
"titleBar.inactiveForeground": "FOREGROUND", | |
"titleBar.activeBackground": "BACKGROUND", | |
"titleBar.inactiveBackground": "BACKGROUND" | |
} | |
} | |
# Note: The FOREGROUND and BACKROUND above will be replaced by the script. | |
# Here is a shell function for creating the template. It's only been tested on Mac with zsh. | |
# One way to make this launchable from anywhere is to create a bash function and put it in your .zshrc (or .bashrc) | |
# That is the way we will do it here. An alternate way would be to create a .sh script and make it executable and put | |
# it in a directory that is included in the shells PATH. | |
importVscodeSettings() { | |
# this assumes you are in the root dir of your project | |
# first create a dir | |
mkdir -p .vscode | |
timestamp=$(date +%s) | |
theme=$((${timestamp} % 2)) # theme 0 or 1 | |
declare -a lightColors=( | |
[1]="#ffffff" # white | |
[2]="#ffc8c8" # pink | |
[3]="#84ff8d" # light green | |
[4]="#8ccbfe" # light blue | |
[5]="#e1e1e1" # light grey | |
[6]="#ffa565" # orange | |
[7]="#d5d166" # lightYello | |
) | |
darkChoices=7 | |
declare -a darkColors=( | |
[1]="#b67300" # brown | |
[2]="#000000" # black | |
[3]="#178803" # dark green | |
[4]="#050388" # dark blue | |
[5]="#656565" # dark grey | |
[6]="#860303" # dark red | |
[7]="#e30000" # red | |
) | |
lightChoices=7 | |
timestamp=$(date +%s) | |
lightColorIndex=$((${timestamp} % ${lightChoices} + 1)) # pseudo random based on timestamp | |
lightColor=${lightColors[${lightColorIndex}]} | |
timestamp=$(date +%s) | |
darkColorIndex=$((${timestamp} % 123456 % ${darkChoices} + 1)) # different pseudo random based on timestamp % 123456 | |
darkColor=${darkColors[${darkColorIndex}]} | |
if [ ${theme} -gt 0 ]; then | |
foreground=${lightColor} | |
background=${darkColor} | |
else | |
foreground=${darkColor} | |
background=${lightColor} | |
fi | |
# replace the path below with the path to your settings.json template | |
cat ${HOME}/dev/utils/settings.json \ | |
| sed "s/FOREGROUND/${foreground}/g" \ | |
| sed "s/BACKGROUND/${background}/g" \ | |
> ./.vscode/settings.json | |
} | |
# That's all! source ~/.zshrc to activate the function then type `importVSCodeSettings` from the command line to run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment