dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/bin/whid

51 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
file="/tmp/.minimized"
touch $file
# By https://github.com/tatou-tatou
lines=$(wc -l < $file)
case $1 in
hide)
if [[ $lines -ge 10 ]]; then ## Fight against bad practices
notify-send "10 windows are already hidden" "You should consider closing some before hiding even more." -i warning
else
focusedDesktop=$(xdotool get_desktop)
focusedID=$(xdo id)
focusedName=$(xdotool getwindowname "$focusedID")
notiflines=$((lines + 1))
echo "$focusedID $focusedDesktop $focusedName" >> "$file" && xdo hide "$focusedID" && notify-send "${notiflines} hidden windows." "$focusedName" -i warning
fi
;;
dmenu)
miniList=$(cat $file)
# Dmenu cannot draw more than 30 lines
if [[ $lines -gt 30 ]]
then linesDisplayed=30
else linesDisplayed=$lines
fi
# If the list is empty
if [ -z "$miniList" ]
then
miniList=" Nothing is hidden!"
linesDisplayed=1
fi
dmenu_cmd="rofi -lines $linesDisplayed -dmenu -p Hidden:"
# Launch dmenu
lineNumber=$(echo "$miniList" | cut -d " " -f 3- | nl -w 3 -n rn | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' | $dmenu_cmd | cut -d '-' -f -1)
# If you exited dmenu without selecting anything or if the list was empty
[ -z "$lineNumber" ] || [ "$miniList" = " Nothing is hidden!" ] && exit
# Show the selected hidden window
selectedID=$(sed -n "$lineNumber p" $file | cut -d ' ' -f 1)
selectedDesktop=$(sed -n "$lineNumber p" $file | cut -d ' ' -f 2)
xdotool set_desktop "$selectedDesktop"
xdo show "$selectedID" && sed -i "${lineNumber}d" $file
;;
esac