-
Notifications
You must be signed in to change notification settings - Fork 0
/
changebackgd.sh
executable file
·87 lines (81 loc) · 2.54 KB
/
changebackgd.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
#!/bin/bash
# language
declare -A Ltab=(
["fr_toolNotSet"]="Veuillez configurer un outil pour appliquer le fichier background."
["fr_langApply"]="Utilisation du français."
["fr_langError"]="Impossible de déterminer la langue à utiliser. Application de l'anglais par défaut."
["fr_fExists"]="Le fichier de liste existe déjà."
["fr_fApply"]="Application du fichier"
["fr_fCreated"]="Le fichier de liste a été créé."
["fr_dirError"]="Un des dossiers d'images n'existe pas."
["en_toolNotSet"]="Please configure a tool to apply the background file."
["en_langApply"]="Utilisation de l'anglais."
["en_langError"]="Can not get the language to use. Setting to english by default."
["en_fExists"]="List file already exists."
["en_fApply"]="Setting file"
["en_fCreated"]="Lis file created."
["en_dirError"]="One of images directories does not exists."
)
language=""
if [[ -z ${LANG} ]]
then
language="en"
echo ${Ltab["${language}_langError"]}
else
[[ ${LANG} =~ .*fr.* ]] && language="fr" && echo ${Ltab["${language}_langApply"]}
[[ ${LANG} =~ .*en.* ]] && language="en" && echo ${Ltab["${language}_langApply"]}
[[ -z ${language} ]] && language="en" && echo ${Ltab["${language}_langError"]}
fi
# Configuration
setTool=$(which nitrogen)
optTool="--set-centered"
declare -a DISPLAYS=(
":0.0"
)
declare -a IMG_DIR=(
"${HOME}/Documents/backgrounds"
)
TMP_DIR="${HOME}/Documents/changeBackground"
LIST_FILE="list.txt"
# functions
function getFiles {
OLDIFS=${IFS}
IFS="||"
$(rm -f "${TMP_DIR}/${LIST_FILE}")
for i in ${IMG_DIR[*]}
do
if [[ ! -d "$i" ]]
then
echo ${Ltab["${language}_dirError"]}
else
for file in $(find "$i" -maxdepth 1 -type f -regex ".*\.\(png\|jpg\|jpeg\|\bmp\)")
do
echo "${file}" >> "${TMP_DIR}/${LIST_FILE}"
done
fi
done
IFS=${OLDIFS}
echo ${Ltab["${language}_fCreated"]}
}
function setBckgd {
if [[ -z ${setTool} ]]
then
echo ${Ltab["${language}_toolNotSet"]}
else
OLDIFS=${IFS}
IFS="||"
bckgd=$(sort --random-sort "${TMP_DIR}/${LIST_FILE}" | head -n 1)
[[ -z ${bckgd} ]] && getFiles && bckgd=$(sort --random-sort "${TMP_DIR}/${LIST_FILE}" | head -n 1)
newList=$(cat "${TMP_DIR}/${LIST_FILE}" | grep -v "${bckgd}")
echo ${newList} > "${TMP_DIR}/${LIST_FILE}"
echo ${Ltab["${language}_fApply"]} $(basename ${bckgd}).
$(DISPLAY=$1 ${setTool} ${optTool} ${bckgd})
IFS=${OLDIFS}
fi
}
# main
[[ ! -s "${TMP_DIR}/${LIST_FILE}" ]] && getFiles || echo ${Ltab["${language}_fExists"]}
for i in ${DISPLAYS[*]}
do
setBckgd "$i"
done