From 88bc188aa64d96a9355099070d3edd932d84057e Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 21 Aug 2024 19:38:14 +0200 Subject: [PATCH] chore(osx): remap home and end keys --- knowledge base/mac os x/README.md | 40 ++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/knowledge base/mac os x/README.md b/knowledge base/mac os x/README.md index bcfb176..fcf40ac 100644 --- a/knowledge base/mac os x/README.md +++ b/knowledge base/mac os x/README.md @@ -13,6 +13,7 @@ 1. [Use TouchID to authenticate in the terminal](#use-touchid-to-authenticate-in-the-terminal) 1. [Fix iTerm2](#fix-iterm2) 1. [Create custom DNS resolvers](#create-custom-dns-resolvers) +1. [Remap the Home and End keys](#remap-the-home-and-end-keys) 1. [Xcode CLI tools](#xcode-cli-tools) 1. [Headless installation](#headless-installation) 1. [Removal](#removal) @@ -386,6 +387,27 @@ Instead: dscacheutil -q 'host' -a 'name' 'gitlab.lan' ``` +## Remap the Home and End keys + +Refer [Remap Home and End Keys?] and [trusktr's default keybindings]. + +```sh +mkdir -p "$HOME/Library/KeyBindings" +cat <<-EOF | tee "$HOME/Library/KeyBindings/DefaultKeyBinding.dict" +{ + /* Remap Home and End keys to act primarily on lines */ + "\UF729" = "moveToBeginningOfLine:"; /* Home */ + "\UF72B" = "moveToEndOfLine:"; /* End */ + "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */ + "$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */ + "^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */ + "^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */ + "$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */ + "$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */ +} +EOF +``` + ## Xcode CLI tools ```sh @@ -401,12 +423,14 @@ The tools will be installed into `/Library/Developer/CommandLineTools` by defaul touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress # Get their label. -CLI_TOOLS_LABEL="$(/usr/sbin/softwareupdate -l \ - | grep -B 1 -E 'Command Line Tools' \ - | awk -F'*' '/^ *\\*/ {print $2}' \ - | sed -e 's/^ *Label: //' -e 's/^ *//' \ - | sort -V \ - | tail -n1)" +CLI_TOOLS_LABEL="$(\ + /usr/sbin/softwareupdate -l \ + | grep -B 1 -E 'Command Line Tools' \ + | awk -F'*' '/^ *\\*/ {print $2}' \ + | sed -e 's/^ *Label: //' -e 's/^ *//' \ + | sort -V \ + | tail -n1 \ +)" # Install them. /usr/sbin/softwareupdate -i --agree-to-license "$CLI_TOOLS_LABEL" @@ -504,6 +528,8 @@ To use any of these key combinations, press and hold the keys immediately after - [macOS tools and tips] - [List all network hardware from command line in Mac OS] - [Network warrior: how to use macOS network utilities] +- [Remap Home and End Keys?] +- [trusktr's default keybindings]