bootstrap and system config improvements

This commit is contained in:
Barrett Ruth 2026-02-08 18:22:31 -05:00
parent 745075530c
commit cce3b87edb
17 changed files with 513 additions and 141 deletions

View file

@ -1,21 +1,34 @@
#!/bin/sh
require() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "ctl: missing dependency: $cmd" >&2
exit 1
}
done
}
case "$1" in
screenshot)
dir="$HOME/img/ss"
mkdir -p "$dir"
file="$dir/$(openssl rand -hex 10)-$(date +'%Y-%m-%d_%H-%M-%S').png"
if [ "${XDG_SESSION_TYPE:-}" = "wayland" ]; then
require grim slurp wl-copy
grim -g "$(slurp)" "$file" && wl-copy < "$file"
else
require maim xclip
maim -s "$file" && xclip -selection clipboard -t image/png -i "$file" &
fi
;;
ocr)
require tesseract
dir="$HOME/img/ss"
mkdir -p "$dir"
file="$dir/$(openssl rand -hex 10)-$(date +'%Y-%m-%d_%H-%M-%S').png"
if [ "${XDG_SESSION_TYPE:-}" = "wayland" ]; then
require grim slurp wl-copy
(
region="$(slurp)"
[ -n "$region" ] || exit 0
@ -23,6 +36,7 @@ ocr)
tesseract -l eng "$file" - 2>/dev/null | wl-copy
) </dev/null >/dev/null 2>&1 &
else
require maim xclip
(
maim -s "$file" &&
tesseract -l eng "$file" - 2>/dev/null | xclip -selection clipboard -in
@ -58,6 +72,7 @@ keyboard)
esac
;;
audio)
require pactl
case "$2" in
out)
sinks="$(pactl list short sinks | awk '{print $1": "$2}')"

View file

@ -1,11 +1,24 @@
#!/bin/sh
require() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "doc: missing dependency: $cmd" >&2
exit 1
}
done
}
require sioyek
dir="$HOME/doc"
test -d "$dir" || exit
if [ "$XDG_SESSION_TYPE" = x11 ]; then
require dmenu
picker() { dmenu -i -l 10 -p "Select file or folder: "; }
else
require rofi
picker() { rofi -dmenu -i -l 10 -p "Select file or folder"; }
fi

View file

@ -1,5 +1,14 @@
#!/bin/sh
require() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "hypr: missing dependency: $cmd" >&2
exit 1
}
done
}
usage() {
cat <<EOF
Usage: hypr <subcommand> [app] [args...]
@ -9,7 +18,7 @@ Commands:
brightness {up,down} Adjust brightness accordingly and notify
spawnfocus <app> [args...] Focus existing window or spawn app with args
pull [app] Pull window to current workspace (picker if no app)
borders Initialize dynamic borders
windowrules Apply dynamic window rules
exit Safely exit hyprland
Options:
@ -31,12 +40,14 @@ case "$cmd" in
exit 0
;;
exit)
require hyprctl
pkill hypridle
pkill hyprpaper
hyprctl dispatch exit
exit 0
;;
brightness)
require brightnessctl notify-send
BRIGHT_STEP=5
max_brightness="$(brightnessctl max)"
case "$1" in
@ -55,6 +66,7 @@ brightness)
esac
;;
volume)
require pactl notify-send
SINK="@DEFAULT_SINK@"
VOL_STEP=5
get_vol() { pactl get-sink-volume "$SINK" | awk 'NR==1{print $5+0}'; }
@ -92,60 +104,72 @@ volume)
fi
;;
pull)
require hyprctl jq rofi
APP="$1"
if [ -n "$APP" ]; then
case "$APP" in
google-chrome | google-chrome-stable) CLASS="google-chrome" ;;
chromium | ungoogled-chromium) CLASS="Chromium" ;;
firefox) CLASS="firefox" ;;
alacritty) CLASS="Alacritty" ;;
code | vscodium) CLASS="Code" ;;
signal-desktop | signal) CLASS="signal" ;;
telegram-desktop | telegram) CLASS="TelegramDesktop" ;;
ghostty) CLASS="com.mitchellh.ghostty" ;;
bitwarden-desktop | bitwarden) CLASS="Bitwarden" ;;
slack) CLASS="Slack" ;;
discord) CLASS="discord" ;;
vesktop) CLASS="vesktop" ;;
*) CLASS="$APP" ;;
esac
CUR_ADDR=$(hyprctl -j activewindow | jq -r '.address')
WIN_ADDRS=$(
hyprctl -j clients 2>/dev/null | jq -r --arg class "$CLASS" '
.[]? | select(
((.xdgTag // "") | ascii_downcase | contains($class | ascii_downcase)) or
((.initialClass // "") | ascii_downcase | contains($class | ascii_downcase)) or
((.class // "") | ascii_downcase | contains($class | ascii_downcase))
) | "\(.class)\t\(.title)\t\(.address)"'
)
WIN_COUNT=$(echo "$WIN_ADDRS" | grep -c .)
if [ "$WIN_COUNT" -eq 1 ]; then
WIN_ADDR=$(echo "$WIN_ADDRS" | awk -F'\t' '{print $3}')
elif [ "$WIN_COUNT" -gt 1 ]; then
SELECTED=$(echo "$WIN_ADDRS" |
awk -F'\t' -v cur="$CUR_ADDR" '{if($3!=cur) print $1 ": " $2 "\t" $3}' |
rofi -dmenu -i -p "pull window")
WIN_ADDR=$(echo "$SELECTED" | awk -F'\t' '{print $2}')
fi
fi
if [ -z "$SELECTED" ]; then
case "$APP" in
google-chrome | google-chrome-stable) CLASS="google-chrome" ;;
zen | zen-browser) CLASS="zen" ;;
chromium | ungoogled-chromium) CLASS="Chromium" ;;
firefox) CLASS="firefox" ;;
alacritty) CLASS="Alacritty" ;;
code | vscodium) CLASS="Code" ;;
signal-desktop | signal) CLASS="signal" ;;
telegram-desktop | telegram) CLASS="TelegramDesktop" ;;
ghostty) CLASS="com.mitchellh.ghostty" ;;
bitwarden-desktop | bitwarden) CLASS="Bitwarden" ;;
slack) CLASS="Slack" ;;
discord) CLASS="discord" ;;
vesktop) CLASS="vesktop" ;;
element-desktop | element) CLASS="element" ;;
*) CLASS="$APP" ;;
esac
CUR_WS=$(hyprctl activeworkspace -j | jq -r '.id')
CUR_ADDR=$(hyprctl -j activewindow | jq -r '.address // empty')
WIN_ADDRS=$(hyprctl -j clients 2>/dev/null | jq -r --arg pat "$CLASS" '
.[]?
| select(
(.class? | ascii_downcase | contains($pat | ascii_downcase)) or
(.initialClass? | ascii_downcase | contains($pat | ascii_downcase)) or
(.xdgTag? // "" | ascii_downcase | contains($pat | ascii_downcase))
)
| "\(.class)\t\(.title // "no title")\t\(.address)"
')
WIN_COUNT=$(echo "$WIN_ADDRS" | grep -c '^' || :)
if [ "$WIN_COUNT" -eq 0 ]; then
exit 0
fi
if [ -z "$WIN_ADDR" ]; then
CUR_ADDR=$(hyprctl -j activewindow | jq -r '.address')
WIN_ADDRS=$(hyprctl -j clients 2>/dev/null | jq -r '.[]? | "\(.class)\t\(.title)\t\(.address)"')
SELECTED=$(echo "$WIN_ADDRS" |
awk -F'\t' -v cur="$CUR_ADDR" '{if($3!=cur) print $1 ": " $2 "\t" $3}' |
rofi -dmenu -i -p "pull window")
if [ "$WIN_COUNT" -eq 1 ]; then
WIN_ADDR=$(echo "$WIN_ADDRS" | awk -F'\t' '{print $3}')
else
ROFI_LINES=$(
echo "$WIN_ADDRS" |
awk -F'\t' -v cur="$CUR_ADDR" '
$3 != cur { printf "%s : %s\t%s\n", $1, $2, $3 }
'
)
[ -z "$ROFI_LINES" ] && exit 0
SELECTED=$(echo "$ROFI_LINES" | rofi -dmenu -i -p "pull window")
[ -z "$SELECTED" ] && exit 0
WIN_ADDR=$(echo "$SELECTED" | awk -F'\t' '{print $2}')
fi
if [ -n "$WIN_ADDR" ]; then
CURRENT_WS="$(hyprctl activeworkspace | head -n1 | awk -F'[()]' '{print $2}')"
hyprctl dispatch movetoworkspace "$CURRENT_WS,address:$WIN_ADDR"
hyprctl dispatch focuswindow "address:$WIN_ADDR"
fi
[ -z "$WIN_ADDR" ] && exit 0
hyprctl dispatch movetoworkspace "${CUR_WS},address:${WIN_ADDR}"
hyprctl dispatch focuswindow "address:${WIN_ADDR}"
;;
spawnfocus)
require hyprctl jq rofi socat
WS=""
while [ $# -gt 0 ]; do
case "$1" in
@ -177,6 +201,7 @@ spawnfocus)
case "$APP" in
google-chrome | google-chrome-stable) CLASS="google-chrome" ;;
chromium | ungoogled-chromium) CLASS="Chromium" ;;
zen | zen-browser) CLASS="zen" ;;
firefox) CLASS="firefox" ;;
alacritty) CLASS="Alacritty" ;;
code | vscodium) CLASS="Code" ;;
@ -187,6 +212,7 @@ spawnfocus)
slack) CLASS="Slack" ;;
discord) CLASS="discord" ;;
vesktop) CLASS="vesktop" ;;
element-desktop | element) CLASS="element" ;;
*) CLASS="$APP" ;;
esac
@ -275,6 +301,31 @@ spawnfocus)
done
fi
;;
windowrules)
require hyprctl socat
socat -u UNIX-CONNECT:"$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" - | while IFS= read -r line; do
event="${line%%>>*}"
data="${line#*>>}"
case "$event" in
windowtitlev2)
window_id="${data%%,*}"
window_title="${data#*,}"
window_title=$(echo "$window_title" | tr '[:upper:]' '[:lower:]')
case "$window_title" in
*'extension: (bitwarden password manager) - bitwarden'*)
hyprctl --batch "dispatch setfloating address:0x$window_id; dispatch centerwindow address:0x$window_id"
;;
*'sign in - google accounts '*)
hyprctl --batch "dispatch setfloating address:0x$window_id; \
dispatch resizewindowpixel exact 30% 70%,address:0x$window_id; \
dispatch centerwindow address:0x$window_id"
;;
esac
;;
esac
done
;;
*)
echo "Unknown subcommand: $cmd"
usage

View file

@ -1,7 +1,27 @@
#!/bin/sh
require() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "mux: missing dependency: $cmd" >&2
exit 1
}
done
}
require tmux
get_scope() {
_wname=$(tmux display-message -p '#{window_name}')
case "$_wname" in
ai@*|code@*|git@*|run@*|term@*|misc@*) printf '%s' "${_wname#*@}" ;;
*) printf '%s' "$_wname" ;;
esac
}
spawn_or_focus() {
name="$1"
scope=$(get_scope)
name="${1}@${scope}"
cmd="$2"
if tmux list-windows -F '#{window_name}' | grep -Fx "$name" >/dev/null; then
@ -15,12 +35,69 @@ spawn_or_focus() {
fi
}
pick_session() {
require fzf column
sel=$({
printf 'name\twindows\tstatus\n'
tmux list-sessions -F '#{session_name} #{session_windows}w #{?session_attached,*,}'
} | column -t -s "$(printf '\t')" |
fzf --reverse --header-lines 1 --prompt 'select-session> ')
[ -n "$sel" ] && tmux switch-client -t "${sel%% *}"
}
pick_window() {
require fzf column
sel=$({
printf 'target\tname\tcommand\tpanes\n'
tmux list-windows -a -F '#{window_index}:#{session_name} #{window_name} #{pane_current_command} #{window_panes}p'
} | column -t -s "$(printf '\t')" |
fzf --reverse --header-lines 1 --prompt 'select-window> ')
sel="${sel%% *}"
[ -n "$sel" ] && tmux switch-client -t "${sel#*:}:${sel%%:*}"
}
pick_pane() {
require fzf column
sel=$({
printf 'target\tcommand\tpath\n'
tmux list-panes -a -F '#{window_index}.#{pane_index}:#{session_name} #{pane_current_command} #{pane_current_path}' |
sed "s|$HOME|~|g"
} | column -t -s "$(printf '\t')" |
fzf --reverse --header-lines 1 --prompt 'select-pane> ')
sel="${sel%% *}"
[ -n "$sel" ] && tmux switch-client -t "${sel#*:}:${sel%%:*}"
}
target_pane() {
require fzf column
sel=$({
printf 'target\tcommand\tpath\n'
tmux list-panes -a -F '#{window_index}.#{pane_index}:#{session_name} #{pane_current_command} #{pane_current_path}' |
sed "s|$HOME|~|g"
} | column -t -s "$(printf '\t')" |
fzf --reverse --header-lines 1 --prompt "$1> ")
sel="${sel%% *}"
[ -n "$sel" ] && printf '%s' "${sel#*:}:${sel%%:*}"
}
confirm() {
printf '%s ' "$1"
old=$(stty -g)
stty raw -echo
c=$(dd bs=1 count=1 2>/dev/null)
stty "$old"
printf '\n'
[ "$c" = "y" ]
}
case "$1" in
bar)
[ "$2" ] || exit
mouse=""
if [ "$(tmux show-options | grep mouse | awk '{ print $NF }')" = "on" ]; then
mouse='[m]'
session=$(tmux display-message -p '#S')
[ "$session" ] || exit
if [ "$(tmux show-options -gv mouse)" = "on" ]; then
indicator='#{?pane_in_mode,[mouse#{@c}copy],[mouse]}'
else
indicator='#{?pane_in_mode,[copy],}'
fi
set -f
keys="H J K L"
@ -38,67 +115,39 @@ bar)
key='?'
fi
star=""
[ "$sname" = "$2" ] && star="*"
bar_content="$bar_content#[range=session|${sid}]$key:$sname$star#[norange] "
[ "$sname" = "$session" ] && star="*"
[ -n "$bar_content" ] && bar_content="$bar_content │ "
bar_content="$bar_content#[range=session|${sid}]$key:$sname$star#[norange]"
i=$((i + 1))
done
set +f
left='#[align=left list=on] #{W:#[range=window|#{window_index}]#{window_index}:#{window_name}#{window_flags}#[norange] }#[nolist]'
right="#[align=right]$mouse $bar_content"
left='#[align=left list=on] #{W:#[range=window|#{window_index}]#{window_index}:#{window_name}#{window_flags}#[norange]#{?window_end_flag,, │ }}#[nolist]'
right="#[align=right]$indicator $bar_content"
tmux set -g 'status-format[0]' "$left$right"
;;
switch)
session="$(tmux ls -F '#S' | tail -n "+$(($2 + 1))" | head -1)"
tmux switch -t "$session"
;;
exec)
name="$(basename "$PWD")"
project="$(basename "$(dirname "$PWD")")/$name"
case "$project" in
*/bmath)
cmd='cmake -B build -DCMAKE_BUILD_TYPE=Debug && cmake --build build && ctest --test-dir build --output-on-failure'
;;
*/ag)
cmd='cp -f autograder.py example && cd example && ./run_autograder'
;;
*/project-a-10)
cmd='. venv/bin/activate && python manage.py runserver'
;;
*/theCourseForum2)
cmd='docker compose up'
;;
*/atlas | */tinyground)
cmd='pnpm run dev'
;;
*/interview-prep)
cmd='pnpm run dev'
;;
*/neovim)
cmd='make'
;;
*/TestCppClient)
cmd='rm -f TestCppClientStatic && cmake -S . -B build/ && make && ./TestCppClientStatic'
;;
sl/*)
cmd='make clean install && make clean'
[ "$name" = 'slock' ] && cmd="doas $cmd"
;;
*/barrettruth.com)
cmd='pnpm dev'
;;
esac
echo " > $cmd" | sed "s|$HOME|~|g"
eval "$cmd"
pick-session)
pick_session
;;
claude)
spawn_or_focus claude 'claude --chrome'
pick-window)
pick_window
;;
nvim)
spawn_or_focus nvim 'nvim -c "lua require([[config.tmux]]).run([[nvim]])"'
pick-pane)
pick_pane
;;
ai)
require claude
spawn_or_focus ai 'claude'
;;
code)
require nvim
spawn_or_focus code 'nvim -c "lua require([[config.tmux]]).run([[nvim]])"'
;;
git)
require nvim git
pane_path=$(tmux display-message -p '#{pane_current_path}')
if ! git -C "$pane_path" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
tmux display-message "Not a git repository"
@ -107,11 +156,85 @@ git)
fi
;;
run)
require nvim
spawn_or_focus run 'nvim -c "lua require([[config.tmux]]).run([[run]])"'
;;
term)
spawn_or_focus term
;;
misc)
spawn_or_focus misc
;;
cmd)
require fzf
result=$(tmux list-commands |
sed 's/ / /' |
fzf --reverse --prompt ':' --print-query \
--delimiter '\t' --with-nth '1,2' --accept-nth '1' \
--bind 'ctrl-y:transform-query(echo {1})+disable-search')
rc=$?
query=$(printf '%s' "$result" | head -1)
action=$(printf '%s' "$result" | sed -n '2p')
[ $rc -eq 130 ] && exit
if [ -n "$action" ]; then
case "$query" in
"$action "*)
tmux $query
exit
;;
esac
case "$action" in
switch-client) pick_session ;;
select-window) pick_window ;;
select-pane) pick_pane ;;
rename-window)
cur=$(tmux display-message -p '#{window_name}')
printf 'name [%s]: ' "$cur"
read -r name
[ -n "$name" ] && tmux rename-window "$name"
;;
rename-session)
cur=$(tmux display-message -p '#S')
printf 'name [%s]: ' "$cur"
read -r name
[ -n "$name" ] && tmux rename-session "$name"
;;
join-pane)
target=$(target_pane 'join-pane')
[ -n "$target" ] && tmux join-pane -s "$target"
;;
swap-pane)
target=$(target_pane 'swap-pane')
[ -n "$target" ] && tmux swap-pane -t "$target"
;;
select-layout)
layout=$(printf '%s\n' \
'even-horizontal' \
'even-vertical' \
'main-horizontal' \
'main-vertical' \
'tiled' |
fzf --reverse --prompt 'layout> ')
[ -n "$layout" ] && tmux select-layout "$layout"
;;
kill-pane)
confirm 'kill-pane? [y/N]:' && tmux kill-pane
;;
kill-window)
confirm "kill-window \"$(tmux display-message -p '#{window_name}')\"? [y/N]:" && tmux kill-window
;;
kill-session)
confirm "kill-session \"$(tmux display-message -p '#S')\"? [y/N]:" && tmux kill-session
;;
kill-server)
confirm 'kill-server? [y/N]:' && tmux kill-server
;;
*) tmux "$action" ;;
esac
elif [ -n "$query" ]; then
tmux $query
fi
;;
*)
tmux attach
;;

View file

@ -1,5 +1,14 @@
#!/bin/sh
require() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "theme: missing dependency: $cmd" >&2
exit 1
}
done
}
themes="daylight
midnight"
@ -11,8 +20,10 @@ Linux)
theme="$1"
else
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
require rofi
theme="$(printf "%s\n" "$themes" | rofi -dmenu -p 'theme')"
else
require dmenu
theme="$(printf "%s\n" "$themes" | dmenu -p 'select theme: ')"
fi
fi
@ -56,9 +67,10 @@ Linux)
midnight)
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
;;
*)
daylight)
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
;;
*) ;;
esac
fi
@ -95,27 +107,27 @@ Darwin)
;;
esac
if tmux list-sessions >/dev/null 2>&1; then
test -f "$XDG_CONFIG_HOME/tmux/tmux.conf" && tmux source-file "$XDG_CONFIG_HOME/tmux/tmux.conf"
[ "$TMUX" ] && tmux refresh-client -S
fi
test -d "$XDG_CONFIG_HOME/fzf/themes" && ln -sf "$XDG_CONFIG_HOME/fzf/themes/$theme" "$XDG_CONFIG_HOME/fzf/themes/theme"
test -d "$XDG_CONFIG_HOME/rg/themes" && ln -sf "$XDG_CONFIG_HOME/rg/themes/$theme" "$XDG_CONFIG_HOME/rg/themes/theme"
test -d "$XDG_CONFIG_HOME/sioyek/themes" && ln -sf "$XDG_CONFIG_HOME/sioyek/themes/$theme.config" "$XDG_CONFIG_HOME/sioyek/themes/theme.config"
test -d "$XDG_CONFIG_HOME/task/themes" && ln -sf "$XDG_CONFIG_HOME/task/themes/$theme.theme" "$XDG_CONFIG_HOME/task/themes/theme.theme"
if command -v claude >/dev/null 2>&1; then
CLAUDE_CONFIG="${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json"
claude_theme='light'
case "$theme" in
daylight)
claude config set theme light
claude_theme='light'
;;
midnight)
claude config set theme dark
claude_theme='dark'
;;
esac
test -f "$CLAUDE_CONFIG" && jq ".theme=\"$claude_theme\"" "$CLAUDE_CONFIG" >"$CLAUDE_CONFIG.tmp" && mv "$CLAUDE_CONFIG.tmp" "$CLAUDE_CONFIG"
fi
test -f ~/.zshenv && sed -i "s|^\(export THEME=\).*|\1$theme|" ~/.zshenv
[ -n "$TMUX" ] && tmux setenv -g THEME "$theme"
for socket in /tmp/nvim-*.sock; do
test -S "$socket" && nvim --server "$socket" --remote-expr "luaeval('require(\"config.fzf_reload\").reload()')" 2>/dev/null || true

View file

@ -5,7 +5,11 @@ import random
import subprocess
import sys
from PIL import Image, ImageDraw
try:
from PIL import Image, ImageDraw
except ImportError:
print("wp: missing dependency: pillow (pip install pillow)", file=sys.stderr)
sys.exit(1)
HOME = os.environ["HOME"]
DIR = f"{HOME}/img/screen"

View file

@ -1,9 +1,19 @@
#!/bin/sh
require() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "x: missing dependency: $cmd" >&2
exit 1
}
done
}
cmd="$1"; shift
case "$cmd" in
setup)
require xrdb xset xmodmap xss-lock slock
xrdb -merge "$XDG_CONFIG_HOME"/X11/xresources."$THEME"
xset b off
xset m 0
@ -14,6 +24,7 @@ setup)
xss-lock -- slock &
;;
bg)
require xrandr feh
randr="$(xrandr | rg ' connected ')"
mons="$(echo "$randr" | wc -l)"
wpdir="$HOME"/img/wp
@ -31,6 +42,7 @@ bg)
eval "$cmd"
;;
mon)
require xrandr
mons="$(xrandr | rg --no-config ' connected ' | awk '{ print $1 }')"
one="$(echo "$mons" | head -n 1)"