-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlapav.sh
executable file
·101 lines (87 loc) · 2.83 KB
/
lapav.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env sh
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 11)
NC=$(tput sgr 0)
delim=":"
stack=/tmp/win_hide
die(){
[ ! -s $stack ] && notify-send "Empty File" "No window is hidden" && exit 1
}
failed(){
echo "$1"
exit 1
}
cmd=$([ -f /usr/bin/rofi ] && echo "rofi -dmenu -matching fuzzy" || echo "dmenu -i -l 10")
push() {
[ -z "$1" ] && exit 1
wid="$1"
# Add window id only if it doesn't exist
grep -qxF "$1" "$stack" || printf "%s%s%s\n" "$wid" "$delim" "$(xdotool getwindowname $wid)" >> "$stack"
xdotool windowminimize --sync "$wid"
}
pop() {
tmp=$(mktemp)
wid=$1
xdotool windowactivate "$wid" || failed "$RED Failed $NC"
head -n-1 "$stack" > "$tmp"
mv "$tmp" "$stack"
}
usage() {
## For Colored output looking into this
## Black 0;30 Dark Gray 1;30
## Red 0;31 Light Red 1;31
## Green 0;32 Light Green 1;32
## Brown/Orange 0;33 Yellow 1;33
## Blue 0;34 Light Blue 1;34
## Purple 0;35 Light Purple 1;35
## Cyan 0;36 Light Cyan 1;36
## Light Gray 0;37 White 1;37
cat << EOF
Usage:
$YELLOW $0 $GREEN [hide|show] [select]
$YELLOW Options:$NC
$GREEN hide:$NC Hide option will hide the window, if no arguement is provided
then current focused window will be hidden
$GREEN show:$NC This option will show the window. If no arguement is provided
then the last hidden window will be show
$YELLOW Args:$NC
$GREEN select:$NC This option will launch rofi or dmenu(which is installed)
and show the list of windows to perform operation
(like hide or show)
EOF
}
case $1 in
hide)
if [ -z "$2" ]; then
# no arguement provide to hide focused window
push "$(xdotool getwindowfocus)"
else
if [ "$2" = "select" ]; then
win_names=$(xdo id -d | xargs -r -I{} sh -c 'printf "%s:%s\n" {} "$(xdotool getwindowname {})"')
wid=$(echo "$win_names" | eval "$cmd" | cut -d "$delim" -f1)
push "$wid"
else
printf "%s Please provide right arguements.\n%s Did you mean%s select \n%s" "$RED" "$NC" "$GREEN" "$NC"
exit 1
fi
fi
;;
show)
die
if [ -z "$2" ]; then
# No arguement is provide to unhide last window
wid=$(tail < $stack -n1 | cut -d "$delim" -f1)
pop "$wid"
else
if [ "$2" = "select" ]; then
wid=$( eval "$cmd" < "$stack" | cut -d "$delim" -f1)
pop "$wid"
else
printf "%s Please provide right arguements.\n%s Did you mean%s select \n%s" "$RED" "$NC" "$GREEN" "$NC"
exit 1
fi
fi
;;
*) usage ;;
esac