Skip to content

Instantly share code, notes, and snippets.

@flee2free
Last active June 2, 2021 23:43
Show Gist options
  • Select an option

  • Save flee2free/fde3beb9ae9231f73ec7db44741ab5f6 to your computer and use it in GitHub Desktop.

Select an option

Save flee2free/fde3beb9ae9231f73ec7db44741ab5f6 to your computer and use it in GitHub Desktop.

Revisions

  1. flee2free renamed this gist Jun 2, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. flee2free created this gist Jun 2, 2021.
    66 changes: 66 additions & 0 deletions Project - Shell - Toggle Theme.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    alacritty_theme() {
    theme=$1
    config_path=~/.config/alacritty/color.yml
    if ! test -f "$config_path"; then
    echo "$config_path does not exists"
    return
    fi

    sed -i "" -e "s/^colors: \*.*/colors: *$theme/g" $config_path

    echo "switched to $theme"
    }

    vi_theme() {
    for wix in `tmux list-windows -t main -F 'main:#{window_index}'`; do
    for tix in `tmux list-panes -t $wix -F 'main:#{window_index}.#{pane_index}.#{pane_tty}'`; do
    pat='(main:[0-9].[0-9]).(.*)'
    [[ $tix =~ $pat ]]
    _pane_tty="${BASH_REMATCH[2]}"
    _pane_id="${BASH_REMATCH[1]}"

    _nvim=$(ps -o state= -o comm= -t $_pane_tty | grep -c 'nvim')

    if [ $_nvim == 1 ]; then
    tmux if-shell -t "$_pane_id" "true" "send-keys -t $_pane_id Escape"
    tmux if-shell -t "$_pane_id" "true" "send-keys -t $_pane_id ':call ChangeBackground()' ENTER"
    fi

    done
    done
    }

    _light() {
    alacritty_theme gruvbox_light
    sed -i "" -e "s/^\([[:space:]]*\)\(export FZF_DEFAULT_OPTS=\)\(.*\)/\1\2\$fzf_theme_light/g" ~/.zshrc
    sed -i "" -e "s/^\(export BAT_THEME=\).*/\1\"gruvbox-light\"/g" ~/.zshrc
    sed -i "" -e "s/^\(set background=\).*/\1light/g" ~/.config/nvim/init.vim
    sed -i "" -e "s/\(.*active_window_border_color.*\)\".*\"/\1\"0xE03e5ea3\"/g" ~/.config/yabai/yabairc
    }

    _dark() {
    alacritty_theme gruvbox_dark
    sed -i "" -e "s/^\([[:space:]]*\)\(export FZF_DEFAULT_OPTS=\)\(.*\)/\1\2\$fzf_theme_dark/g" ~/.zshrc
    sed -i "" -e "s/^\(export BAT_THEME=\).*/\1\"gruvbox-dark\"/g" ~/.zshrc
    sed -i "" -e "s/^\(set background=\).*/\1dark/g" ~/.config/nvim/init.vim
    sed -i "" -e "s/\(.*active_window_border_color.*\)\".*\"/\1\"0xE04caf50\"/g" ~/.config/yabai/yabairc
    }


    case $1 in

    light)
    echo "Light"
    _light
    ;;

    dark)
    echo "Dark"
    _dark
    ;;

    *)
    echo "Unknown Option"
    esac

    vi_theme