feat: Begins breaking kanatactl subcommands into their own files.

This commit is contained in:
2025-10-13 16:58:54 -04:00
parent ee2898053b
commit e77b3e7535
6 changed files with 298 additions and 136 deletions

View File

@@ -130,11 +130,6 @@
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)

View File

@@ -43,11 +43,12 @@
;; have the same number of keys as defsrc. Any keys not listed in defsrc will
;; be passed straight to the operating system.
(defsrc
= 1 2 3 4 5 6 7 8 9 0 -
grv q w e r t y u i o p \
esc a s d f g h j k l ; '
lsft z x c v b n m , . / rsft
ret tab bspc spc
;;----------------LEFT-------------------;------------------RIGHT-------------------;;
= 1 2 3 4 5 6 7 8 9 0 -
grv q w e r t y u i o p \
esc a s d f g h j k l ; '
lsft z x c v b n m , . / rsft
ret tab bspc spc
)
(defalias
@@ -92,29 +93,32 @@
;; BLANK LAYER
;; (deflayer {{NAME}}
;; = 1 2 3 4 5 6 7 8 9 0 -
;; grv q w e r t y u i o p \
;; esc a s d f g h j k l ; '
;; lsft z x c v b n m , . / rsft
;; ret tab bspc spc
;;;;----------------LEFT-------------------;------------------RIGHT-------------------;;
;; = 1 2 3 4 5 6 7 8 9 0 -
;; grv q w e r t y u i o p \
;; esc a s d f g h j k l ; '
;; lsft z x c v b n m , . / rsft
;; ret tab bspc spc
;; )
;; Main layer
(deflayer main
= 1 2 3 4 5 6 7 8 9 0 -
grv q w e r t y u i o p \
@mlms @mlctl @mlalt @mlmet @mlsft g h @mrsft @mrmet @mralt @mrctl @mrms
lsft z x c v b n m , . / rsft
@mlnums tab @mhypr @mrnums
;;----------------LEFT----------------------------;-------------------------RIGHT---------------------------;;
= 1 2 3 4 5 6 7 8 9 0 -
grv q w e r t y u i o p \
@mlms @mlctl @mlalt @mlmet @mlsft g h @mrsft @mrmet @mralt @mrctl @mrms
lsft z x c v b n m , . / rsft
@mlnums tab @mhypr @mrnums
)
;; Number and Symbols layer
(deflayer nums_and_symbols
= XX XX XX XX XX XX XX XX XX XX -
S-grv S-1 S-9 S-0 S-2 XX - 1 2 3 \ \
XX [ ] S-[ S-] XX S-= 4 5 6 . '
lsft S-7 S-8 S-3 S-4 XX S-8 7 8 9 / rsft
@mlnums tab @mhypr 0
;;----------------LEFT-----------------------;--------------------RIGHT-------------------;;
= XX XX XX XX XX XX XX XX XX XX -
S-grv S-1 S-9 S-0 S-2 XX - 1 2 3 \ \
XX [ ] S-[ S-] XX S-= 4 5 6 . '
lsft S-7 S-8 S-3 S-4 XX S-8 7 8 9 / rsft
@mlnums tab @mhypr 0
)
(defalias
@@ -123,11 +127,6 @@
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)
@@ -140,9 +139,10 @@
;; Mouse and arrow layer
(deflayer mouse
XX XX XX XX XX XX XX XX XX XX XX XX
XX XX XX XX XX @mwl @mwd @mwu @mwr XX XX
XX XX XX @ma← @ma↓ @ma↑ @ma→ XX XX
XX XX XX XX XX XX XX XX XX XX XX XX
ret tab mltp mrtp
;;----------------LEFT-------------------;------------------RIGHT-------------------;;
XX brdn bru XX XX XX XX XX mute vold volu XX
XX XX XX XX XX @mwl @mwd @mwu @mwr XX XX
XX XX ▼ ▶ XX @ma← @ma↓ @ma↑ @ma→ XX XX
XX XX XX XX XX XX XX XX XX XX XX XX
ret tab mltp mrtp
)

View File

@@ -176,6 +176,7 @@ alias gs='git status' # git status quickly
alias hn='hugo new' # generate a hugo site
alias hnc='hugo new content' # generate new hugo site content quickly
alias j='just' # run justfile's quickly.
alias kb='kanatactl' # Keyboard / kanata commands.
alias l='eza --long --git --group --links --icons --all' # better ls command.
alias lfs='ls -lahH --color=auto "$ZDOTDIR/functions"' # List functions.
alias ls='eza --long --git --group --links --icons --all'

View File

@@ -29,16 +29,14 @@ FLAGS:
COMMANDS:
bootstrap: Bootstrap a new machine, performs installation, enables, and starts kanata systemd service.
config <kbd>: Copy the keyboard configuration files for the keyboard type (macbook or voyager).
disable: Stop and disable the kanata systemd service.
config: Commands for the kanata keyboard configuration file(s).
service: Commands for 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.
Run "$THIS <command> --help" for more information about a command.
EOF
}
@@ -146,59 +144,6 @@ copy_to_usr_bin() {
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() {
@@ -230,37 +175,6 @@ bootstrap() {
enable_and_start_service
}
# Copy the configuration files based on keyboard type (either macbook or voyager).
copy_config() {
local kbd=${1:-""}
if [[ -z $kbd ]] && [[ -n $KBD ]]; then
kbd=$KBD
fi
if [[ -z $DEV_ENV ]]; then
log --error "DEV_ENV not set properly." && exit 1
fi
if [[ -z $kbd ]]; then
log --error "Keyboard not set." && exit 1
fi
log "Copying configuration: '$kbd'..."
mkdir $XDG_CONFIG_HOME/kanata &>/dev/null
if [[ $kbd == "macbook" ]]; then
log "Copying macbook configuration."
cp "$DEV_ENV/env/.config/kanata/config.kbd" "$XDG_CONFIG_HOME/kanata/config.kbd"
elif [[ $kbd == "voyager" ]]; then
log "Copying voyager configuration."
cp "$DEV_ENV/env/.config/kanata/voyager.kbd" "$XDG_CONFIG_HOME/kanata/config.kbd"
else
log --error "Invalid keyboard: '$kbd'" && exit 1
fi
}
################################################################################
# MAIN
################################################################################
@@ -276,21 +190,16 @@ while [[ $# -gt 0 ]]; do
bootstrap && exit 0
elif [[ $1 == "config" ]]; then
shift
copy_config "$@" && exit $?
elif [[ $1 == "disable" ]]; then
disable_service && exit $?
elif [[ $1 == "start" ]]; then
enable_and_start_service && exit 1
THIS="$THIS config" $SCRIPTS/utils/kanatactl/config "$@"
exit $?
elif [[ $1 == "service" ]]; then
shift
THIS="$THIS service" $SCRIPTS/utils/kanatactl/service "$@"
exit $?
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

136
env/.local/scripts/utils/kanatactl/config vendored Executable file
View File

@@ -0,0 +1,136 @@
#!/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"}
DEV_ENV=${DEV_ENV:-""}
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"}
KBD=${KBD:-""} # Keyboard config to use, either "voyager" or "macbook"
FZF_DEFAULT_OPTS=${FZF_DEFAULT_OPTS:-""}
install_mode="0"
update_mode="0"
usage() {
cat <<EOF
Manages the keyboard configuration file(s).
USAGE:
$ $THIS <command> <flags> <args...>
FLAGS:
-h | --help: Show this help page.
COMMANDS:
install <kbd>: Install the configuration files for the given keyboard.
update <kbd>: Update the configuration.
NOTES:
The 'kbd' argument is optional, if it is not supplied or found in either the
environment or configuration directory, then we will prompt which keyboard
configuration you would like to use. Once it has been setup the first time it
should not need to be supplied again, unless you are changing keyboard configurations.
ENVIRONMENT:
KBD: Sets the keyboard (<kbd>) that should be installed.
KBD FILE:
The kbd type can also be discovered from a file at '$XDG_CONFIG_HOME/kanata/kbd.txt'.
EOF
}
# Logging utility function, use in place of echo.
log() {
logging log --source "$THIS_FILE" "$@"
}
get_kbd() {
local kbd=${1:-""}
if [[ -z $kbd ]]; then
# check if it's set in the environment.
if [[ -n $KBD ]]; then
kbd=$KBD
elif [[ -f $XDG_CONFIG_HOME/kanata/kbd.txt ]]; then
# check if it's set in the config directory.
kbd=$(cat $XDG_CONFIG_HOME/kanata/kbd.txt)
fi
fi
echo "$kbd"
}
prompt_for_kbd() {
if [[ -z $DEV_ENV ]]; then
log --error "DEV_ENV is not set properly." && exit 1
fi
# Setup fzf color scheme if it's not setup yet.
[[ -z $FZF_DEFAULT_OPTS ]] && source "$SCRIPTS/catppuccin-colors"
echo $(/bin/ls $DEV_ENV/env/.config/kanata | fzf --header="Which keyoard configuration would you like to use?")
}
title() {
if [[ $install_mode == "1" ]] || [[ ! $update_mode == "1" ]]; then
echo "Installing"
else
echo "Updating"
fi
}
install_or_update() {
local kbd=$(get_kbd ${1:-""})
if [[ -z $kbd ]]; then
kbd=$(prompt_for_kbd)
if [[ -z $kbd ]]; then
log --error "No keyboard setup or selected." && exit 1
fi
fi
# Ensure the file extension is on the kbd variable.
if [[ ! $kbd =~ ".kbd" ]]; then
kbd="$kbd.kbd"
fi
log "$(title) '$kbd' configuration."
# Ensure the kanata config directory exists
[[ ! -d $XDG_CONFIG_HOME/kanata ]] && mkdir $XDG_CONFIG_HOME/kanata
cp --force $DEV_ENV/env/.config/kanata/$kbd $XDG_CONFIG_HOME/kanata/config.kbd
echo "$kbd" >$XDG_CONFIG_HOME/kanata/kbd.txt
}
################################################################################
# MAIN
################################################################################
# Setup logging file and label.
source "$SCRIPTS/hypr/logging"
setup-logging "$LOG_FILE" "$LOG_LABEL"
while [[ $# -gt 0 ]]; do
if [[ $1 == "install" ]]; then
install_mode="1"
shift
install_or_update "$@" && exit $?
elif [[ $1 == "update" ]]; then
update_mode="1"
shift
install_or_update "$@" && exit $?
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
usage && exit 0
fi
done
# If we made it here, then none of the commands handled the args, so
# show the usage and exit.
usage && exit 1

121
env/.local/scripts/utils/kanatactl/service vendored Executable file
View File

@@ -0,0 +1,121 @@
#!/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"}
DEV_ENV=${DEV_ENV:-""}
usage() {
cat <<EOF
Manages the kanata systemd service.
USAGE:
$ $THIS <command> <flags> <args...>
FLAGS:
-h | --help: Show this help page.
COMMANDS:
enable: Enable the kanata service.
disable: Disable the kanata service.
install <kbd>: Install the systemd service, the 'kbd' argument is passed to
'kanatactl config install' command, to ensure the keyboard configuration
is installed otherwise the keyboard may not work when the service is started.
start: Start the kanata service.
status: Get the status of the kanata service.
stop: Start the kanata service.
restart: Restart the kanata service.
EOF
}
# Logging utility function, use in place of echo.
log() {
logging log --source "$THIS_FILE" "$@"
}
enable_service() {
log "Enabling kanata service..."
sudo systemctl enable kanata.service
}
get_status() {
log "Getting kanata service status..."
systemctl status kanata.service
}
install_service() {
if [[ -z $DEV_ENV ]]; then
log --error "DEV_ENV is not set properly." && exit 1
fi
# Ensure the configuration is copied / setup otherwise the keyboard may not work.
"$SCRIPTS/kanatactl" config install "$@"
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
}
start_service() {
log "Starting kanata service..."
systemctl start kanata.service
}
stop_service() {
log "Stopping kanata service..."
sudo systemctl stop kanata.service
}
disable_service() {
log "Disabling kanata service..."
stop_service
sudo systemctl disable kanata.service
}
restart_service() {
log "Restarting kanata service..."
sudo systemctl restart kanata.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 == "disable" ]]; then
disable_service && exit $?
elif [[ $1 == "enable" ]]; then
enable_service && exit $?
elif [[ $1 == "install" ]]; then
shift
install_service "$@" && exit $?
elif [[ $1 == "start" ]]; then
start_service && exit $?
elif [[ $1 == "status" ]]; then
get_status && exit $?
elif [[ $1 == "stop" ]]; then
stop_service && exit $?
elif [[ $1 == "restart" ]]; then
restart_service && exit $?
fi
done
# If we made it here, then none of the subcommands handled the args.
usage && exit 1