Created
October 7, 2019 03:48
-
-
Save NatKarmios/e711d33894b27c44abbcc2a92a85f17d to your computer and use it in GitHub Desktop.
Minimize/restore scripts using xdotool (and a dash of dmenu)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# minimizes the currently focused window | |
current_window=$(xdotool getactivewindow) && \ | |
echo $current_window >> ~/.minim && \ | |
xdotool windowunmap $current_window |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# uses dmenu to select a minimised window, and restore it | |
declare -A names | |
options="" | |
touch ~/.minim | |
while read window_id; do | |
window_name=$(xdotool getwindowname $window_id) | |
if [ -n "$window_name" ]; then | |
if [ -z "${names[ $window_name ]}" ]; then | |
displayed_name=" $window_name " | |
else | |
i=1 | |
while [ -n "${names[ $window_name ($i) ]}" ]; do | |
i=$(( $i+1 )) | |
done | |
displayed_name=" $window_name ($i) " | |
fi | |
names[$displayed_name]=$window_id | |
options=$options$displayed_name'\n' | |
fi | |
done < ~/.minim | |
if [ -n "$options" ]; then | |
choice=$(echo -e "$options Cancel " | $HOME/.config/dmenu/dmenu.sh -i -p "Restore window: ") | |
if [ "$choice" == ' Cancel ' ]; then | |
echo "Cancelled" | |
else | |
echo "Restoring '$choice'" | |
xdotool windowmap "${names[$choice]}" | |
names[$choice]= | |
rm ~/.minim | |
for window_id in "${names[@]}"; do | |
if [ -n "$window_id" ]; then | |
echo $window_id >> ~/.minim | |
fi | |
done | |
fi | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[module/minim] | |
type = custom/script | |
exec = echo $(cat $HOME/.minim 2> /dev/null | wc -l || echo 0) | |
exec-if = cat $HOME/.minim | |
format = <label> | |
label = %output% | |
click-left = $HOME/.bin/minim-r | |
format-foreground = ${colors.foreground} | |
format-background = ${colors.background-lighter} | |
format-padding = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment