summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfauxpark <fauxpark@gmail.com>2019-07-09 07:07:36 +1000
committerFlorian Didron <fdidron@users.noreply.github.com>2019-07-10 09:07:12 +0900
commit642986a8349e7de728b2a886542ea29a95b32d52 (patch)
tree73f3f6ce489888f2be219d0d161e58df22af0428
parentea40d07776a0c0f2cb195336cf7bdc0d12dc958b (diff)
Add copyright year placeholders to new keyboard script (#6280)
* Add copyright year placeholders to new keyboard script * More copyright header tweaks
-rw-r--r--quantum/template/avr/config.h2
-rw-r--r--quantum/template/avr/template.c2
-rw-r--r--quantum/template/base/keymaps/default/config.h2
-rw-r--r--quantum/template/base/keymaps/default/keymap.c2
-rw-r--r--quantum/template/base/template.h2
-rw-r--r--quantum/template/ps2avrgb/config.h2
-rw-r--r--quantum/template/ps2avrgb/rules.mk15
-rw-r--r--quantum/template/ps2avrgb/template.c2
-rw-r--r--quantum/template/ps2avrgb/usbconfig.h13
-rwxr-xr-xutil/new_keyboard.sh172
10 files changed, 180 insertions, 34 deletions
diff --git a/quantum/template/avr/config.h b/quantum/template/avr/config.h
index c13784ba15..1e41a2d31d 100644
--- a/quantum/template/avr/config.h
+++ b/quantum/template/avr/config.h
@@ -1,5 +1,5 @@
/*
-Copyright 2019 %YOUR_NAME%
+Copyright %YEAR% %YOUR_NAME%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/quantum/template/avr/template.c b/quantum/template/avr/template.c
index 1e4ce26cd1..7a5434f30e 100644
--- a/quantum/template/avr/template.c
+++ b/quantum/template/avr/template.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 %YOUR_NAME%
+/* Copyright %YEAR% %YOUR_NAME%
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/quantum/template/base/keymaps/default/config.h b/quantum/template/base/keymaps/default/config.h
index 44382016a1..5b00c8956f 100644
--- a/quantum/template/base/keymaps/default/config.h
+++ b/quantum/template/base/keymaps/default/config.h
@@ -1,4 +1,4 @@
-/* Copyright 2019 %YOUR_NAME%
+/* Copyright %YEAR% %YOUR_NAME%
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/quantum/template/base/keymaps/default/keymap.c b/quantum/template/base/keymaps/default/keymap.c
index 482a445448..0e9fad357f 100644
--- a/quantum/template/base/keymaps/default/keymap.c
+++ b/quantum/template/base/keymaps/default/keymap.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 %YOUR_NAME%
+/* Copyright %YEAR% %YOUR_NAME%
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/quantum/template/base/template.h b/quantum/template/base/template.h
index 5b5076c476..2e531b1fd4 100644
--- a/quantum/template/base/template.h
+++ b/quantum/template/base/template.h
@@ -1,4 +1,4 @@
-/* Copyright 2019 %YOUR_NAME%
+/* Copyright %YEAR% %YOUR_NAME%
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/quantum/template/ps2avrgb/config.h b/quantum/template/ps2avrgb/config.h
index 88968c8b97..9479246ccf 100644
--- a/quantum/template/ps2avrgb/config.h
+++ b/quantum/template/ps2avrgb/config.h
@@ -1,5 +1,5 @@
/*
-Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
+Copyright %YEAR% %YOUR_NAME%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/quantum/template/ps2avrgb/rules.mk b/quantum/template/ps2avrgb/rules.mk
index bcd7dff999..440d99345f 100644
--- a/quantum/template/ps2avrgb/rules.mk
+++ b/quantum/template/ps2avrgb/rules.mk
@@ -1,18 +1,3 @@
-# Copyright 2019 Luiz Ribeiro <luizribeiro@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
# MCU name
MCU = atmega32a
PROTOCOL = VUSB
diff --git a/quantum/template/ps2avrgb/template.c b/quantum/template/ps2avrgb/template.c
index 08156c562c..16fcc8469f 100644
--- a/quantum/template/ps2avrgb/template.c
+++ b/quantum/template/ps2avrgb/template.c
@@ -1,4 +1,4 @@
-/* Copyright 2019 %YOUR_NAME%
+/* Copyright %YEAR% %YOUR_NAME%
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/quantum/template/ps2avrgb/usbconfig.h b/quantum/template/ps2avrgb/usbconfig.h
index d2d848fcdc..4efa935d99 100644
--- a/quantum/template/ps2avrgb/usbconfig.h
+++ b/quantum/template/ps2avrgb/usbconfig.h
@@ -1,15 +1,4 @@
-/* Name: usbconfig.h
- * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
- * Author: Christian Starkjohann
- * Creation Date: 2005-04-01
- * Tabsize: 4
- * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
- * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $
- */
-
-#ifndef __usbconfig_h_included__
-#define __usbconfig_h_included__
+#pragma once
#include "config.h"
diff --git a/util/new_keyboard.sh b/util/new_keyboard.sh
new file mode 100755
index 0000000000..35d89e4026
--- /dev/null
+++ b/util/new_keyboard.sh
@@ -0,0 +1,172 @@
+#!/bin/bash
+
+# This script generates a new keyboard directory under keyboards/,
+# and copies the template files from quantum/template/ into it.
+
+# Print an error message with the word "ERROR" in red.
+echo_error() {
+ echo -e "[\033[0;91mERROR\033[m]: $1"
+}
+
+# Print a message in bold.
+echo_bold() {
+ echo -e "\033[1m$1\033[m"
+}
+
+# Prompt the user for information, showing the default value in brackets.
+prompt() {
+ local message="$1"
+ local default="$2"
+
+ [ -n "$default" ] && message+=" [$default]"
+ message+=": "
+
+ read -rp "$message" prompt_return
+ [ -z "$prompt_return" ] && prompt_return="$default"
+}
+
+# Grab a username from Git config.
+set_git_username() {
+ git_username="$(git config --get user.name)"
+}
+
+# Copy the template files to the new keyboard directory.
+copy_templates() {
+ echo -n "Copying base template files..."
+ cp -r "quantum/template/base" "${keyboard_dir}"
+ echo " done"
+
+ echo -n "Copying $keyboard_type template files..."
+ cp -r "quantum/template/${keyboard_type}/." "${keyboard_dir}"
+ echo " done"
+
+ echo -n "Renaming keyboard files..."
+ mv "${keyboard_dir}/template.c" "${keyboard_dir}/${keyboard_name}.c"
+ mv "${keyboard_dir}/template.h" "${keyboard_dir}/${keyboard_name}.h"
+ echo " done"
+}
+
+# Set the inplace editing parameter for sed.
+# macOS/BSD sed expects a file extension immediately following -i.
+set_sed_i() {
+ sed_i=(-i)
+
+ case $(uname -a) in
+ *Darwin*) sed_i=(-i "")
+ esac
+}
+
+# Replace a token with a value in the given list of files.
+replace_placeholders() {
+ local replace_token="$1"
+ local replace_value="$2"
+ shift 2
+ local replace_filenames=("$@")
+
+ echo -n "Replacing $replace_token with $replace_value..."
+ for replace_filename in "${replace_filenames[@]}"; do
+ sed "${sed_i[@]}" -e "s/${replace_token}/${replace_value}/g" "$replace_filename"
+ done
+ echo " done"
+}
+
+# Replace %YEAR% with the current year.
+replace_year_placeholders() {
+ local replace_year_filenames=(
+ "${keyboard_dir}/config.h"
+ "${keyboard_dir}/${keyboard_name}.c"
+ "${keyboard_dir}/${keyboard_name}.h"
+ "${keyboard_dir}/keymaps/default/config.h"
+ "${keyboard_dir}/keymaps/default/keymap.c"
+ )
+ replace_placeholders "%YEAR%" "$(date +%Y)" "${replace_year_filenames[@]}"
+}
+
+# Replace %KEYBOARD% with the keyboard name.
+replace_keyboard_placeholders() {
+ local replace_keyboard_filenames=(
+ "${keyboard_dir}/config.h"
+ "${keyboard_dir}/readme.md"
+ "${keyboard_dir}/${keyboard_name}.c"
+ "${keyboard_dir}/keymaps/default/readme.md"
+ )
+ replace_placeholders "%KEYBOARD%" "$keyboard_name" "${replace_keyboard_filenames[@]}"
+}
+
+# Replace %YOUR_NAME% with the username.
+replace_name_placeholders() {
+ local replace_name_filenames=(
+ "${keyboard_dir}/config.h"
+ "${keyboard_dir}/readme.md"
+ "${keyboard_dir}/${keyboard_name}.c"
+ "${keyboard_dir}/${keyboard_name}.h"
+ "${keyboard_dir}/keymaps/default/config.h"
+ "${keyboard_dir}/keymaps/default/keymap.c"
+ )
+ replace_placeholders "%YOUR_NAME%" "$username" "${replace_name_filenames[@]}"
+}
+
+# Check if an array contains an element.
+array_contains() {
+ local e match="$1"
+ shift
+ for e; do
+ [[ "$e" == "$match" ]] && return 0;
+ done
+
+ return 1
+}
+
+# If we've been started from util/, we want to be in qmk_firmware/
+[[ "$PWD" == *util ]] && cd ..
+
+# The root qmk_firmware/ directory should have a subdirectory called quantum/
+if [ ! -d "quantum" ]; then
+ echo_error "Could not detect the QMK firmware directory!"
+ echo_error "Are you sure you're in the right place?"
+ exit 1
+fi
+
+echo_bold "Generating a new QMK keyboard directory"
+echo
+
+# Keyboard name is required, so keep prompting until we get one
+while [ -z "$keyboard_name" ]; do
+ prompt "Keyboard Name" ""
+ keyboard_name=$prompt_return
+done
+
+keyboard_dir="keyboards/$keyboard_name"
+
+if [ -d "$keyboard_dir" ]; then
+ echo_error "Keyboard $keyboard_name already exists!"
+ exit 1
+fi
+
+KEYBOARD_TYPES=("avr" "ps2avrgb")
+
+prompt "Keyboard Type" "avr"
+keyboard_type=$prompt_return
+
+if ! array_contains "$keyboard_type" "${KEYBOARD_TYPES[@]}"; then
+ echo_error "Keyboard type must be one of: ${KEYBOARD_TYPES[*]}"
+ exit 1
+fi
+
+set_git_username
+prompt "Your Name" "$git_username"
+username=$prompt_return
+
+echo
+
+copy_templates
+set_sed_i
+replace_year_placeholders
+replace_keyboard_placeholders
+[ -n "$username" ] && replace_name_placeholders
+
+echo
+echo_bold "Created a new keyboard called $keyboard_name."
+echo
+echo_bold "To start working on things, cd into keyboards/$keyboard_name,"
+echo_bold "or open the directory in your favourite text editor."