]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Add an easy way to create new keymaps for your favorite keyboard (#3868)
authorMechMerlin <30334081+mechmerlin@users.noreply.github.com>
Thu, 13 Sep 2018 18:22:05 +0000 (11:22 -0700)
committerDrashna Jaelre <drashna@live.com>
Thu, 13 Sep 2018 18:22:05 +0000 (11:22 -0700)
* initial commit of keymap creation script

* create default keymap

* pass shellcheck

* provide a better usage message

* change printf string to more accurately reflect the path

* make it more easily understood

* found another typo

* add documentation regarding the new_keymap script

* enforce lowercase for userinputs

docs/newbs_building_firmware.md
util/new_keymap.sh [new file with mode: 0755]

index f227d623f01a7a08220f382f41c7ddb2e70539c3..ac6bff2bc7aa7f4e9a968059a8c1b58f8ee2fb05 100644 (file)
@@ -22,6 +22,20 @@ Start by navigating to the `keymaps` folder for your keyboard.
 
 Once you have the `keymaps` folder open you will want to create a copy of the `default` folder. We highly recommend you name your folder the same as your GitHub username, but you can use any name you want as long as it contains only lower case letters, numbers, and the underscore character.
 
+To automate the process, you also have the option to run the `new_keymap.sh` script. 
+
+Navigate to the `qmk_firmware/util` directory and type the following:
+
+```
+./new_keymap.sh <keyboard path> <username>
+```
+
+For example, for a user named John, trying to make a new keymap for the 1up60hse, they would type in
+
+```
+./new_keymap.sh 1upkeyboards/1up60hse john
+```
+
 ## Open `keymap.c` In Your Favorite Text Editor
 
 Open up your `keymap.c`. Inside this file you'll find the structure that controls how your keyboard behaves. At the top of `keymap.c` there may be some defines and enums that make the keymap easier to read. Farther down you'll find a line that looks like this:
diff --git a/util/new_keymap.sh b/util/new_keymap.sh
new file mode 100755 (executable)
index 0000000..b09f3dd
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Script to make a new keymap for a keyboard of your choosing
+# This script automates the copying of the default keymap into
+# your own keymap
+
+KB_PATH=$(echo "$1" | tr 'A-Z' 'a-z')
+USERNAME=$(echo "$2" | tr 'A-Z' 'a-z')
+
+if [ -z "$KB_PATH" ]; then
+    printf "Usage:   %s <keyboard_path> <username>\n" "$0"
+    printf "Example: %s 1upkeyboards/1up60hse yourname\n" "$0"
+    exit 1
+fi
+
+if [ -z "$USERNAME" ]; then
+    printf "Usage:   %s <keyboard_path> <username>\n" "$0"
+    printf "Example: %s 1upkeyboards/1up60hse yourname\n" "$0"
+    exit 1
+fi
+
+cd ..
+
+if [ ! -d "keyboards/$KB_PATH" ]; then
+       printf "Error! keyboards/%s does not exist!\n" "$KB_PATH"
+       exit 1
+fi
+
+if [ -d "keyboards/$KB_PATH/keymaps/$USERNAME" ]; then
+       printf "Error! keyboards/%s/keymaps/%s already exists!\n" "$KB_PATH" "$USERNAME"
+       exit 1
+fi
+
+# Recursively copy the chosen keyboard's default keymap
+cp -r keyboards/"$KB_PATH"/keymaps/default keyboards/"$KB_PATH"/keymaps/"$USERNAME"
+
+printf "%s keymap directory created in: qmk_firmware/keyboards/%s/keymaps/\n\n" "$USERNAME" "$KB_PATH"
+
+printf "Compile a firmware file with your new keymap by typing: \n"
+printf "   make %s:%s\n" "$KB_PATH" "$USERNAME"
+printf "from the qmk_firmware directory\n"
\ No newline at end of file