Update swap_mode.sh to take parametes to specify specific modes

This commit is contained in:
Alex Selimov 2025-09-17 09:14:53 -04:00
parent d36ded958e
commit 9ed95658f8
No known key found for this signature in database
GPG key ID: BC03C17FF5CFFFD2

View file

@ -6,26 +6,37 @@ GHOSTTY_CONF="${HOME}/.config/ghostty/config"
[ -f "$NVIM_CONF" ] || { echo "Missing $NVIM_CONF"; exit 1; } [ -f "$NVIM_CONF" ] || { echo "Missing $NVIM_CONF"; exit 1; }
[ -f "$GHOSTTY_CONF" ] || { echo "Missing $GHOSTTY_CONF"; exit 1; } [ -f "$GHOSTTY_CONF" ] || { echo "Missing $GHOSTTY_CONF"; exit 1; }
# Toggle Ghostty theme between zenwritten-dark and zenwritten-light set_light_mode() {
sed -E -i '' \ sed -E -i '' 's/^([[:space:]]*theme[[:space:]]*=[[:space:]]*)zenwritten-dark/\1zenwritten-light/' "$GHOSTTY_CONF"
-e 's/^([[:space:]]*theme[[:space:]]*=[[:space:]]*)zenwritten-dark/\1zenwritten-light/' \ sed -E -i '' 's/(vim.g.light_mode[[:space:]]*=[[:space:]]*).*/\1true/' "$NVIM_CONF"
-e 't' \
-e 's/^([[:space:]]*theme[[:space:]]*=[[:space:]]*)zenwritten-light/\1zenwritten-dark/' \
"$GHOSTTY_CONF"
# Determine new mode from Ghostty theme
if grep -Eq '^\s*theme\s*=\s*zenwritten-light' "$GHOSTTY_CONF"; then
MODE="light" MODE="light"
# Toggle Neovim vim.g.light_mode true/false }
sed -E -i '' \
-e 's/(vim\.g\.light_mode[[:space:]]*=[[:space:]]*).*/\1true/' \ set_dark_mode() {
"$NVIM_CONF" sed -E -i '' 's/^([[:space:]]*theme[[:space:]]*=[[:space:]]*)zenwritten-light/\1zenwritten-dark/' "$GHOSTTY_CONF"
else sed -E -i '' 's/(vim.g.light_mode[[:space:]]*=[[:space:]]*).*/\1false/' "$NVIM_CONF"
MODE="dark" MODE="dark"
sed -E -i '' \ }
-e 's/(vim\.g\.light_mode[[:space:]]*=[[:space:]]*).*/\1false/' \
"$NVIM_CONF" toggle_mode() {
fi if grep -Eq '^\s*theme\s*=\s*zenwritten-light' "$GHOSTTY_CONF"; then
set_dark_mode
else
set_light_mode
fi
}
case "$1" in
light)
set_light_mode
;;
dark)
set_dark_mode
;;
toggle|*)
toggle_mode
;;
esac
# Reload neovim theme # Reload neovim theme
if [ "$MODE" = "light" ]; then if [ "$MODE" = "light" ]; then
@ -36,24 +47,13 @@ fi
for dir in "${XDG_RUNTIME_DIR:-}" "${TMPDIR:-/tmp}" "/tmp" "$HOME/.local/state/nvim"; do for dir in "${XDG_RUNTIME_DIR:-}" "${TMPDIR:-/tmp}" "/tmp" "$HOME/.local/state/nvim"; do
[ -d "$dir" ] || continue [ -d "$dir" ] || continue
find "$dir" -type s -name 'nvim*' 2>/dev/null | while read -r sock; do find "$dir" -type s -name 'nvim*' 2>/dev/null | while read -r sock; do
if command -v timeout >/dev/null 2>&1; then
timeout 1s nvim --server "$sock" --remote-send "$keys" >/dev/null 2>&1 || true timeout 1s nvim --server "$sock" --remote-send "$keys" >/dev/null 2>&1 || true
else
( nvim --server "$sock" --remote-send "$keys" >/dev/null 2>&1 & )
fi
done done
done done
# Reload Ghostty: send SIGUSR2 to running ghostty processes (macOS/Linux) # Reload Ghostty: send SIGUSR2 to running ghostty processes (macOS/Linux)
if command -v pkill >/dev/null 2>&1; then pkill -USR2 -x ghostty 2>/dev/null
pkill -USR2 -x ghostty 2>/dev/null || true
elif command -v killall >/dev/null 2>&1; then
killall -USR2 ghostty 2>/dev/null || true
else
pids=$(pgrep -x ghostty 2>/dev/null || true)
[ -n "${pids:-}" ] && kill -USR2 $pids || true
fi
echo "Switched to ${MODE} mode" echo "Switched to ${MODE} mode"