mardi 3 novembre 2015

Writing an idempotent shell script using a condition on an environment variable

I am trying to use xmodmap to swap caps and escape. I put the xmodmap ~/.Xmodmap command in my .zshrc. But whenever I start a new shell, the xmod settings are swapped again. So I tried to wrap the xmodmap command in a condition that checks for a global variable, but I just can't get it to work.

if [ ! -z "${CAPS_MAPPED+xxx}" ]; then     # check if CAPS_LOCKED is empty
    echo 'mapping'
    xmodmap ~/dotfiles/.xmodmap            # call xmodmap
    export readonly CAPS_MAPPED=1          # assign global var
fi

I tried different variations but just don't get what to do as I am fairly inexperienced with shell scripts.

Aucun commentaire:

Enregistrer un commentaire