#!/usr/bin/env bash STATUS_FILE=/dev/shm/polybar_task_manager REFRESH=2 create_module_tasklabel() { cat < -1) print $3,$1}' \ | awk -F'.' '{ print $NF }' \ | tail -"$max_tasks" | sort > $STATUS_FILE.current diff -q $STATUS_FILE $STATUS_FILE.current > /dev/null 2>&1 if [ $? -ne 1 ]; then rm -rf $STATUS_FILE.current return 0 fi mv $STATUS_FILE.current $STATUS_FILE num_windows=$(wc -l $STATUS_FILE | cut -f 1 -d " ") for counter in $(seq 1 "$max_tasks"); do if [ "$counter" -le "$num_windows" ]; then polybar-msg hook taskbar"$counter" 2 > /dev/null else polybar-msg hook taskbar"$counter" 1 > /dev/null fi sleep 0.1 done } print_task_name() { name=$(sed "${1}q;d" $STATUS_FILE | cut -f 1 -d " " | tr '[:upper:]' '[:lower:]') icon=$(get_icon_by_name "$name") if [ -n "$icon" ]; then name="$name " fi printf "%s%s" "${name^}" "$icon" } get_active_window() { echo 0x0"$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2 | cut -f 2 -d 'x')" } get_task_id() { sed "${1}q;d" $STATUS_FILE | cut -f 2 -d " " } daemon() { create_module_tasklabel > ~/.config/polybar/task_manager.ini create_module_sections "$1" >> ~/.config/polybar/task_manager.ini while true; do show_tasks sleep $REFRESH done } case "$1" in --daemon) > /dev/shm/polybar_task_manager daemon "$2" ;; --set-task) print_task_name "$2" ;; --show-window) id=$(get_task_id "$2") if [ "$id" = "$(get_active_window)" ]; then xdotool getactivewindow windowminimize else wmctrl -ia "$id" fi print_task_name "$2" ;; --close-window) id=$(get_task_id "$2") wmctrl -ic "$id" ;; esac exit 0