Skip to content

Commit

Permalink
Update switcher script
Browse files Browse the repository at this point in the history
  • Loading branch information
shapeshed committed Oct 2, 2023
1 parent abb9ca3 commit f98d077
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions content/posts/vim-tmux-alacritty-theme-switcher/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,38 +187,42 @@ really don't want to be doing this. If you think you can improve this, or know a
better way [send me a PR][11]. I'd love to delete this post.

```sh
#!/usr/bin/env sh
# Theme switch for firefox, tmux, alacritty and (neo)vim.
LIGHTTHEME=catppuccin-latte
DARKTHEME=catppuccin-mocha
VIMCONF=${XDG_CONFIG_HOME}/nvim/lua/config/set.lua
ALACRITTYCONF=${XDG_CONFIG_HOME}/alacritty/alacritty.yml
TMUXCONF=${XDG_CONFIG_HOME}/tmux/tmux.conf
if [ "$1" = "light" ]; then
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
sed -i 's/'"$DARKTHEME"'/'"$LIGHTTHEME"'/' "$ALACRITTYCONF"
sed -i 's/'"$DARKTHEME"'/'"$LIGHTTHEME"'/' "$TMUXCONF"
sed -i 's/dark/light/' "$VIMCONF"
#!/bin/sh
# Toggle dark and light themes for firefox, tmux, alacritty,
# and (neo)vim. Either run it from a shell or add a keybinding
# in tmux / alacritty
LIGHTTHEME="catppuccin-latte"
DARKTHEME="catppuccin-mocha"
VIMCONF="${XDG_CONFIG_HOME}/nvim/lua/config/set.lua"
ALACRITTYCONF="${XDG_CONFIG_HOME}/alacritty/alacritty.yml"
TMUXCONF="${XDG_CONFIG_HOME}/tmux/tmux.conf"
CURRENT_MODE=$(gsettings get org.gnome.desktop.interface color-scheme)
# Function to switch theme in n(v)im panes inside tmux
switch_vim_theme() {
theme_for_vim_panes="$1"
tmux list-panes -a -F '#{pane_id} #{pane_current_command}' |
grep vim |
grep vim | # this captures vim and nvim
cut -d ' ' -f 1 |
xargs -I PANE tmux send-keys -t PANE ESCAPE ":set background=light" ENTER
fi
xargs -I PANE tmux send-keys -t PANE ESCAPE \
":set background=${theme_for_vim_panes}" ENTER
}
if [ "$1" = "dark" ]; then
# Toggle logic based on current mode
if [ "$CURRENT_MODE" = "'prefer-dark'" ]; then
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
sed -i "s/${DARKTHEME}/${LIGHTTHEME}/" "$ALACRITTYCONF" "$TMUXCONF"
sed -i 's/dark/light/' "$VIMCONF"
switch_vim_theme "light"
else
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
sed -i 's/'"$LIGHTTHEME"'/'"$DARKTHEME"'/' "$ALACRITTYCONF"
sed -i 's/'"$LIGHTTHEME"'/'"$DARKTHEME"'/' "$TMUXCONF"
sed -i "s/${LIGHTTHEME}/${DARKTHEME}/" "$ALACRITTYCONF" "$TMUXCONF"
sed -i 's/light/dark/' "$VIMCONF"
tmux list-panes -a -F '#{pane_id} #{pane_current_command}' |
grep vim |
cut -d ' ' -f 1 |
xargs -I PANE tmux send-keys -t PANE ESCAPE ":set background=dark" ENTER
switch_vim_theme "dark"
fi
tmux source-file $TMUXCONF
tmux source-file "$TMUXCONF"
```

## Conclusion
Expand Down

0 comments on commit f98d077

Please sign in to comment.