-
Notifications
You must be signed in to change notification settings - Fork 5
/
mxfb-trashcheck
executable file
·187 lines (147 loc) · 3.88 KB
/
mxfb-trashcheck
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
187
#!/bin/bash
##This script counts the files in the trash and asks for confirmation
##to remove them permanently. It uses YAD dialog-box.
##Created by Kobalan for MX-Fluxbox with additions by MX Devs and users
##Released August 2021 under GPL3
# adjusted by fehlix, September 2021
# version : 210906-02
: YAD=${YAD:=/usr/bin/yad}
export TEXTDOMAIN=mxfb-accessories
export TEXTDOMAINDIR="/usr/share/locale"
. gettext.sh
export CLASS=mxfb-trashcheck
# translation re-use ;)
GETTEXT=gettext
TITLE=$($GETTEXT -d gtk30 "Trash" )
CLOSE=$($GETTEXT -d gtk30 "_Close" ); #CLOSE=${CLOSE//_}
CANCEL=$($GETTEXT -d gtk30 "_Cancel"); #CANCEL=${CANCEL//_};
YES=$($GETTEXT -d gtk30 "_Yes" ) ; #YES=${YES//_}
NO=$($GETTEXT -d gtk30 "_No" ) ; #NO=${NO//_}
OK=$($GETTEXT -d gtk30 "_OK" ) ; #OK=${OK//_}
SHOW=$($GETTEXT -d gtk30-properties "Show 'Trash'")
SHOW=$(echo "$SHOW" | sed 's/[a-zA-Z]/_&/')
MSG_NONE=$(gettext "There are no files in the trash.")
MSG_ASK=$(gettext "Do you want to empty the trash?")
main() {
local xpid
# run me only once
if xpid=$(xdotool search --class $CLASS getwindowpid); then
kill -SIGUSR2 $xpid && exit
fi
trap hangup_trash_monitor EXIT TERM HUP
fix_mime
run_trash_monitor &
MSG_NONE="
<b><big>$MSG_NONE</big></b>
"
ICON_TRASH_NONE=trashcan_empty
ICON_TRASH_SOME=trashcan_full
BUTTON_NO="$NO"'!dialog-no:0'
BUTTON_OK="$OK"'!dialog-ok:0'
BUTTON_YES="$YES"'!dialog-yes:2'
BUTTON_SHOW="$SHOW"'!'"$ICON_TRASH_SOME"':3'
YAD_NONE=(
$YAD
--title="$TITLE"
--borders=12
--height=20
--text-align=right
--fixed
--class=$CLASS
--window-icon=$ICON_TRASH_NONE
--image=user-trash
--timeout=300
--button="$BUTTON_OK"
)
YAD_SOME=(
$YAD
--title="$TITLE"
--borders=12
--text-align=right
--fixed
--height 20
--class=$CLASS
--image=$ICON_TRASH_SOME
--window-icon=$ICON_TRASH_SOME
--button="$BUTTON_YES"
--button="$BUTTON_NO"
--button="$BUTTON_SHOW"
)
while true; do
COUNT=$(gio list trash:// | wc -l)
# TRANSLATORS:
# Do not translate the count placeholder '${COUNT}'.
# Singular form: 'There is 1 file in the trash.'
# Plural form: 'There are 2 files in the trash.'
MSG_SOME=$(eval_ngettext \
'There is 1 file in the trash.' \
'There are ${COUNT} files in the trash.' \
${COUNT}
)
MSG_SOME="
$MSG_SOME
$MSG_ASK "
MSG_SOME="
<b><big>$MSG_SOME</big></b>
"
case ${COUNT:=0} in
0) "${YAD_NONE[@]}" --text="$MSG_NONE" ;;
*) "${YAD_SOME[@]}" --text="$MSG_SOME" ;;
esac
ret=$?
case $ret in
0|252) exit 0
;;
2) gio trash --empty
;;
3) ( xdg-open trash:// 2>/dev/null 1>&2 ) 2>/dev/null 1>&2 &
;;
esac
done
}
trash_monitor() {
local monitor=
while true ; do
local TRASH
read TRASH
break
done < <( /usr/bin/gio monitor trash:// )
hangup_trash_monitor
return 0
}
reload_mxfb_trash() {
local pid=$(xdotool search --class $CLASS getwindowpid)
if [[ -n $pid ]]; then
kill -SIGUSR2 $pid
return 0
else
return 1
fi
}
hangup_trash_monitor() {
pkill -SIGHUP -f '/usr/bin/gio monitor trash://'
}
run_trash_monitor() {
while trash_monitor 2>/dev/null; do
reload_mxfb_trash || break
sleep 0.5
done
hangup_trash_monitor
}
fix_mime() {
local mime
for mime in inode/directory x-scheme-handler/trash; do
if grep -sq -iE '^Default.*(thunar|pcmanfm)' < <(LC_ALL=C.UTF-8 gio mime $mime); then
continue
fi
if which thunar >/dev/null; then
gio mime $mime thunar.desktop
elif which pcmanfm-qt >/dev/null; then
gio mime $mime pcmanfm-qt.desktop
elif which pcmanfm >/dev/null; then
gio mime $mime pcmanfm.desktop
fi
done
}
main
exit 0