mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 17:01:01 +00:00
theme dark:light
This commit is contained in:
parent
7ae7c1ceec
commit
67128fe09b
7 changed files with 190 additions and 40 deletions
|
|
@ -16,14 +16,20 @@ read_mode() {
|
|||
|
||||
link_mode_assets() {
|
||||
local mode="$1"
|
||||
local ghostty_target
|
||||
local tmux_target
|
||||
local apple_dark_mode
|
||||
|
||||
case "$mode" in
|
||||
dark)
|
||||
ghostty_target="@GHOSTTY_DARK_FILE@"
|
||||
tmux_target="@TMUX_DARK_FILE@"
|
||||
apple_dark_mode=true
|
||||
;;
|
||||
light)
|
||||
ghostty_target="@GHOSTTY_LIGHT_FILE@"
|
||||
tmux_target="@TMUX_LIGHT_FILE@"
|
||||
apple_dark_mode=false
|
||||
;;
|
||||
*)
|
||||
echo "invalid mode: $mode" >&2
|
||||
|
|
@ -31,18 +37,40 @@ link_mode_assets() {
|
|||
;;
|
||||
esac
|
||||
|
||||
mkdir -p "@STATE_DIR@" "@TMUX_DIR@"
|
||||
mkdir -p "@STATE_DIR@" "@GHOSTTY_DIR@" "@TMUX_DIR@"
|
||||
printf '%s\n' "$mode" > "@STATE_FILE@"
|
||||
ln -sfn "$ghostty_target" "@GHOSTTY_CURRENT_FILE@"
|
||||
ln -sfn "$tmux_target" "@TMUX_CURRENT_FILE@"
|
||||
|
||||
if command -v tmux >/dev/null 2>&1 && tmux start-server >/dev/null 2>&1; then
|
||||
tmux source-file "@TMUX_CONFIG@" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
for socket in /tmp/nvim-*.sock; do
|
||||
if [[ "$(uname -s)" == "Darwin" ]] && command -v osascript >/dev/null 2>&1; then
|
||||
osascript -e "tell application \"System Events\" to tell appearance preferences to set dark mode to ${apple_dark_mode}" >/dev/null 2>&1 || true
|
||||
|
||||
osascript <<'EOF' >/dev/null 2>&1 || true
|
||||
tell application "System Events"
|
||||
if not (exists process "Ghostty") then
|
||||
return
|
||||
end if
|
||||
|
||||
tell process "Ghostty"
|
||||
click menu item "Reload Configuration" of menu 1 of menu bar item "Ghostty" of menu bar 1
|
||||
end tell
|
||||
end tell
|
||||
EOF
|
||||
fi
|
||||
|
||||
while IFS= read -r socket; do
|
||||
[[ -S "$socket" ]] || continue
|
||||
nvim --server "$socket" --remote-send "<Cmd>ThemeSync $mode<CR>" >/dev/null 2>&1 || true
|
||||
done
|
||||
nvim --server "$socket" --remote-expr "execute('ThemeSync $mode')" >/dev/null 2>&1 || true
|
||||
done < <(
|
||||
{
|
||||
find /tmp -maxdepth 1 -type s -name 'nvim-*.sock' 2>/dev/null
|
||||
find "${TMPDIR:-/tmp}" -type s -path "*/nvim.${USER}/*/nvim.*" 2>/dev/null
|
||||
} | sort -u
|
||||
)
|
||||
}
|
||||
|
||||
mode="${1:-current}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue