-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmxfb-look
More file actions
executable file
·1002 lines (735 loc) · 28.2 KB
/
mxfb-look
File metadata and controls
executable file
·1002 lines (735 loc) · 28.2 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#MXFB-Look is a tool to save and restore desktop settings in MX-Linux Fluxbox by Melber
VERSION=2511-1
#License: GPL-3.0+
##Changelog##
#reworked for MXFB25, replaced .look with .look2 files
# add locale
export TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN="mxfb-accessories"
source gettext.sh
#define some variables
#export TITLE="$(gettext 'MXFB-Look')"
export TITLE='MXFB-Look'
export CLASS="mxfb-look"
export MXLKPATH="$HOME/.config/MX-Linux/mxfb-look"
export ICONPATH="/usr/share/pixmaps/mxfb-look.svg"
# buttons
export BTN_CLOSE=$(gettext "Close") ; BTN_CLOSE+='!window-close'
export BTN_CANCEL=$(gettext "Cancel") ; BTN_CANCEL+='!window-close'
export BTN_SAVE=$(gettext "Save Current Look") ; BTN_SAVE+='!document-save'
export BTN_OK=$(gettext "OK") ; BTN_OK+='!window-ok'
export BTN_RESTORE=$(gettext "Restore Look") ; BTN_RESTORE+='!reload'
export BTN_HELP=$(gettext "Help") ; BTN_HELP+='!help-about'
export BTN_ABOUT=$(gettext "About MXFB-Look") ; BTN_ABOUT+='!help-about'
#delete stylelist and tempclr after use
trap "rm -f "/tmp/lookselection.txt" " EXIT
#create path
if [ ! -d $MXLKPATH ]; then
mkdir $MXLKPATH
fi
#create looks folder
if [ ! -d $MXLKPATH/looks ]; then
mkdir -p $MXLKPATH/looks
fi
#create backup folder
if [ ! -d $HOME/.restore/mxfb-look ]; then
mkdir -p $HOME/.restore/mxfb-look
fi
#remove old Default looks
if [ -f $MXLKPATH/looks/MXFB-default.look ]; then
rm $MXLKPATH/looks/MXFB-default.look $MXLKPATH/looks/MXFB-default.png
fi
if [ -f $MXLKPATH/looks/MX23-default.look ]; then
mv $MXLKPATH/looks/MX23-default.look $HOME/.restore/mxfb-look/MX23-default.look
fi
if [ -f $MXLKPATH/looks/torre-di-libretti.look ]; then
mv $MXLKPATH/looks/torre-di-libretti.look $HOME/.restore/mxfb-look/torre-di-libretti.look
fi
#make checkfile
if [ ! -f $MXLKPATH/checkfile.conf ]; then
echo 'look_version=xxx' > $MXLKPATH/checkfile.conf
fi
#make MX25 Default look2 file
source $MXLKPATH/checkfile.conf
if [ "$look_version" != "$VERSION" ]; then
printf 'look_fluxstyle=/usr/share/mxflux/styles/MX-Matcha
look_theme=mx-matcha
look_icon=Papirus-mxblue
look_font="Noto Sans-11"
look_cursor=DMZ-Black
look_tintnum=1
look_tint1=$HOME/.config/tint2/tint2rc
look_tint2=None
look_rofi=$HOME/.config/rofi/themes/MX-ease-dark.rasi
look_checkfeh=
look_wallpaper=/usr/share/backgrounds/Maturity.png
look_conky1=/usr/share/mx-conky-data/themes/MX-Infinity
look_conky2=/usr/share/mx-conky-data/themes/MX-Infinity/MX-Infinity-conkyrc
look_conkystate=false' > $MXLKPATH/looks/MX25-default.look2
echo "look_version=$VERSION" > $MXLKPATH/checkfile.conf
fi
#copy image for MX25 Default look
if [ ! -f $MXLKPATH/looks/MX25-default.png ]; then
cp /usr/share/pixmaps/MX25-default.png $MXLKPATH/looks/
fi
#check firsttext
if [ ! -f $MXLKPATH/looks/firsttext.txt ]; then
echo '
A look is comprised of the following elements
- Fluxbox Style
- Wallpaper
- Gtk-Theme
- Icon Theme
- Font
- Cursor
- Tint2 Panel (max. 2)
- Rofi Theme
- Conky (max. 1)' > $MXLKPATH/looks/firsttext.txt
fi
#################################
#convert .look to .look2
if compgen -G "$MXLKPATH/looks/*.look" > /dev/null; then
look_convertlist=$(ls -f $HOME/.config/MX-Linux/mxfb-look/looks/*.look)
look_convertarray=($look_convertlist)
for i in "${look_convertarray[@]}"; do
look_convertname=$(basename $i | sed -e 's/.look/.look2/' )
look_backupname=$(basename $i)
mapfile look_convertitems < $i
look_fluxstyle="${look_convertitems[6]}"
look_fluxstyle="$(echo $look_fluxstyle | sed -e "s/session\.styleFile\://" | sed -e "s/ //g" )"
look_theme="${look_convertitems[0]}"
look_theme="$(echo $look_theme | sed -e "s/gtk-theme-name\=//")"
look_icon="${look_convertitems[1]}"
look_icon="$(echo $look_icon | sed -e "s/gtk-icon-theme-name\=//")"
look_font="${look_convertitems[2]}"
look_font="$(echo $look_font | sed -e "s/gtk-font-name\=//" | sed -e 's/ /-/g')"
look_cursor='DMZ-Black'
look_tintnum="${look_convertitems[7]}"
look_tint1="${look_convertitems[8]}"
look_tint2="${look_convertitems[9]}"
look_rofi="${look_convertitems[10]}"
look_rofi="$(echo $look_rofi | sed -e "s/\@theme\ //" | sed -e "s/\"//g")"
look_checkfeh=
look_wallpaper="${look_convertitems[11]}"
look_wallpaper="$(echo $look_wallpaper | sed -e "s/file\=//g")"
look_conky1="${look_convertitems[12]}"
look_conky1="$(echo $look_conky1 | sed -e "s/cd\ //" | sed -e "s/\"//g")"
look_conky2="${look_convertitems[13]}"
look_conky2="$(echo $look_conky2 | sed -e "s/conky \-c\ \"//" | sed -e "s/\"\ \&//")"
look_conkystate="${look_convertitems[14]}"
look_conkystate="$(echo $look_conkystate | sed -e 's/Hidden=//')"
echo "
look_fluxstyle="$look_fluxstyle"
look_theme="$look_theme"
look_icon="$look_icon"
look_font="$look_font"
look_cursor="$look_cursor"
look_tintnum="$look_tintnum"
look_tint1="$look_tint1"
look_tint2="$look_tint2"
look_rofi="$look_rofi"
look_checkfeh=
look_wallpaper="$look_wallpaper"
look_conky1="$look_conky1"
look_conky2="$look_conky2"
look_conkystate="$look_conkystate"
" > $MXLKPATH/looks/"$look_convertname"
mv $i $HOME/.restore/mxfb-look/"$look_backupname"
path_check=($look_fluxstyle $look_wallpaper $look_rofi)
for i in $path_check; do
if [[ $i =~ "/home/" ]]; then
oldusername="$(echo "$i" | cut -d/ -f3)"
sed -i "s|/home/$oldusername/|\$HOME/|g" $MXLKPATH/looks/"$look_convertname"
break
fi
done
done
fi
#################################
# function save look
save_look() {
#define some variables
source gettext.sh
#read current look components
#fluxbox style
look_fluxstyle="$( grep "styleFile" $HOME/.fluxbox/init | sed -e "s/session\.styleFile\://" | sed -e "s/ //g" )"
#theme and icons
look_theme="$(grep "gtk-theme-name" $HOME/.config/gtk-3.0/settings.ini | sed -e "s/gtk-theme-name\=//")"
look_icon="$(grep "gtk-icon-theme-name" $HOME/.config/gtk-3.0/settings.ini | sed -e "s/gtk-icon-theme-name\=//")"
look_font="$(grep "gtk-font-name" $HOME/.config/gtk-3.0/settings.ini | sed -e "s/gtk-font-name\=//" | sed -e 's/ /-/g')"
#cursor
look_cursor=$(grep "gtk-cursor-theme-name" $HOME/.config/gtk-3.0/settings.ini | sed -e 's/gtk-cursor-theme-name=//' )
#tint2
look_tintnum="$(wc -l < $HOME/.config/tint2/tint2-sessionfile)"
look_tint1="$(grep "tint2" $HOME/.config/tint2/tint2-sessionfile | sed -n 1p)"
look_tint1=$(echo "${look_tint1}" | sed -e 's/$HOME/\$HOME/g')
look_tint2="$(grep "tint2" $HOME/.config/tint2/tint2-sessionfile | sed -n 2p)"
look_tint2=$(echo "${look_tint2}" | sed -e 's/$HOME/\$HOME/g')
if [ $look_tintnum = 0 ]; then
look_tint1="None"
look_tint2="None"
fi
if [ $look_tintnum = 1 ]; then
look_tint2="None"
fi
#rofi
look_rofi="$(grep '@theme' $HOME/.config/rofi/config.rasi | sed -e "s/\@theme\ //" | sed -e 's/"//g')"
if [ "$look_rofi" = "MX-ease-dark.rasi" ]; then
look_rofi="$HOME/.config/rofi/themes/MX-ease-dark.rasi"
fi
#wallpaper
look_checkfeh=$(grep '#nitrogen' $HOME/.fluxbox/startup)
if [ -z "$look_checkfeh" ]; then
look_wallpaper="$(grep "file=" $HOME/.config/nitrogen/bg-saved.cfg | sed -n 2p | sed -e "s/file\=//g")"
if [ -z "$look_wallpaper" ]; then
look_wallpaper="$(grep "file=" $HOME/.config/nitrogen/bg-saved.cfg | sed -e "s/file\=//g")"
fi
else
look_wallpaper=$(grep "feh" $HOME/.fehbg)
look_wallpaper=$(echo "${look_wallpaper}" | sed -e "s/'/|/g")
look_wallpaper=$(echo "$look_wallpaper" | cut -d '|' -f 2)
fi
if [ -z "$look_wallpaper" ]; then
look_wallpaper='/usr/share/backgrounds/Maturity.png'
fi
#conky
look_conky1="$(grep "conky" $HOME/.conky/conky-startup.sh | sed -n 2p | sed -e 's/cd //' | sed -e 's/"//g')"
look_conky2="$(grep "conky" $HOME/.conky/conky-startup.sh | sed -n 3p | sed -e 's/conky -c "//' | sed -e 's/" &//')"
look_conkystate="$(grep "Hidden" "$HOME/.config/autostart/conky.desktop" | sed -e 's/Hidden=//')"
if [ -z "$look_conky1" ]; then
look_conky1='/usr/share/mx-conky-data/themes/MX-Infinity'
fi
if [ -z "$look_conky2" ]; then
look_conky2='/usr/share/mx-conky-data/themes/MX-Infinity/MX-Infinity-conkyrc'
fi
#MAINSAVE
MAINSAVE=(yad --title="$TITLE" --class="$CLASS" --icon="$ICONPATH" \
--borders=20 --center --width=600 --height=200 --fixed \
--form --columns=1 --align=left --separator="" \
--button="yad-quit":1 --button="$(gettext 'Save Look')":0 \
--field="$(eval_gettext 'Save Look as')" $"New-Look-Name"\
)
NEWNAME=$("${MAINSAVE[@]}")
(($?==0)) && echo "$NEWNAME" > /tmp/look_tempname.txt
GETOUT=$(echo "$?")
if [ "$GETOUT" != 0 ]; then
exit
elif [ "$GETOUT" = 0 ]; then
read NEWNAME < /tmp/look_tempname.txt
unset IFS
fi
NEWNAME=$(echo "$NEWNAME" | sed -e 's/ /-/g')
#check new Look name is not empty and forbid MXFB-default overwrite
while [ -z "$NEWNAME" -o "$NEWNAME" = 'MXFB-default' ]; do
NEWNAME=$(yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--width=400 --height=200 --fixed \
--text="$(eval_gettext 'Look name $NEWNAME is protected. Choose another name.')" \
--form --center --borders=20 --separator="" \
--field="$(gettext '<b>Name for new style</b>')":LBL " " \
--field=$" " "$NEWNAME-new" )
GETOUT=$(echo "$?")
if [ "$GETOUT" != 0 ]; then
exit
fi
done
#check if new Look name exists, if yes ask if overwrite or different name
cd $MXLKPATH/looks
while [ -f $NEWNAME.look2 ]; do
message="$(eval_gettext 'A Look with this name already exists.\n\nDo you want to overwrite $NEWNAME or save as a new name?\n')"
yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--text-align=center --center --borders=20 \
--width=400 --fixed --text="$message" \
--button="$(eval_gettext 'Overwrite $NEWNAME')":2 --button="$(gettext 'Save as different name')":3
case $? in
2) rm -r $MXLKPATH/looks/$NEWNAME.look2 ;;
3) NEWNAME=$(yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--width=400 --height=200 --fixed --form --center --borders=20 --separator="" \
--field="$(gettext '<b>Name for New Look</b>')":LBL " " \
--field=$" " "$NEWNAME-new" ) ;;
252) exit 0 ;;
esac
done
#make look file
echo "
look_fluxstyle="$look_fluxstyle"
look_theme="$look_theme"
look_icon="$look_icon"
look_font="$look_font"
look_cursor="$look_cursor"
look_tintnum="$look_tintnum"
look_tint1="$look_tint1"
look_tint2="$look_tint2"
look_rofi="$look_rofi"
look_checkfeh=
look_wallpaper="$look_wallpaper"
look_conky1="$look_conky1"
look_conky2="$look_conky2"
look_conkystate="$look_conkystate"
" > $MXLKPATH/looks/"$NEWNAME".look2
sed -i 's/= /=/g' $MXLKPATH/looks/"$NEWNAME".look2
sed -i "s|$HOME|\$HOME|g" $MXLKPATH/looks/"$NEWNAME".look2
#make preview image
WINLIST=$(wmctrl -l | grep -v tint2 | grep -v conky | awk '{ print$1 }')
for i in $WINLIST;
do
WINNUM=$i
wmctrl -i -r "$i" -b add,hidden
done
sleep 0.5
scrot $MXLKPATH/looks/"$NEWNAME".png -b -o -t 20
rm $MXLKPATH/looks/"$NEWNAME".png
mv $MXLKPATH/looks/"$NEWNAME"-thumb.png $MXLKPATH/looks/"$NEWNAME".png
sleep 0.5
for i in $WINLIST;
do
WINNUM=$i
wmctrl -i -r "$i" -b toggle,hidden
done
#all done
ALLDONE="$(eval_gettext 'All done!\n\nLook has been saved as <b>$NEWNAME</b>')"
yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--width=400 --height=250 --fixed --center --borders=20 \
--text="$ALLDONE" --text-align=center --button="$BTN_OK":9
}
#################################
#function restore look
restore_look() {
#define some variables
source gettext.sh
#read Settings for new look
if [ -f /tmp/lookselection.txt ]; then
touch /tmp/look_tempname.txt
look_to_restore=$(cat /tmp/lookselection.txt )
source "$look_to_restore"
##################
#check if files exist
if [ ! -d "$look_fluxstyle" ] && [ ! -f "$look_fluxstyle" ]; then
missinglist+=("Fluxbox Style- $look_fluxstyle")
missing_fbstyle=yes
fi
while [ ! -f "$look_wallpaper" ]; do
text_missing_wp1="$(eval_gettext 'not found!')"
text_missing_wp2="$(eval_gettext 'Select an alternative wallpaper.')"
cd /usr/share/backgrounds
look_wallpaper=$(yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--center --width=800 --height=200 --borders=10 --image="dialog-error" --separator="" \
--text="\n<b>$look_wallpaper $text_missing_wp1\n\n$text_missing_wp2</b>\n" --text-align=center \
--file --image-filter --add-preview --large-preview \
--button="${BTN_CANCEL}":31 --button="${BTN_OK}":32 )
case $? in
31 | 252 )
look_wallpaper=/usr/share/backgrounds/THE_Dark_Metal.png
exit
;;
esac
done
if [ ! -d /usr/share/themes/$look_theme ] && [ ! -d $HOME/.themes/$look_theme ] && [ ! -d $HOME/.local/share/themes/$look_theme ]; then
missinglist+=("Gtk Theme: $look_theme")
missing_theme=yes
fi
if [ ! -d /usr/share/icons/$look_icon ] && [ ! -d $HOME/.icons/$look_icon ] && [ ! -d $HOME/.local/share/icons/$look_icon ]; then
missinglist+=("Icon Theme: $look_icon")
missing_icon=yes
fi
look_fontcheck=$(echo $look_font | sed -e 's/-/ /g' | sed -e 's/[0-9]//g' | sed -e 's/Condensed//')
look_fontcheck=$(echo $look_fontcheck)
look_fontcheck2=$(fc-list | grep -i "$look_fontcheck")
if [ -z "$look_fontcheck2" ]; then
missinglist+=("Font: $look_font")
missing_font=yes
fi
if [ ! -d /usr/share/icons/$look_cursor ] && [ ! -d $HOME/.icons/$look_cursor ] && [ ! -d $HOME/.local/share/icons/$look_cursor ]; then
missinglist+=("Cursor: $look_cursor")
missing_cursor=yes
fi
if [ ! -f "$look_tint1" ]; then
missinglist+=("Tint2 Panel: $look_tint1")
missing_tint1=yes
fi
if [ "$look_tint2" != "None" ]; then
if [ ! -f "$look_tint2" ]; then
missinglist+=("Tint2 Panel: $look_tint2")
missing_tint2=yes
fi
fi
if [ ! -f "$look_rofi" ]; then
missinglist+=("Rofi: $look_rofi")
missing_rofi=yes
fi
if [ ! -f "$look_conky2" ]; then
missinglist+=("Conky: $look_conky2")
missing_conky=yes
fi
apply_restore=yes
if [ ! -z "$missinglist" ]; then
printf '%s\n' "${missinglist[@]}" > /tmp/look_missinglist.txt
text_missing_1="$(gettext 'The following elements cannot be found and will not be restored.')"
text_missing_2="$(gettext 'Continue anyway?')"
BTN_CANCEL=$(gettext "Cancel") ; BTN_CANCEL+='!window-close'
yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--center --width=600 --height=200 --borders=10 --image="dialog-error" \
--text="$text_missing_1\n$text_missing_2" --text-align=center \
--buttons-layout=spread \
--button="${BTN_RESTORE}":21 \
--button="${BTN_CANCEL}":22 \
--text-info --wrap --margins=10 < /tmp/look_missinglist.txt
case $? in
22 | 252 )
apply_restore=no
;;
21 )
apply_restore=yes
;;
esac
fi
###################
look_fluxstyle="session.styleFile: $look_fluxstyle"
look_fluxstyle=$( echo "$look_fluxstyle" | sed -e 's/[]$\/*[\^]/\\&/g' )
look_theme3="gtk-theme-name=$look_theme"
look_icon3="gtk-icon-theme-name=$look_icon"
look_font=$(echo "$look_font" | sed -e 's/-/ /g')
look_font3="gtk-font-name=$look_font"
look_theme2="gtk-theme-name=\"$look_theme\""
look_icon2="gtk-icon-theme-name=\"$look_icon\""
look_font2="gtk-font-name=\"$look_font\""
look_cursor1="gtk-cursor-theme-name=$look_cursor"
look_cursor1=$( echo "$look_cursor1" | sed -e 's/[]$\/*[\^]/\\&/g' )
look_cursor2="gtk-cursor-theme-name=\"$look_cursor\""
look_cursor2=$( echo "$look_cursor2" | sed -e 's/[]$\/*[\^]/\\&/g' )
if [ -f $HOME/.icons/default/index.theme ]; then
look_cursor3="Inherits=$look_cursor"
look_cursor3=$( echo "$look_cursor3" | sed -e 's/[]$\/*[\^]/\\&/g' )
fi
look_tint1=$( echo "$look_tint1" | sed -e 's/[]$\/*[\^]/\\&/g' )
if [ "$look_tint2" != "None" ]; then
look_tint2=$( echo "$look_tint2" | sed -e 's/[]$\/*[\^]/\\&/g' )
fi
look_rofi="@theme \"$look_rofi\""
look_rofi=$( echo "$look_rofi" | sed -e 's/[]$\/*[\^]/\\&/g' )
look_checkfeh=
look_wallpaper1="file=$look_wallpaper"
look_wallpaper1=$( echo "$look_wallpaper1" | sed -e 's/[]$\/*[\^]/\\&/g' )
look_conky1="cd \"$look_conky1\""
look_conky2="conky -c \"$look_conky2\" &"
#read current look components
#fluxbox style
look_fluxstyle_old="$(grep "styleFile" $HOME/.fluxbox/init)"
look_fluxstyle_old=$(echo "${look_fluxstyle_old}" | sed -e 's/[]$\/*[\^]/\\&/g' )
#theme and icons
look_theme_old3="$(grep "gtk-theme-name" $HOME/.config/gtk-3.0/settings.ini)"
look_icon_old3="$(grep "gtk-icon-theme-name" $HOME/.config/gtk-3.0/settings.ini)"
look_font_old3="$(grep "gtk-font-name" $HOME/.config/gtk-3.0/settings.ini)"
look_theme_old2="$(grep "gtk-theme-name" $HOME/.gtkrc-2.0)"
look_icon_old2="$(grep "gtk-icon-theme-name" $HOME/.gtkrc-2.0)"
look_font_old2="$(grep "gtk-font-name" $HOME/.gtkrc-2.0)"
look_theme_old3=$(echo "${look_theme_old3}" | sed -e 's/[]$ .*[\^]/\\&/g' )
look_icon_old3=$(echo "${look_icon_old3}" | sed -e 's/[]$ .*[\^]/\\&/g' )
look_font_old3=$(echo "${look_font_old3}" | sed -e 's/[]$ .*[\^]/\\&/g' )
look_theme_old2=$(echo "${look_theme_old2}" | sed -e 's/[]$ .*[\^]/\\&/g' )
look_icon_old2=$(echo "${look_icon_old2}" | sed -e 's/[]$ .*[\^]/\\&/g' )
look_font_old2=$(echo "${look_font_old2}" | sed -e 's/[]$ .*[\^]/\\&/g' )
#cursor
look_cursor_old1=$(grep "gtk-cursor-theme-name" $HOME/.config/gtk-3.0/settings.ini )
look_cursor_old1=$(echo "${look_cursor_old1}" | sed -e 's/[]$ .*[\^]/\\&/g' )
look_cursor_old2=$(grep "gtk-cursor-theme-name" $HOME/.gtkrc-2.0 )
look_cursor_old2=$(echo "${look_cursor_old2}" | sed -e 's/[]$ .*[\^]/\\&/g' )
if [ -f $HOME/.icons/default/index.theme ]; then
look_cursor_old3=$(grep "Inherits" $HOME/.icons/default/index.theme)
look_cursor_old3=$( echo "$look_cursor_old3" | sed -e 's/[]$\/*[\^]/\\&/g' )
fi
#tint2
look_tint1_old="$(grep "tint2" $HOME/.config/tint2/tint2-sessionfile | sed -n 1p)"
look_tint2_old="$(grep "tint2" $HOME/.config/tint2/tint2-sessionfile | sed -n 2p)"
#rofi
look_rofi_old="$(grep '@theme' $HOME/.config/rofi/config.rasi | tail -1)"
look_rofi_old=$(echo "${look_rofi_old}" | sed -e 's/[]$\/*[\^]/\\&/g' )
#wallpaper
look_checkfeh=$(grep '#nitrogen' "$HOME"/.fluxbox/startup)
if [ -z "$look_checkfeh" ]; then
look_wallpaper_old="$(grep "file=" $HOME/.config/nitrogen/bg-saved.cfg | sed -n 2p)"
look_wallpaper_old=$(echo "${look_wallpaper_old}" | sed -e 's/[]$\/*[\^]/\\&/g' )
if [ -z "$look_wallpaper_old" ]; then
look_wallpaper_old="$(grep "file=" $HOME/.config/nitrogen/bg-saved.cfg)"
look_wallpaper_old=$(echo "${look_wallpaper_old}" | sed -e 's/[]$\/*[\^]/\\&/g' )
fi
fi
#conky
look_conkystate_old="$(grep "Hidden" $HOME/.config/autostart/conky.desktop | sed -e 's/Hidden=//')"
#################################
#Edit Config files
if [ "$apply_restore" = "yes" ]; then
#fluxbox
if [ "$missing_fbstyle" != "yes" ]; then
cd $HOME/.fluxbox
sed -i -e "s/${look_fluxstyle_old}/${look_fluxstyle}/" ~/.fluxbox/init
fluxbox-remote restart
fi
#gtk
if [ "$missing_theme" != "yes" ]; then
sed -i -e "s/${look_theme_old3}/${look_theme3}/" $HOME/.config/gtk-3.0/settings.ini
sed -i -e "s/${look_theme_old2}/${look_theme2}/" $HOME/.gtkrc-2.0
fi
if [ "$missing_icon" != "yes" ]; then
sed -i -e "s/${look_icon_old3}/${look_icon3}/" $HOME/.config/gtk-3.0/settings.ini
sed -i -e "s/${look_icon_old2}/${look_icon2}/" $HOME/.gtkrc-2.0
fi
if [ "$missing_font" != "yes" ]; then
sed -i -e "s/${look_font_old3}/${look_font3}/" $HOME/.config/gtk-3.0/settings.ini
sed -i -e "s/${look_font_old2}/${look_font2}/" $HOME/.gtkrc-2.0
fi
#cursor
if [ "$missing_cursor" != "yes" ]; then
sed -i -e "s/${look_cursor_old1}/${look_cursor1}/" $HOME/.config/gtk-3.0/settings.ini
sed -i -e "s/${look_cursor_old2}/${look_cursor2}/" $HOME/.gtkrc-2.0
if [ -f $HOME/.icons/default/index.theme ]; then
if [ "$look_cursor" = "default" ]; then
rm -rf $HOME/.icons/default
fi
if [ "$look_cursor" != "default" ]; then
sed -i -e "s/${look_cursor_old3}/${look_cursor3}/" $HOME/.icons/default/index.theme
fi
fi
if [ ! -f $HOME/.icons/default/index.theme ] && [ "$look_cursor" != "default" ]; then
mkdir -p $HOME/.icons/default
printf "[Icon Theme]
Name=Default
Comment=Default Cursor Theme
Inherits=$look_cursor" > $HOME/.icons/default/index.theme
fi
fi
#gtk bash
function reload_gtk_theme() {
theme=$(gsettings get org.gnome.desktop.interface gtk-theme)
gsettings set org.gnome.desktop.interface gtk-theme ''
sleep 1
gsettings set org.gnome.desktop.interface gtk-theme "$theme"
}
reload_gtk_theme
#tint
cd $HOME/.config/tint2
if [ "$look_tintnum" = 2 ]; then
if [ "$missing_tint1" != "yes" ] && [ "$missing_tint2" != "yes" ]; then
rm tint2-sessionfile
killall tint2
look_tintNEWA=$(basename "$look_tint1")
look_tintNEWB=$(basename "$look_tint2")
echo "$look_tint1
$look_tint2" >> ~/.config/tint2/tint2-sessionfile
tint2 -c $HOME/.config/tint2/"$look_tintNEWA" >/dev/null 2>&1 & disown
tint2 -c $HOME/.config/tint2/"$look_tintNEWB" >/dev/null 2>&1 & disown
fi
fi
if [ "$look_tintnum" = 1 ]; then
if [ "$missing_tint1" != "yes" ]; then
rm tint2-sessionfile
killall tint2
look_tintNEWA=$(basename "$look_tint1")
echo "$HOME/.config/tint2/$look_tintNEWA" >> ~/.config/tint2/tint2-sessionfile
tint2 -c "$HOME"/.config/tint2/"$look_tintNEWA" >/dev/null 2>&1 & disown
fi
fi
if [ "$look_tintnumNEW" = 0 ]; then
rm tint2-sessionfile
killall tint2
echo "" >> ~/.config/tint2/tint2-sessionfile
fi
#rofi
if [ "$missing_rofi" != "yes" ]; then
sed -i "s/$look_rofi_old/$look_rofi/g" $HOME/.config/rofi/config.rasi
fi
#wallpaper
if [ -z "$look_checkfeh" ]; then
cd $HOME/.config/nitrogen
sed -i -e "s/${look_wallpaper_old}/${look_wallpaper1}/g" bg-saved.cfg
feh --bg-scale $look_wallpaper
else
feh --bg-scale $look_wallpaper
fi
#conky
if [ "$missing_conky" != "yes" ]; then
printf "#!/bin/sh
killall conky
sleep 5s
$look_conky1
$look_conky2
exit 0" > $HOME/.conky/conky-startup.sh
if [ "$look_conkystate" = "false" ]; then
killall conky
exec sh $HOME/.conky/conky-startup.sh &
sed -i 's/Hidden=.*/Hidden=false/' $HOME/.config/autostart/conky.desktop
else
killall conky
sed -i 's/Hidden=.*/Hidden=true/' $HOME/.config/autostart/conky.desktop
fi
conky_checkstart=$(grep 'conkystart' $HOME/.fluxbox/startup)
if [ "$conky_checkstart" = "#conkystart" ] && [ "$look_conkystate" = "false" ]; then
sed -i 's/#conkystart/conkystart/' $HOME/.fluxbox/startup
fi
if [ "$conky_checkstart" = "conkystart" ] && [ "$look_conkystate" = "true" ]; then
sed -i 's/conkystart/#conkystart/' $HOME/.fluxbox/startup
fi
fi
fi
unset missinglist apply_restore missing_fbstyle missing_theme missing_icon missing_font missing_cursor missing_tint1 missing_tint2 missing_rofi missing_conky
rm -f /tmp/look_missinglist.txt
fi
}
#################################
#function about_look
about_look() {
#set some variables
source gettext.sh
#button label
BTN_LICENSE=$(gettext "License")
# button label
BTN_CHANGELOG=$(gettext "Changelog"); BTN_CHANGELOG+='!preferences-system-time-symbolic'
#about window app name
ABOUTTEXT_TOP="$(gettext 'MXFB Look')"
#about window text
ABOUTTEXT_1="$(gettext 'Version')"
ABOUTTEXT_2="$(gettext 'Save and restore desktop settings for MX-Linux Fluxbox')"
ABOUTTEXT_4="<b>mxlinux.org</b>"
ABOUTTEXT_5="Copyright (c) Melber - MX Linux"
until [ "$about_loop" = "closed" ]; do
yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--borders=10 --center --width=300 --height=500 --fixed \
--image="/usr/share/pixmaps/mxfb-look-96.svg" \
--buttons-layout=spread --button="${BTN_LICENSE}":12 --button="${BTN_CHANGELOG}":10 --button="${BTN_CLOSE}":1 \
--form --columns=1 --align=center \
--field="<b><big>$ABOUTTEXT_TOP</big></b>":LBL " " \
--field=" ":LBL " " \
--field="$ABOUTTEXT_1 $VERSION":LBL " " \
--field=" ":LBL " " \
--field="<big>$ABOUTTEXT_2</big>":LBL " " \
--field=" ":LBL " " \
--field=" ":LBL " " \
--field="$ABOUTTEXT_4":BTN 'sensible-browser https://mxlinux.org' \
--field=" ":LBL " " \
--field="$ABOUTTEXT_5":LBL " " \
> /dev/null
case $? in
1 | 252 )
about_loop=closed
;;
10 )
printf "$(zcat /usr/share/doc/mxfb-accessories/changelog.gz)" > /tmp/look-clog.txt
yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--borders=10 --center --width=400 --height=500 --fixed \
--text-info < /tmp/look-clog.txt --wrap --show-uri \
--button="${BTN_CLOSE}":1 \
> /dev/null
rm /tmp/look-clog.txt
;;
12 )
yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--borders=10 --center --width=400 --height=500 --fixed \
--text-info < /usr/share/doc/mxfb-accessories/copyright --wrap --show-uri \
--button="${BTN_CLOSE}":1 \
> /dev/null
;;
esac
done
}
#################################
#MAIN LOOK
#Set up pipe
export fpipe="$(mktemp -u --tmpdir looktemp.XXXXXXXX)"
mkfifo "$fpipe"
trap "rm "$fpipe"" EXIT
exec 3<> "$fpipe"
until [ "$look_status" = "finished" ]; do
unset look_list look_array images
look_list=$(ls -f $HOME/.config/MX-Linux/mxfb-look/looks/*.look2)
look_array=($look_list)
for i in "${look_array[@]}"; do
j=$(echo $i | sed -e 's/\.look2/\.png/')
k=$(basename $i | sed -e 's/\.look2//')
image_add=$(echo "$i $k $j")
images+=($image_add)
done
look_infotext () {
echo -e "\f"
printf $1 > /tmp/lookselection.txt
source $1
if [ "$look_tintnum" = "1" ]; then
look_tint0=$(basename "$look_tint1")
else
look_tint1=$(basename "$look_tint1")
look_tint2=$(basename "$look_tint2")
look_tint0="$look_tint1
Tint2 Panel: $look_tint2"
fi
look_title=$(basename $1 | sed -e 's/\.look2//')
look_fluxstyle=$(basename "$look_fluxstyle")
look_title=$(basename $1 | sed -e 's/\.look2//')
look_tint0=$(basename "$look_tint0")
look_font=$(echo $look_font | sed -e 's/ /-/')
look_cursor=$(echo $look_cursor | sed -e 's/ /-/')
look_rofi0=$(basename "$look_rofi" | sed -e 's/\.rasi//' )
look_wallpaper=$(basename "$look_wallpaper")
look_conkyname=$(echo $look_conky1 | sed -e 's/\/usr\/share\/mx-conky-data\/themes\///')
if [ "$look_conkystate" = "false" ]; then
look_conkystate='Active'
else
look_conkystate='Inactive'
fi
echo "
$look_title
Fluxbox Style: $look_fluxstyle
Wallpaper: $look_wallpaper
Gtk-Theme: $look_theme
Icon Theme: $look_icon
Font: $look_font
Cursor: $look_cursor
Tint2 Panel: $look_tint0
Rofi Theme: $look_rofi0
Conky: $look_conkyname
Conky Status: $look_conkystate
"
}
export -f look_infotext
look_boxtextstart=$(cat "$MXLKPATH/looks/firsttext.txt")
echo "$look_boxtextstart" > $fpipe
key=$RANDOM
#define some variables
TEXTMAIN="$(gettext 'Select a saved look to restore or save the current setup as a new look')"
#MAIN YAD WINDOW
yad --plug=$key --tabnum=1 \
--select-action='bash -c "look_infotext %s >$fpipe"' \
--list --no-headers --hide-column=1 --print-column=3 --grid-lines=hor \
--column=Path --column=Name --column=":IMG" \
${images[@]} >/dev/null &
yad --plug=$key --tabnum=2 --listen --cycle-read \
--wrap --margins=10 --text-info= <&3 &
yad --title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--paned --key=$key --orient=Horizontal --splitter=400 \
--center --width=600 --height=450 --borders=10 \
--text="\n<b>$TEXTMAIN</b>\n" --text-align=center --buttons-layout=spread \
--button="${BTN_ABOUT}":2 \
--button="${BTN_RESTORE}":5 \
--button="${BTN_SAVE}":4 \
--button="${BTN_CLOSE}":3 \
case $? in
2 )
about_look
look_status="notyet"
;;
3 | 252 )
look_status="finished"
;;
4 )
save_look
look_status="notyet"
;;
5 )
restore_look
look_status="notyet"
;;
esac
done
rm -f /tmp/lookselection.txt /tmp/look_tempname.txt
exit
#################################