polybar/polybar-scripts

hlwm workspaces custom script

RaZ0rr-Two opened this issue · 2 comments

Could you add an example for info-hlwm-workspaces script with colors?

I have added some formatting to my own. So, if it's okay maybe add this as example or replace the current orginial one with this.

Thank you.

#!/usr/bin/env bash

# Multi monitor support. Needs MONITOR environment variable to be set for each instance of polybar
# If MONITOR environment variable is not set this will default to monitor 0
# Check https://github.com/polybar/polybar/issues/763
MON_IDX="0"
mapfile -t MONITOR_LIST < <(polybar --list-monitors | cut -d":" -f1)
for (( i=0; i<$((${#MONITOR_LIST[@]})); i++ )); do
  [[ ${MONITOR_LIST[${i}]} == "$MONITOR" ]] && MON_IDX="$i"
done;

herbstclient --idle "tag_*" 2>/dev/null | {

    while true; do
        # Read tags into $tags as array
        IFS=$'\t' read -ra tags <<< "$(herbstclient tag_status "${MON_IDX}")"
        {
            for i in "${tags[@]}" ; do
                # Read the prefix from each tag and render them according to that prefix
                case ${i:0:1} in
                    '.')
                        # the tag is empty
                        # TODO Add your formatting tags
		        # echo "%{F#345F0C} 0%{F-}"
		        # echo "%{A1:herbstclient focus_monitor ${MON_IDX}; herbstclient use ${i:1}:}%{B#345F0C}  ${i:1}  %{B-}%{A}"
                        ;;
                    ':')
                        # the tag is not empty
                        # TODO Add your formatting tags
		        echo "%{A1:herbstclient focus_monitor ${MON_IDX}; herbstclient use ${i:1}:}%{F#000000}%{B#608B4E} [${i:1}] %{F-}%{B-}%{A}"
                        ;;
                    '+')
                        # the tag is viewed on the specified MONITOR, but this monitor is not focused.
                        # TODO Add your formatting tags
                        ;;
                    '#')
                        # the tag is viewed on the specified MONITOR and it is focused.
                        # TODO Add your formatting tags
		        echo "%{A1:herbstclient focus_monitor ${MON_IDX}; herbstclient use ${i:1}:}%{F#000000}%{B#569CD6}  ${i:1}  %{F-}%{B-}%{A}"
                        ;;
                    '-')
                        # the tag is viewed on a different MONITOR, but this monitor is not focused.
                        # TODO Add your formatting tags
                        ;;
                    '%')
                        # the tag is viewed on a different MONITOR and it is focused.
                        # TODO Add your formatting tags
                        ;;
                    '!')
                        # the tag contains an urgent window
                        # TODO Add your formatting tags
		        echo "%{A1:herbstclient focus_monitor ${MON_IDX}; herbstclient use ${i:1}:}%{F#000000}%{B#D16969} [${i:1}] %{F-}%{B-}%{A}"
                        ;;
                esac

                # focus the monitor of the current bar before switching tags
                # echo "%{A1:herbstclient focus_monitor ${MON_IDX}; herbstclient use ${i:1}:}  ${i:1}  %{A -u -o F- B-}"
            done

            # reset foreground and background color to default
            echo "%{F-}%{B-}"
        } | tr -d "\n"

    echo

    # wait for next event from herbstclient --idle
    read -r || break
done
} 2>/dev/null
x70b1 commented

@RaZ0rr-Two Thanks for your code!
If you want, open a pull request for this. Than we can work on it and merge it in our repository.

Done