This script changes your ZSA keyboard's LED colors based on your git branch to provide a visual indicator when you're working in protected branches like master or main.
-
Clone this repository or download the script
-
Source the script in your shell's rc file (e.g., .zshrc or .bashrc):
source /path/to/change_keyboard_color_on_master_branch.bash
The script continuously monitors your git environment through two mechanisms:
- A background process that checks for branch changes
- A directory change hook that evaluates the git status when you navigate directories
When a branch change is detected, the script:
- Checks if the current branch matches any in your
PRIMARY_BRANCHES
array - Sets the keyboard color using Kontroll's
set-rgb-all
command to the color specified in thePROTECTED_BRANCH_COLOR
variable, or theFEATURE_BRANCH_COLOR
variable if the branch is not in thePRIMARY_BRANCHES
array
The script handles Keymapp (the ZSA keyboard management application) automatically:
- Checks if Keymapp is running using
pgrep
- Launches Keymapp if needed using macOS's
open
command - Uses AppleScript to move the Keymapp window off-screen
- Manages keyboard connections using Kontroll CLI commands
This script uses macOS-specific commands in several places. If you're adapting for another OS, you'll need to modify:
-
Application Management:
# macOS command to launch Keymapp open -g -a "Keymapp"
-
Window Management:
# macOS AppleScript for window control osascript -e ' tell application "System Events" tell process "keymapp" tell window 1 set position to {2000, -1000} end tell end tell end tell '
-
Process Detection:
# macOS process check pgrep -q "keymapp"
For other operating systems:
- Linux users might use
xdotool
orwmctrl
for window management - Windows users might use PowerShell commands for process and window control
- The Kontroll CLI commands should work the same across platforms
The script can be customized by modifying the following variables at the top of the file:
# Add any branches that should trigger the protected branch color
PRIMARY_BRANCHES=("master" "main" "production")
# Colors should be specified in hex format WITHOUT the '#' symbol
PROTECTED_BRANCH_COLOR="E56717" # Papaya Orange
FEATURE_BRANCH_COLOR="25A2DC" # Yas Marina Blue
- If colors aren't changing, ensure Keymapp is installed and the keyboard is connected
- If you see no output when switching branches, that's normal! The script runs silently unless there's an error
- If you need to manually reconnect:
kontroll connect-any