mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-15 22:52:37 +00:00
Compare commits
3 Commits
087d7963e8
...
e77b3e7535
| Author | SHA1 | Date | |
|---|---|---|---|
|
e77b3e7535
|
|||
|
ee2898053b
|
|||
|
f1202d77f3
|
2
dev-env
2
dev-env
@@ -45,7 +45,7 @@ update_dirs() {
|
|||||||
# Copy everything except systemd, share, and zsh folders, they need treated differently.
|
# Copy everything except systemd, share, and zsh folders, they need treated differently.
|
||||||
configs=$(
|
configs=$(
|
||||||
find . -mindepth 1 -maxdepth 1 -type d \
|
find . -mindepth 1 -maxdepth 1 -type d \
|
||||||
\( -name "systemd" -o -name "zsh" -o -name "share" -o -name "scripts" \) \
|
\( -name "systemd" -o -name "zsh" -o -name "share" -o -name "scripts" -o -name "kanata" \) \
|
||||||
-prune -o -type d -print
|
-prune -o -type d -print
|
||||||
)
|
)
|
||||||
for c in $configs; do
|
for c in $configs; do
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
;; Macbook-Pro configuration file.
|
||||||
|
;;
|
||||||
|
|
||||||
;; Adapted from https://github.com/linkarzu/dotfiles-latest/blob/main/kanata/configs/macbook-subl.kbd
|
;; Adapted from https://github.com/linkarzu/dotfiles-latest/blob/main/kanata/configs/macbook-subl.kbd
|
||||||
;; Video related to this file
|
;; Video related to this file
|
||||||
;; https://youtu.be/jvJ3f4HHiMY
|
;; https://youtu.be/jvJ3f4HHiMY
|
||||||
@@ -127,11 +130,6 @@
|
|||||||
mwl (mwheel-left 50 120)
|
mwl (mwheel-left 50 120)
|
||||||
mwr (mwheel-right 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-up 5 1000 1 3)
|
||||||
ma← (movemouse-accel-left 5 1000 1 3)
|
ma← (movemouse-accel-left 5 1000 1 3)
|
||||||
ma↓ (movemouse-accel-down 5 1000 1 3)
|
ma↓ (movemouse-accel-down 5 1000 1 3)
|
||||||
148
env/.config/kanata/voyager.kbd
vendored
Normal file
148
env/.config/kanata/voyager.kbd
vendored
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
;; ZSA Voyager configuration file.
|
||||||
|
;;
|
||||||
|
|
||||||
|
;; 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
|
||||||
|
;;----------------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
|
||||||
|
;; 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 ret (layer-while-held nums_and_symbols))
|
||||||
|
mrnums (tap-hold-press $tap-time-plus $hold-time-plus spc (layer-while-held nums_and_symbols))
|
||||||
|
|
||||||
|
;; mouse layer trigger keys.
|
||||||
|
mlms (tap-hold-press $tap-time $hold-time esc (layer-while-held mouse))
|
||||||
|
mrms (tap-hold-press $tap-time $hold-time ' (layer-while-held mouse))
|
||||||
|
|
||||||
|
;; Multi
|
||||||
|
mhypr (tap-hold $tap-time $hold-time bspc (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}}
|
||||||
|
;;;;----------------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
|
||||||
|
;;----------------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
|
||||||
|
;;----------------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
|
||||||
|
mwu (mwheel-up 50 120)
|
||||||
|
mwd (mwheel-down 50 120)
|
||||||
|
mwl (mwheel-left 50 120)
|
||||||
|
mwr (mwheel-right 50 120)
|
||||||
|
|
||||||
|
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
|
||||||
|
;;----------------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
|
||||||
|
)
|
||||||
1
env/.config/zsh/.zshrc
vendored
1
env/.config/zsh/.zshrc
vendored
@@ -176,6 +176,7 @@ alias gs='git status' # git status quickly
|
|||||||
alias hn='hugo new' # generate a hugo site
|
alias hn='hugo new' # generate a hugo site
|
||||||
alias hnc='hugo new content' # generate new hugo site content quickly
|
alias hnc='hugo new content' # generate new hugo site content quickly
|
||||||
alias j='just' # run justfile's 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 l='eza --long --git --group --links --icons --all' # better ls command.
|
||||||
alias lfs='ls -lahH --color=auto "$ZDOTDIR/functions"' # List functions.
|
alias lfs='ls -lahH --color=auto "$ZDOTDIR/functions"' # List functions.
|
||||||
alias ls='eza --long --git --group --links --icons --all'
|
alias ls='eza --long --git --group --links --icons --all'
|
||||||
|
|||||||
83
env/.local/scripts/kanatactl
vendored
83
env/.local/scripts/kanatactl
vendored
@@ -12,12 +12,13 @@ LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
|||||||
XDG_DATA_HOME=${XDG_DATA_HOME:-"$HOME/.local/share"}
|
XDG_DATA_HOME=${XDG_DATA_HOME:-"$HOME/.local/share"}
|
||||||
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"}
|
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"}
|
||||||
DEV_ENV=${DEV_ENV:-""}
|
DEV_ENV=${DEV_ENV:-""}
|
||||||
|
KBD=${KBD:-""} # Keyboard config to use, either "voyager" or "macbook"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
Manages kanata qmk keyboard program, which needs to be built locally. Currently the linux builds
|
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.
|
are only for x86. Also manages the kanata systemd service.
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
|
|
||||||
@@ -28,15 +29,14 @@ FLAGS:
|
|||||||
|
|
||||||
COMMANDS:
|
COMMANDS:
|
||||||
bootstrap: Bootstrap a new machine, performs installation, enables, and starts kanata systemd service.
|
bootstrap: Bootstrap a new machine, performs installation, enables, and starts kanata systemd service.
|
||||||
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.
|
install: Build and install kanata, prompts you to choose the version to install.
|
||||||
logs: View the log file.
|
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.
|
update: Pull from git and check for updates.
|
||||||
|
|
||||||
|
Run "$THIS <command> --help" for more information about a command.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,59 +144,6 @@ copy_to_usr_bin() {
|
|||||||
done
|
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
|
# 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.
|
# "Updating" argument when updating, so log messages are clear.
|
||||||
install_or_update() {
|
install_or_update() {
|
||||||
@@ -241,20 +188,18 @@ while [[ $# -gt 0 ]]; do
|
|||||||
usage && exit 0
|
usage && exit 0
|
||||||
elif [[ $1 == "bootstrap" ]]; then
|
elif [[ $1 == "bootstrap" ]]; then
|
||||||
bootstrap && exit 0
|
bootstrap && exit 0
|
||||||
elif [[ $1 == "disable" ]]; then
|
elif [[ $1 == "config" ]]; then
|
||||||
disable_service && exit $?
|
shift
|
||||||
elif [[ $1 == "start" ]]; then
|
THIS="$THIS config" $SCRIPTS/utils/kanatactl/config "$@"
|
||||||
enable_and_start_service && exit 1
|
exit $?
|
||||||
|
elif [[ $1 == "service" ]]; then
|
||||||
|
shift
|
||||||
|
THIS="$THIS service" $SCRIPTS/utils/kanatactl/service "$@"
|
||||||
|
exit $?
|
||||||
elif [[ $1 == "install" ]]; then
|
elif [[ $1 == "install" ]]; then
|
||||||
install_or_update && exit $?
|
install_or_update && exit $?
|
||||||
elif [[ $1 == "logs" ]]; then
|
elif [[ $1 == "logs" ]]; then
|
||||||
bat ${LOG_DIR:-/tmp/logs}/$LOG_FILE && exit 0
|
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
|
elif [[ $1 == "update" ]]; then
|
||||||
install_or_update "Updating" && exit 0
|
install_or_update "Updating" && exit 0
|
||||||
else
|
else
|
||||||
|
|||||||
136
env/.local/scripts/utils/kanatactl/config
vendored
Executable file
136
env/.local/scripts/utils/kanatactl/config
vendored
Executable 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
121
env/.local/scripts/utils/kanatactl/service
vendored
Executable 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
|
||||||
Reference in New Issue
Block a user