-
Notifications
You must be signed in to change notification settings - Fork 36
feat(qmk): made the install script safer on rerun. #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,8 @@ if [ "$#" -lt 1 ]; then | |
| echo "$0 <keyboard_name> [-n] [-b,-f]" | ||
| echo " # Install Arsenik for your keyboard, opens your editor to edit the config" | ||
| echo ' # -n: no editor: doesn’t open the config with your $EDITOR' | ||
| echo " # -b: build the newly created keymap (after you edited the config)" | ||
| echo " # -f: build the newly created keymap (after you edited the config) then flash" | ||
| echo " # -c: compile the newly created keymap (after you edited the config)" | ||
| echo " # -f: compile the newly created keymap (after you edited the config) then flash" | ||
| exit 0 | ||
| fi | ||
|
|
||
|
|
@@ -39,6 +39,74 @@ function get_keymaps_folder() { | |
| echo "$QMK_PATH/keyboards/$keyboard_name/keymaps" | ||
| } | ||
|
|
||
| function handle_keymap_conflict() { | ||
| local arsenik_folder="$1" | ||
| local script_name=$(basename $0) | ||
|
|
||
| echo -e "\x1b[1;31mError :\x1b[0m The Arsenik keymap already exists for this keyboard." | ||
| echo -e "$script_name should \x1b[4mnot\x1b[0m be used to recompile your keymap, this is an \x1b[4minstall\x1b[0m script." | ||
| echo "This is because some keyboards may need extra info to properly compile or flash the" | ||
| echo "firmware (like if you need to specify the bootloader)" | ||
| echo | ||
|
|
||
| local old_arsenik_keymap_folder="${arsenik_folder::-1}" | ||
| local old_arsenik_keymap_id=1 | ||
|
|
||
| while [ -d "$old_arsenik_keymap_folder"_"$old_arsenik_keymap_id" ]; do | ||
| old_arsenik_keymap_id=$((old_arsenik_keymap_id + 1)) | ||
| done | ||
|
|
||
| local keymap_backup_folder="$old_arsenik_keymap_folder"_"$old_arsenik_keymap_id" | ||
|
|
||
| echo "If you want to reinstall the Arsenik keymap, your old keymap will be moved to this folder:" | ||
| echo " \`$keymap_backup_folder\`" | ||
| echo | ||
|
|
||
| echo "If you want to recompile and flash your keymap, you should do so with the commands provided by QMK" | ||
| echo " Using the QMK CLI: \`qmk flash -kb $keyboard_name -km arsenik\`" | ||
| echo " (docs: https://docs.qmk.fm/cli_commands)" | ||
| echo " Using the \`make\` command: \`make $keyboard_name:arsenik:flash\` run in $QMK_PATH" | ||
| echo " (docs: https://docs.qmk.fm/getting_started_make_guide)" | ||
| echo | ||
| echo "Note: Those commands may not work out of the box, some keyboards need extra cmdline arguments" | ||
| echo "(for instance if you need to specify the bootloader explicitely)" | ||
| echo "If you have an error, check the docs mentionned above." | ||
| echo | ||
|
|
||
| echo "What do you want to do?" | ||
| COLUMNS=1 # Display options from select in a single column | ||
| select cmd in \ | ||
| "Backup keymap and reinstall Arsenik" \ | ||
| "Recompile and flash keymap with the QMK CLI" \ | ||
| "Recompile and flash keymap with \`make\`" \ | ||
| "Abort" | ||
| do | ||
| case $cmd in | ||
| "Backup keymap and reinstall Arsenik") | ||
| mv "$arsenik_folder" "$keymap_backup_folder" | ||
| return 0 | ||
| ;; | ||
| "Recompile and flash keymap with the QMK CLI") | ||
| cd "$QMK_PATH" | ||
| make "$keyboard_name":arsenik:flash | ||
| return 1 | ||
| ;; | ||
| "Recompile and flash keymap with \`make\`") | ||
| qmk flash -kb $keyboard_name -km arsenik | ||
| return 1 | ||
| ;; | ||
| "Abort") | ||
| echo "Aborting." | ||
| return 1 | ||
| ;; | ||
| *) | ||
| echo "Unknown command chosen. Aborting." | ||
| return 1 | ||
| ;; | ||
|
Comment on lines
+89
to
+105
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be the return code used ? If so why returning
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I wanted the function to be able to tell if we should still reinstall the keymap after this case statement (see this comment), but it’s kinda dumb. If you have a better idea to return a status from this function, I’m all ears. |
||
| esac | ||
| done | ||
| } | ||
|
|
||
| function make_new_arsenik_keymap() { | ||
| local keyboard_name="$1" | ||
| local qmk_cmd="$2" | ||
|
|
@@ -48,8 +116,9 @@ function make_new_arsenik_keymap() { | |
| local arsenik_folder="$keymap_folder/arsenik/" | ||
| local default_keymap_folder="$keymap_folder/default" | ||
|
|
||
| [ -d "$arsenik_folder" ] && handle_keymap_conflict "$arsenik_folder" | ||
|
|
||
|
Comment on lines
+119
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return code of handle_keymap_conflict is not used.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is but in a pretty roundabout way. Basically, the I thought it was a bit dirty but maybe fine ? But if you don’t get it then it’s not clear enough and should be fixed. |
||
| cp -r "$default_keymap_folder" "$arsenik_folder" | ||
| ls -l "$arsenik_folder" | ||
|
|
||
| local layout="" | ||
| case $(ls "$default_keymap_folder"/keymap.* | sed 's/.*\(keymap.*\)/\1/') in | ||
|
|
@@ -78,7 +147,7 @@ function make_new_arsenik_keymap() { | |
|
|
||
| case "$qmk_cmd" in | ||
| "none") ;; | ||
| "build") cd "$QMK_PATH" && make "$keyboard_name:arsenik";; | ||
| "compile") cd "$QMK_PATH" && make "$keyboard_name:arsenik";; | ||
| "flash") cd "$QMK_PATH" && make "$keyboard_name:arsenik:flash";; | ||
| esac | ||
| } | ||
|
|
@@ -89,7 +158,7 @@ qmk_cmd="none" | |
| for arg in "${@:2}"; do | ||
| case "$arg" in | ||
| "-n") no_editor=true;; | ||
| "-b") qmk_cmd="build";; | ||
| "-c") qmk_cmd="compile";; | ||
| "-f") qmk_cmd="flash";; | ||
| *) echo "Unknown argument $arg."; exit 1;; | ||
| esac | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be you can do something like
-f: flash the newly created keymap and compile it (if needed ?) after you edited the configAt first reading, we can misunderstand the use of
-fand preciseflashafter-fis more clear according to me