mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-16 07:02:37 +00:00
Compare commits
4 Commits
8a63efd6cf
...
087d7963e8
| Author | SHA1 | Date | |
|---|---|---|---|
|
087d7963e8
|
|||
|
8b25509344
|
|||
|
0034ac6d87
|
|||
|
5c6409c2e9
|
153
env/.config/kanata/config.kbd
vendored
Normal file
153
env/.config/kanata/config.kbd
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
;; Adapted from https://github.com/linkarzu/dotfiles-latest/blob/main/kanata/configs/macbook-subl.kbd
|
||||
;; Video related to this file
|
||||
;; https://youtu.be/jvJ3f4HHiMY
|
||||
|
||||
;; Kanata docs
|
||||
;; https://github.com/jtroo/kanata/blob/main/docs/config.adoc
|
||||
|
||||
;; OS key code mappings
|
||||
;; https://github.com/jtroo/kanata/blob/main/parser/src/keys/mod.rs
|
||||
|
||||
(defcfg
|
||||
process-unmapped-keys yes
|
||||
log-layer-changes no
|
||||
danger-enable-cmd yes
|
||||
concurrent-tap-hold yes
|
||||
rapid-event-delay 3
|
||||
allow-hardware-repeat false
|
||||
|
||||
;; When any non-chord activation happens, this timeout begins. Until this timeout expires
|
||||
;; all inputs will immediately skip chords processing and be processed by the active layer.
|
||||
;; chords-v2-min-idle 250
|
||||
)
|
||||
|
||||
;; Variables
|
||||
(defvar
|
||||
tap-higher 400
|
||||
tap-time 200
|
||||
tap-time-plus 300
|
||||
hold-time-plus 300
|
||||
hold-time 200
|
||||
chord-time 60
|
||||
subl-time 200
|
||||
tmux-delay 40
|
||||
)
|
||||
|
||||
;; Only one defsrc is allowed.
|
||||
;;
|
||||
;; defsrc defines the keys that will be intercepted by kanata. The order of the
|
||||
;; keys matches with deflayer declarations and all deflayer declarations must
|
||||
;; have the same number of keys as defsrc. Any keys not listed in defsrc will
|
||||
;; be passed straight to the operating system.
|
||||
(defsrc
|
||||
esc f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12
|
||||
grv 1 2 3 4 5 6 7 8 9 0 - = bspc
|
||||
tab q w e r t y u i o p [ ] \
|
||||
caps a s d f g h j k l ; ' ret
|
||||
lsft z x c v b n m , . / ▲ rsft
|
||||
lctl lalt lmet spc rmet ralt ◀ ▼ ▶
|
||||
)
|
||||
|
||||
(defalias
|
||||
;; Modifier keys - Left
|
||||
mlctl (tap-hold $tap-time $hold-time a lctl)
|
||||
mlalt (tap-hold $tap-time $hold-time s lalt)
|
||||
mlmet (tap-hold $tap-time $hold-time d lmet)
|
||||
mlsft (tap-hold $tap-time $hold-time f lsft)
|
||||
|
||||
;; Modifier keys - Right
|
||||
mrsft (tap-hold $tap-time $hold-time j rsft)
|
||||
mrmet (tap-hold $tap-time $hold-time k rmet)
|
||||
mralt (tap-hold $tap-time $hold-time l ralt)
|
||||
mrctl (tap-hold $tap-time $hold-time ; rctl)
|
||||
|
||||
mretu (tap-hold $tap-time $hold-time tab ret)
|
||||
|
||||
;; number and symbols layer trigger keys.
|
||||
mlnums (tap-hold-press $tap-time-plus $hold-time-plus esc (layer-while-held nums_and_symbols))
|
||||
mrnums (tap-hold-press $tap-time-plus $hold-time-plus ret (layer-while-held nums_and_symbols))
|
||||
|
||||
;; mouse layer trigger keys.
|
||||
mlms (tap-hold-press $tap-time $hold-time lsft (layer-while-held mouse))
|
||||
mrms (tap-hold-press $tap-time $hold-time rsft (layer-while-held mouse))
|
||||
|
||||
;; Multi
|
||||
mhypr (tap-hold $tap-time $hold-time spc (multi lsft lctl lalt lmet)) ;; Hyper key
|
||||
|
||||
;; Sublayers
|
||||
;; I implemented sublayers thanks to the help in this discussion
|
||||
;; https://github.com/jtroo/kanata/discussions/1765
|
||||
;; DO NOT USE THE SUBLAYERS IN A FREQUENTLY PRESSED KEY LIKE SPACEBAR
|
||||
;; It made typing spaces a pain in the ass, enter is not pressed to often, so it works way better
|
||||
;; msubl (tap-hold-press $subl-time $subl-time ret (layer-while-held sublayers))
|
||||
|
||||
;; Execute script
|
||||
;; maltt (cmd open "btt://execute_assigned_actions_for_trigger/?uuid=F35EF770-FAA5-448A-957D-70BB449DEB0F")
|
||||
|
||||
;; key and script at the same time
|
||||
;; maltt (tap-hold $tap-time $hold-time lsft (cmd open "btt://execute_assigned_actions_for_trigger/?uuid=F35EF770-FAA5-448A-957D-70BB449DEB0F"))
|
||||
)
|
||||
|
||||
;; Blank layer
|
||||
;; (deflayer {{NAME}}
|
||||
;; esc XX XX XX XX XX XX XX XX XX XX XX XX ;; function row
|
||||
;; grv XX XX XX XX XX XX XX XX XX XX XX XX bspc ;; number row
|
||||
;; tab XX XX XX XX XX XX XX XX XX XX XX XX XX ;; top letter row
|
||||
;; caps XX XX XX XX XX XX XX XX XX XX XX ret ;; home row
|
||||
;; lsft XX XX XX XX XX XX XX XX XX XX XX rsft ;; bottom letter row
|
||||
;; lctl lalt lmet spc rmet ralt ◀ ▼ ▶ ;; control row
|
||||
;; )
|
||||
|
||||
;; Main layer
|
||||
;;
|
||||
;; Disable most function keys, and add homerow mods.
|
||||
;;
|
||||
(deflayer main
|
||||
esc brdn bru XX XX XX XX XX XX XX mute vold volu
|
||||
grv 1 2 3 4 5 6 7 8 9 0 - = bspc
|
||||
tab q w e r t y u i o p [ ] \
|
||||
@mlnums @mlctl @mlalt @mlmet @mlsft g h @mrsft @mrmet @mralt @mrctl ' @mrnums
|
||||
@mlms z x c v b n m , . / ▲ @mrms
|
||||
lctl lalt lmet spc rmet ralt ◀ ▼ ▶
|
||||
)
|
||||
|
||||
;; Number and Symbols layer
|
||||
(deflayer nums_and_symbols
|
||||
esc XX XX XX XX XX XX XX XX XX XX XX XX
|
||||
grv XX XX XX XX XX XX XX XX XX XX - = bspc
|
||||
S-grv S-1 S-9 S-0 S-2 XX XX 1 2 3 \ XX XX XX
|
||||
XX [ ] S-[ S-] XX XX 4 5 6 . XX ret
|
||||
lsft S-7 S-8 S-4 S-3 XX XX 7 8 9 / XX rsft
|
||||
lctl lalt lmet 0 rmet ralt ◀ ▼ ▶
|
||||
)
|
||||
|
||||
(defalias
|
||||
mwu (mwheel-up 50 120)
|
||||
mwd (mwheel-down 50 120)
|
||||
mwl (mwheel-left 50 120)
|
||||
mwr (mwheel-right 50 120)
|
||||
|
||||
ms↑ (movemouse-up 1 1)
|
||||
ms← (movemouse-left 1 1)
|
||||
ms↓ (movemouse-down 1 1)
|
||||
ms→ (movemouse-right 1 1)
|
||||
|
||||
ma↑ (movemouse-accel-up 5 1000 1 3)
|
||||
ma← (movemouse-accel-left 5 1000 1 3)
|
||||
ma↓ (movemouse-accel-down 5 1000 1 3)
|
||||
ma→ (movemouse-accel-right 5 1000 1 3)
|
||||
|
||||
sm (setmouse 32228 32228)
|
||||
|
||||
fst (movemouse-speed 200)
|
||||
)
|
||||
|
||||
;; Mouse and arrow layer
|
||||
(deflayer mouse
|
||||
esc XX XX XX XX XX XX XX XX XX XX XX XX ;; function row
|
||||
grv XX XX XX XX XX XX XX XX XX XX XX XX bspc ;; number row
|
||||
tab XX XX ▲ XX XX @mwl @mwd @mwu @mwr XX XX XX XX ;; top letter row
|
||||
caps XX ◀ ▼ ▶ XX @ma← @ma↓ @ma↑ @ma→ XX XX mrtp ;; home row
|
||||
lsft XX XX XX XX XX XX XX XX XX XX XX rsft ;; bottom letter row
|
||||
lctl lalt lmet mltp rmet ralt XX XX XX ;; control row
|
||||
)
|
||||
7
env/.local/scripts/hypr/logging
vendored
7
env/.local/scripts/hypr/logging
vendored
@@ -78,7 +78,7 @@ logging() {
|
||||
args=()
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == "-w" ]] || [[ $1 =~ ^--warn ]]; then
|
||||
if [[ $1 == "-w" ]] || [[ $1 == "--warn" ]] || [[ $1 == "--warning" ]]; then
|
||||
log_flag="1"
|
||||
warn_flag="1"
|
||||
elif [[ $1 == "-e" ]] || [[ $1 =~ ^--error ]]; then
|
||||
@@ -116,9 +116,10 @@ logging() {
|
||||
local time=$(date '+%D %H:%M:%S')
|
||||
|
||||
if [[ -z $file ]] || [[ -z $id ]] || [[ -z $label ]]; then
|
||||
echo "Loggging not properly setup."
|
||||
echo "Logging not properly setup."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local prefix="[id: $id][time: $time][source: \e[32m$source_file\e[0m][\e[34m$label\e[0m] :"
|
||||
local m="$prefix $msg"
|
||||
echo -e "$m" >>"$file"
|
||||
@@ -127,6 +128,8 @@ logging() {
|
||||
# Also log errors and warning messages to the console.
|
||||
if [[ $error_flag == "1" ]] || [[ $warn_flag == "1" ]]; then
|
||||
echo -e "[id: $id]$msg"
|
||||
elif [[ $warn_flag == "1" ]]; then
|
||||
echo -e "[id: $id]$msg"
|
||||
fi
|
||||
else
|
||||
# Dry run mode, so just log to the console
|
||||
|
||||
266
env/.local/scripts/kanatactl
vendored
Executable file
266
env/.local/scripts/kanatactl
vendored
Executable file
@@ -0,0 +1,266 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||
THIS_FILE=${BASH_SOURCE[0]}
|
||||
LOG_LABEL=$(basename "$THIS_FILE")
|
||||
THIS=${THIS:-$LOG_LABEL}
|
||||
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
||||
XDG_DATA_HOME=${XDG_DATA_HOME:-"$HOME/.local/share"}
|
||||
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"}
|
||||
DEV_ENV=${DEV_ENV:-""}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
||||
Manages kanata qmk keyboard program, which needs to be built locally. Currently the linux builds
|
||||
are only for x86. Also can manage as a systemd service.
|
||||
|
||||
USAGE:
|
||||
|
||||
$ $THIS <command> <flags>
|
||||
|
||||
FLAGS:
|
||||
-h | --help: Show this help page.
|
||||
|
||||
COMMANDS:
|
||||
bootstrap: Bootstrap a new machine, performs installation, enables, and starts kanata systemd service.
|
||||
disable: Stop and disable the kanata systemd service.
|
||||
install: Build and install kanata, prompts you to choose the version to install.
|
||||
logs: View the log file.
|
||||
restart: Restart the kanata systemd service.
|
||||
start: Enable and start the kanata systemd service.
|
||||
status: Get the status of the kanata systemd service.
|
||||
stop: Stop the kanata systemd service.
|
||||
update: Pull from git and check for updates.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
kanata_dir="$XDG_DATA_HOME/kanata"
|
||||
kanata_url="https://github.com/jtroo/kanata.git"
|
||||
kanata_current_version=""
|
||||
|
||||
# Logging utility function, use in place of echo.
|
||||
log() {
|
||||
logging log --source "$THIS_FILE" "$@"
|
||||
}
|
||||
|
||||
# Get the version of currently installed katana execuatable, if available.
|
||||
get_current_version() {
|
||||
if [[ $(command -v /usr/bin/kanata) ]]; then
|
||||
kanata_current_version=$(/usr/bin/kanata --version)
|
||||
# Remove 'kanata ' from output of the version command.
|
||||
kanata_current_version="${kanata_current_version#kanata *}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Get's kanat versions by git tag and filter's out versions that are less than our
|
||||
# current version number.
|
||||
get_versions() {
|
||||
get_current_version
|
||||
local rows=()
|
||||
local tag=""
|
||||
local has_seen_current="0"
|
||||
for tag in $(git tag --list 'v*' | sort --version-sort); do
|
||||
if [[ $has_seen_current == "1" ]] || [[ -z $kanata_current_version ]]; then
|
||||
rows+=("$tag\n")
|
||||
elif [[ $tag =~ $kanata_current_version ]]; then
|
||||
has_seen_current="1"
|
||||
fi
|
||||
done
|
||||
echo "$(echo -e "${rows[@]}" | sort --version-sort --reverse | tr -d ' ')"
|
||||
}
|
||||
|
||||
# Present an fzf menu to choose a version to install / update to.
|
||||
prompt_for_version_to_install() {
|
||||
local rows=$(get_versions)
|
||||
if [[ -z $rows ]]; then
|
||||
log --error "No versions to select." && exit 1
|
||||
else
|
||||
echo $(printf '%s\n' "${rows[@]}" | fzf --header='Which version would you like to install?')
|
||||
fi
|
||||
}
|
||||
|
||||
# Compares the selected version to the installed version.
|
||||
compare_versions() {
|
||||
# An example selection at this point: 'v1.9.0'
|
||||
local selection=""
|
||||
read -r selection
|
||||
|
||||
if [[ $(command -v /usr/bin/kanata) ]] && [[ -n $selection ]]; then
|
||||
|
||||
[[ -z $kanata_current_version ]] && get_current_version
|
||||
local selected_version=${selection#v*} # remove the 'v' from selected version.
|
||||
|
||||
log "Comparing selected: '$selected_version' to installed '$kanata_current_version'"
|
||||
if [[ $selected_version == $kanata_current_version ]]; then
|
||||
log --warn "Selected version matches the currently installed version." && exit 1
|
||||
fi
|
||||
fi
|
||||
echo "$selection"
|
||||
}
|
||||
|
||||
# Check's out the selected version tag and builds the kanata executable.
|
||||
build_selection() {
|
||||
# An example selection at this point: 'v1.9.0'
|
||||
local selection=""
|
||||
read -r selection
|
||||
|
||||
if [[ -z $selection ]]; then
|
||||
log --error "Selection is empty." && exit 1
|
||||
# Handle logged messages instead of an actual selection.
|
||||
elif [[ $selection =~ "[WARN]" ]] || [[ $selection =~ "[ERROR]" ]]; then
|
||||
echo $selection && exit 1
|
||||
fi
|
||||
|
||||
if [[ $selection =~ ^v ]]; then
|
||||
log "Building kanata..."
|
||||
# checkout the selected version tag and build.
|
||||
git checkout $selection
|
||||
cargo build --release --features cmd
|
||||
echo "done"
|
||||
fi
|
||||
}
|
||||
|
||||
# Copies the most recently built kanata executable to the '/usr/bin' directory.
|
||||
#
|
||||
copy_to_usr_bin() {
|
||||
|
||||
# This is the end of the install / update pipe, so it loops over output of
|
||||
# the other commands in the pipe printing it to the console, while waiting on the
|
||||
# build to be done.
|
||||
while read line; do
|
||||
if [[ $line == "done" ]]; then
|
||||
log "Copying to '/usr/bin/kanata'" && echo "Copying to '/usr/bin/kanata'"
|
||||
sudo cp target/release/kanata /usr/bin
|
||||
echo "Done!"
|
||||
else
|
||||
echo "$line"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Installs the systemd service files and ensures that kanata configuration has been
|
||||
# installed.
|
||||
install_service() {
|
||||
if [[ -z $DEV_ENV ]]; then
|
||||
log --error "DEV_ENV is not set properly." && exit 1
|
||||
fi
|
||||
|
||||
# Ensure the configuration is copied, this is generally handled by the 'dev-env' command in
|
||||
# dotfiles, but just encase it hasn't been ran or removed we need to copy the configuration
|
||||
# over, otherwise the keyboard may not work.
|
||||
if [[ ! -d $XDG_CONFIG_HOME/kanata ]] || [[ ! -f $XDG_CONFIG_HOME/kanata/config.kbd ]]; then
|
||||
log "Copying kanata configuration."
|
||||
cp -R $DEV_ENV/env/.config/kanata $XDG_CONFIG_HOME/kanata
|
||||
fi
|
||||
|
||||
log "Installing kanata service..."
|
||||
[[ -f /etc/systemd/system/kanata.service ]] && sudo rm -rf /etc/systemd/system/kanata.service
|
||||
sudo cp "$DEV_ENV/env/etc/systemd/system/kanata.service" /etc/systemd/system
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
# Enables and starts the kanata systemd service.
|
||||
enable_and_start_service() {
|
||||
log "Enabling kanata service..."
|
||||
sudo systemctl enable kanata.service
|
||||
sudo systemctl start kanata.service
|
||||
}
|
||||
|
||||
# Get the status of the kanata systemd service.
|
||||
get_status() {
|
||||
log "Getting kanata service status..."
|
||||
systemctl status kanata.service
|
||||
}
|
||||
|
||||
# Stop the service.
|
||||
stop_service() {
|
||||
log "Stopping kanata service..."
|
||||
sudo systemctl stop kanata.service
|
||||
}
|
||||
|
||||
# Disable the kanata systemd service.
|
||||
disable_service() {
|
||||
log "Disabling kanata service..."
|
||||
stop_service
|
||||
sudo systemctl disable kanata.service
|
||||
}
|
||||
|
||||
# Restart the kanata systemd service.
|
||||
restart_service() {
|
||||
log "Restarting kanata service..."
|
||||
sudo systemctl restart kanata.service
|
||||
}
|
||||
|
||||
# Handles both install or update commands, as they do the same thing, just need to pass in the
|
||||
# "Updating" argument when updating, so log messages are clear.
|
||||
install_or_update() {
|
||||
local mode=${1:-"Installing"}
|
||||
|
||||
log "$mode kanata..."
|
||||
local should_pull="1"
|
||||
|
||||
if [[ ! -d $kanata_dir ]]; then
|
||||
log "Cloning repo."
|
||||
should_pull="0"
|
||||
git clone $kanata_url $kanata_dir
|
||||
fi
|
||||
|
||||
pushd $kanata_dir &>/dev/null
|
||||
(
|
||||
[[ $should_pull == "1" ]] && git pull origin main >/dev/null 2>&1
|
||||
prompt_for_version_to_install | compare_versions | build_selection | copy_to_usr_bin
|
||||
)
|
||||
popd &>/dev/null
|
||||
}
|
||||
|
||||
# Bootstrap a new machine, by building and installing the kanata executable,
|
||||
# installing the systemd service files, and enable / start the service.
|
||||
bootstrap() {
|
||||
log "Bootstrapping new system..."
|
||||
install_or_update
|
||||
install_service
|
||||
enable_and_start_service
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# MAIN
|
||||
################################################################################
|
||||
|
||||
# Setup logging file and label.
|
||||
source "$SCRIPTS/hypr/logging"
|
||||
setup-logging "$LOG_FILE" "$LOG_LABEL"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||
usage && exit 0
|
||||
elif [[ $1 == "bootstrap" ]]; then
|
||||
bootstrap && exit 0
|
||||
elif [[ $1 == "disable" ]]; then
|
||||
disable_service && exit $?
|
||||
elif [[ $1 == "start" ]]; then
|
||||
enable_and_start_service && exit 1
|
||||
elif [[ $1 == "install" ]]; then
|
||||
install_or_update && exit $?
|
||||
elif [[ $1 == "logs" ]]; then
|
||||
bat ${LOG_DIR:-/tmp/logs}/$LOG_FILE && exit 0
|
||||
elif [[ $1 == "status" ]]; then
|
||||
get_status && exit $?
|
||||
elif [[ $1 == "stop" ]]; then
|
||||
stop_service && exit $?
|
||||
elif [[ $1 == "restart" ]]; then
|
||||
restart_service && exit 0
|
||||
elif [[ $1 == "update" ]]; then
|
||||
install_or_update "Updating" && exit 0
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# If we've made it here, then we didn't handle the command.
|
||||
usage && exit 1
|
||||
12
env/etc/systemd/system/kanata.service
vendored
Normal file
12
env/etc/systemd/system/kanata.service
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Kanata Service
|
||||
Requires=local-fs.target
|
||||
After=local-fs.target
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/usr/bin/modprobe uinput
|
||||
ExecStart=/usr/bin/kanata --cfg /home/michael/.config/kanata/config.kbd
|
||||
Restart=no
|
||||
|
||||
[Install]
|
||||
WantedBy=sysinit.target
|
||||
5
runs/kanata
Executable file
5
runs/kanata
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
yay ${1:-"-S --noconfirm"} rustup
|
||||
|
||||
$DEV_ENV/env/.local/scripts/kanatactl bootstrap
|
||||
Reference in New Issue
Block a user