Created
April 13, 2026 09:06
-
-
Save a-c-m/c9f23833cd05b452cc2692275c6fc7dc to your computer and use it in GitHub Desktop.
Home/End remap for OSX (like it should be)
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
| #!/bin/bash | |
| # ============================================================================= | |
| # fix-home-end-keys.sh | |
| # | |
| # Fixes Home/End key behaviour on macOS so they jump to the start/end of the | |
| # current line, rather than the top/bottom of the document (page up/down). | |
| # | |
| # macOS supports a system-wide key binding file that most native (Cocoa) apps | |
| # respect. This script safely adds the required bindings to that file without | |
| # clobbering any existing configuration. | |
| # | |
| # Bindings added: | |
| # Home → move to start of line | |
| # End → move to end of line | |
| # Shift+Home → select to start of line | |
| # Shift+End → select to end of line | |
| # | |
| # Safe to run multiple times — skips any bindings already present. | |
| # | |
| # Note: Electron apps (VS Code, Slack, etc.) manage their own keybindings and | |
| # are unaffected by this file. Configure those apps separately. | |
| # | |
| # After running: log out and back in (or restart) for changes to take effect. | |
| # ============================================================================= | |
| KEYBINDINGS_FILE="$HOME/Library/KeyBindings/DefaultKeyBinding.dict" | |
| declare -A BINDINGS=( | |
| ['"\\UF729"']="moveToBeginningOfLine:" | |
| ['"\\UF72B"']="moveToEndOfLine:" | |
| ['"$\\UF729"']="moveToBeginningOfLineAndModifySelection:" | |
| ['"$\\UF72B"']="moveToEndOfLineAndModifySelection:" | |
| ) | |
| echo "=== fix-home-end-keys ===" | |
| echo "" | |
| echo "Configures Home/End keys to move to start/end of line in macOS native apps." | |
| echo "" | |
| # Ensure the KeyBindings directory exists | |
| mkdir -p "$HOME/Library/KeyBindings" | |
| # Create the bindings file if it doesn't exist yet | |
| if [ ! -f "$KEYBINDINGS_FILE" ]; then | |
| echo "No existing keybindings file found — creating one." | |
| printf "{\n}\n" > "$KEYBINDINGS_FILE" | |
| else | |
| echo "Found existing keybindings file — will merge safely." | |
| fi | |
| echo "" | |
| # Add each binding only if it isn't already present | |
| for KEY in "${!BINDINGS[@]}"; do | |
| VALUE="${BINDINGS[$KEY]}" | |
| if grep -qF "$KEY" "$KEYBINDINGS_FILE"; then | |
| echo " [skip] $KEY already configured" | |
| else | |
| sed -i '' "s/^}/ $KEY = $VALUE;\\n}/" "$KEYBINDINGS_FILE" | |
| echo " [added] $KEY = $VALUE;" | |
| fi | |
| done | |
| echo "" | |
| echo "Done. Log out and back in for changes to take effect." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment