color.sh (2343B)
1 #!/bin/sh 2 # 3 # color 4 5 COLOR="${XDG_CACHE_HOME:-${HOME}/.cache/}/dots/color" 6 7 # should work with compton too 8 COMPOSITOR='picom' 9 10 # we can make windows mono via shader 11 SHADER="${XDG_DATA_HOME:-${HOME}/.local/share/}/picom/gray.glsl" 12 13 start() { 14 # get mode stored in cache 15 # 0 means mono 16 # 1 means color 17 mode=$(cat "${COLOR}") 18 19 # start compositor 20 [ "${mode}" -eq 1 ] && ${COMPOSITOR} -b --backend glx \ 21 || ${COMPOSITOR} -b --backend glx --window-shader-fg="${SHADER}" 2>/dev/null 22 } 23 24 toggle() { 25 # check shader status and thus check mode 26 #shellcheck disable=SC2009 27 shader_id=$(ps -ef | grep 'window-shader-fg' | grep -iv '\<grep\>' | awk '{ printf "%s ", $2 }') 28 29 # shader enabled, meaning mono 30 # ENABLE COLOR 31 if [ "${shader_id}" ]; then 32 #shellcheck disable=SC2086 33 $(kill ${shader_id} && \ 34 sleep 1 && \ 35 ${COMPOSITOR} -b --backend glx) || return 1 36 mode=1 37 # shader disabled, meaning color 38 # DISABLE COLOR 39 else 40 #shellcheck disable=SC2086 41 $(kill ${comp_id} && \ 42 sleep 1 && \ 43 ${COMPOSITOR} -b --backend glx --window-shader-fg="${SHADER}" 2>/dev/null) || return 1 44 mode=0 45 fi 46 47 # print mode to cache so we remember mode at launch 48 printf '%s\n' "${mode}" > "${COLOR}" 49 } 50 51 main() { 52 if [ ${#} -eq 0 ]; then 53 # get compositor id 54 #shellcheck disable=SC2009 55 comp_id=$(ps -ef | grep "\<${COMPOSITOR}\>" | grep -iv '\<grep\>' | awk '{ printf "%s ", $2 }') 56 57 # compositor not running, so return 58 [ -z "${comp_id}" ] && printf '%s\n' "${COMPOSITOR} is not running" && return 1 59 60 # toggle between mono/color modes 61 if toggle; then 62 # get mode 63 [ "${mode}" -eq 1 ] && msg='Color enabled' || msg='Color disabled' 64 else printf '%s\n' 'Toggle failed' && return 1 65 fi 66 67 # print notification 68 env HERBE_ID=/0 herbe "${msg}" & 69 fi 70 71 # flags for profile 72 while getopts 's' opt; do 73 case "${opt}" in 74 # automatically pick mode based on cache 75 s) start ;; 76 *) return ;; 77 esac 78 done 79 } 80 81 main "${@}"