2015-10-28 00:33:18 +06:00
|
|
|
#!/bin/sh
|
|
|
|
# Script to make a new quantum project
|
|
|
|
# Jack Humbert 2015
|
|
|
|
|
2018-05-10 10:36:40 +06:00
|
|
|
KEYBOARD=$1
|
|
|
|
KEYBOARD_TYPE=$2
|
|
|
|
|
|
|
|
if [ -z "$KEYBOARD" ]; then
|
|
|
|
echo "Usage: $0 <keyboard_name> <keyboard_type>"
|
|
|
|
echo "Example: $0 gh60 avr"
|
|
|
|
echo "Example: $0 bfake ps2avrgb"
|
|
|
|
exit 1
|
|
|
|
elif [ -z "$KEYBOARD_TYPE" ]; then
|
|
|
|
KEYBOARD_TYPE=avr
|
|
|
|
fi
|
|
|
|
|
2018-11-12 09:54:10 +06:00
|
|
|
if [ "$KEYBOARD_TYPE" != "avr" ] && [ "$KEYBOARD_TYPE" != "ps2avrgb" ]; then
|
2018-05-10 10:36:40 +06:00
|
|
|
echo "Invalid keyboard type target"
|
|
|
|
exit 1
|
2016-04-08 04:09:53 +06:00
|
|
|
fi
|
|
|
|
|
2018-03-24 11:40:12 +06:00
|
|
|
if [ -e "keyboards/$1" ]; then
|
|
|
|
echo "Error! keyboards/$1 already exists!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-11-12 09:54:10 +06:00
|
|
|
cd "$(dirname "$0")/.." || exit
|
2016-06-24 08:18:20 +06:00
|
|
|
|
2018-11-12 09:54:10 +06:00
|
|
|
KEYBOARD_NAME=$(basename "$1")
|
|
|
|
KEYBOARD_NAME_UPPERCASE=$(echo "$KEYBOARD_NAME" | awk '{print toupper($0)}')
|
|
|
|
NEW_KBD=keyboards/${KEYBOARD}
|
2015-10-28 00:33:18 +06:00
|
|
|
|
2018-05-10 10:36:40 +06:00
|
|
|
|
2018-11-12 09:54:10 +06:00
|
|
|
cp -r quantum/template/base "$NEW_KBD"
|
|
|
|
cp -r "quantum/template/$KEYBOARD_TYPE/." "$NEW_KBD"
|
2018-05-10 10:36:40 +06:00
|
|
|
|
2018-11-12 09:54:10 +06:00
|
|
|
mv "${NEW_KBD}/template.c" "${NEW_KBD}/${KEYBOARD_NAME}.c"
|
|
|
|
mv "${NEW_KBD}/template.h" "${NEW_KBD}/${KEYBOARD_NAME}.h"
|
|
|
|
find "${NEW_KBD}" -type f -exec sed -i '' -e "s;%KEYBOARD%;${KEYBOARD_NAME};g" {} \;
|
|
|
|
find "${NEW_KBD}" -type f -exec sed -i '' -e "s;%KEYBOARD_UPPERCASE%;${KEYBOARD_NAME_UPPERCASE};g" {} \;
|
2015-10-28 00:33:18 +06:00
|
|
|
|
2018-11-12 09:54:10 +06:00
|
|
|
GIT=$(whereis git)
|
|
|
|
if [ "$GIT" != "" ]; then
|
|
|
|
IS_GIT_REPO=$($GIT log >>/dev/null 2>&1; echo $?)
|
|
|
|
if [ "$IS_GIT_REPO" -eq 0 ]; then
|
2019-02-26 21:59:34 +06:00
|
|
|
ID="$($GIT config --get user.name)"
|
|
|
|
read -rp "What is your name? [$ID] " YOUR_NAME
|
|
|
|
if [ -n "$YOUR_NAME" ]; then
|
|
|
|
ID=$YOUR_NAME
|
|
|
|
fi
|
2018-11-12 09:54:10 +06:00
|
|
|
echo "Using $ID as user name"
|
|
|
|
|
|
|
|
for i in "$NEW_KBD/config.h" \
|
|
|
|
"$NEW_KBD/$KEYBOARD_NAME.c" \
|
|
|
|
"$NEW_KBD/$KEYBOARD_NAME.h" \
|
|
|
|
"$NEW_KBD/keymaps/default/config.h" \
|
|
|
|
"$NEW_KBD/keymaps/default/keymap.c"
|
|
|
|
do
|
2019-02-26 21:59:34 +06:00
|
|
|
awk -v id="$ID" '{sub(/%YOUR_NAME%/,id); print}' < "$i" > "$i.$$"
|
2018-11-12 09:54:10 +06:00
|
|
|
mv "$i.$$" "$i"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<-EOF
|
|
|
|
######################################################
|
|
|
|
# $NEW_KBD project created. To start
|
|
|
|
# working on things, cd into $NEW_KBD
|
|
|
|
######################################################
|
|
|
|
EOF
|