-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratchpad-hypr
executable file
·186 lines (160 loc) · 4.16 KB
/
scratchpad-hypr
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#! /bin/sh
#-- scratchpad-hypr --#
# Scripts easen one's life.
# But we don't know much about what this one does.
# (DESCRIPTION NOT PROVIDED)
# Dependencies:
# - NOT_SET
# ~ ADIGEN
#!/usr/bin/env bash
# Nikhil Singh <[email protected]>
# Variables
_listing=false
_menu_cmd="rofi -dmenu -i -p scratchpad"
green="\033[0;32m"
red="\033[0;31m"
blue="\033[0;34m"
nocolor="\033[0m"
check() {
command -v "$1" 1>/dev/null
}
ok() {
echo -e "[$green $nocolor] $*"
}
err() {
echo -e "[$red $nocolor] $*"
}
optional() {
echo -e "[$blue $nocolor] $*"
}
notify() {
# shellcheck disable=SC2015
check notify-send && {
notify-send "$@"
} || {
echo "$@"
}
}
checkUtils() {
# shellcheck disable=SC2015
check sed && ok "sed" || err "sed"
# shellcheck disable=SC2015
check jq && ok "jq" || err "jq"
# shellcheck disable=SC2015
check notify-send && ok "notify-send (Optional)" || optional "notify-send (Optional)"
exit
}
basicChecks() {
check hyprctl || {
notify "Seriously mate!!" "Start Hyprland before this script"
exit 1
}
pgrep -x Hyprland &>/dev/null || {
notify "Make Sure Hyprland Session is running."
exit 1
}
}
help() {
cat <<EOF
This is a bash script for quick movement of windows to Scratchpad for Hyprland using hyprctl.
Invoking the command without flag will move the focused window to scratchpad.
flags:
-h: Displays This help menu
-c: Checks for all dependencies
-g: To bring back client from scratchpad to current workspace.
if only one client is present then no menu is popped and client will me moved.
if want menu before moving even if count of client is one then use -l.
<no further args will be evaluated>
-l: Forces to display list even if only one window is on scratchpad.
(Usefull if u don't remember which single window is at scratchpad)
-t: Takes you to the scratchpad <no further args will be evaluated>
-m: Sets the menu program. e.g 'scratchpad -m "rofi -dmenu -i"'
'scratchpad -m "bemenu"'
This program will be used to display list of clients present on scratchpad with there address.
default is (${_menu_cmd[@]})
Usage:
bind = SUPER, s, exec, /path/to/scratchpad/binary
bind = SUPERSHIFT, s, exec, /path/to/scratchpad/binary -g
bind = SUPERSHIFT, s, exec, /path/to/scratchpad/binary -l -g
(This will give client title and make sure that choice is asked to the user)
EOF
}
takes() {
hyprctl dispatch workspace "special:scratchpad"
exit 0
}
getBack() {
_ifs="$IFS"
IFS=$'\n'$'\n'
if pgrep "${_menu_cmd%% *}" >/dev/null; then exit; fi # Menu running already? → exit
_current_workspace="$(hyprctl monitors -j | jq '.[] | select(.focused==true)' | jq -j '.activeWorkspace.name')"
[ -z "$_current_workspace" ] && {
notify "Scratchpad" "Some Error Occured while getting current workspace."
exit 1
}
readarray -t _clients_on_spad < <(hyprctl clients -j |
jq '.[] | select(.workspace.name=="special:scratchpad")' |
jq -j '[.class, .title, .address] | @text' |
sed -z -e 's/]/]\n/g' \
-e 's/["]//g' \
-e 's/,/ /g' \
-e 's/\[//g' \
-e 's/]//g')
[ "${#_clients_on_spad[@]}" -eq 0 ] && {
notify "No Clients" "There was no client on scratchpad"
exit 0
}
[ "${#_clients_on_spad[@]}" -eq 1 ] && {
$_listing || {
_selected_client="${_clients_on_spad[0]}"
}
}
[ -z "$_selected_client" ] && _selected_client="$(echo "${_clients_on_spad[*]}" | eval "${_menu_cmd[*]}")"
_address="$(echo "$_selected_client" | awk '{print $NF}')"
hyprctl dispatch movetoworkspace "$_current_workspace,address:$_address"
hyprctl dispatch focuswindow "address:$_address"
[ "$(hyprctl activewindow -j | jq '.floating')" = true ] && {
hyprctl dispatch bringactivetotop none
}
IFS="$_ifs"
}
send() {
hyprctl dispatch movetoworkspace "special:scratchpad"
}
getArgs() {
while [ "$#" -gt 0 ]; do
case "$1" in
-h | --help)
help
exit 0
;;
-g)
getBack
exit 0
;;
-l)
_listing=true
;;
-t)
takes
;;
-m)
_menu_cmd=("$2")
shift
;;
-c)
checkUtils
;;
*)
help
echo ""
echo "Wrong argument given"
exit 1
;;
esac
shift
done
send
}
basicChecks
getArgs "$@"