summaryrefslogtreecommitdiff
path: root/zsh/.zsh/functions
blob: e77dee75e6cb089f199610b90502ca07fa4f0b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/zsh

function colo {

    # Xresource file
    XRESOURCE=$1

    if [[ "${XRESOURCE}" == *"-dark" ]]; then
        export COLORSCHEME=${XRESOURCE%-dark}
        export BACKGROUND="dark"
    elif [[ "${XRESOURCE}" == *"-light" ]]; then
        export COLORSCHEME=${XRESOURCE%-light}
        export BACKGROUND="light"
    else 
        export COLORSCHEME=${XRESOURCE}
        export BACKGROUND=""
    fi

    # Change colors for current session
    $HOME/bin/recolor < ~/.Xresources/${XRESOURCE}

    # Load Xresources file for future sessions
    xrdb -I$HOME ~/.Xresources/${XRESOURCE}

    # Change default environment variable for future sessions
    sed -i --follow-symlinks "s/^export COLORSCHEME=.*$/export COLORSCHEME=${COLORSCHEME}/g" ~/.zsh/tmp
    sed -i --follow-symlinks "s/^export COLORSCHEME=.*$/export BACKGROUND=${BACKGROUND}/g" ~/.zsh/tmp
}

# Completion for colorschemes (-M -> Case insensitive)
compctl -k "($(ls ${HOME}/.Xresources))" -M 'm:{a-z}={A-Z}' colo