-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdmctl.sh
executable file
·141 lines (137 loc) · 3.5 KB
/
fdmctl.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
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
usage(){
echo "fdmctl init: initialize the user configuration directory"
echo "fdmctl list: list all the available sessions"
echo "fdmctl cache: list the sessions of the directory \"cache\""
echo "fdmctl check <session nale>: check which binary is used by a given session"
echo "fdmctl default [<session name>]: check or define the default session"
echo "fdmctl add <session name> <binary path> [x(default) | w[ayland] | e[xtra]]: add a new session"
echo "fdmctl enable/disable <session name>: enable or disable a session"
exit
}
check(){
readlink "$1" || cat "$1"
}
if [ ! -n "$1" ]
then
usage
exit
fi
case "$1" in
init)
shift
init "$@"
;;
list)
echo "X session list : "
for session in ${X}/*; do
[ -x "$session" ] && echo $(basename "$session")
done
echo ""
echo "Wayland session list : "
for session in ${WAYLAND}/*; do
[ -x "$session" ] && echo $(basename "$session")
done
echo ""
echo "Other session list : "
for session in ${EXTRA}/*; do
[ -x "$session" ] && echo $(basename "$session")
done
;;
cache)
for file in "$CACHEDIR"/*; do
fn=$(basename "$file")
echo ${fn:1}
done
;;
default)
if [ ! -n "$2" ]
then
echo "Checking $(readlink ${DEFAULT})"
check $(readlink ${DEFAULT})
elif [ ! -n "$3" ]
then
if [ -x "${X}/$2" ]
then
echo "Setting default to $2"
ln -sf "${X}/$2" "${DEFAULT}"
elif [ -x "${WAYLAND}/$2" ]
then
echo "Setting default to $2"
ln -sf "${WAYLAND}/$2" "${DEFAULT}"
elif [ -x "${EXTRA}/$2" ]
then
echo "Setting default to $2"
ln -sf "${EXTRA}/$2" "${DEFAULT}"
else
echo "fdmctl error: $2 is not available"
fi
elif [ ! -n "$4" ]
then
if [ -x "$CONFDIR/$2/$3" ]
then
echo "Setting default to $3"
ln -sf "$CONFDIR/$2/$3" "${DEFAULT}"
else
echo "fdmctl error: $2/$3 is not available"
fi
else
echo "fdmctl error: syntaxe is fdmctl default [ [ folder ] session ]"
usage
fi
;;
check)
if [ ! -n "$2" ]
then usage
fi
if [ -f "${X}/$2" ]
then check "${X}/$2"
elif [ -f "${WAYLAND}/$2" ]
then check "${WAYLAND}/$2"
elif [ -f "${EXTRA}/$2" ]
then check "${EXTRA}/$2"
else
echo "$2 not exist!"
exit 1
fi
;;
add)
[ -n "$3" ]||usage
if [[ "$4" == "X" || "$4" == "x" || "$4" == "" ]]
then ln -s "$3" "${X}/$2"
elif [ "$4" = "wayland" ] || [ "$4" = "w" ] || [ "$4" = "W" ]
then ln -s "$3" "${WAYLAND}/$2"
elif [ "$4" = "extra" ] || [ "$4" = "e" ] || [ "$4" = "E" ]
then ln -s "$3" "${EXTRA}/$2"
else usage
fi
;;
enable)
if [ -f "${CACHEDIR}/X$2" ]
then cp -v "${CACHEDIR}/X$2" "${X}/$2"
fi
if [ -f "${CACHEDIR}/W$2" ]
then cp -v "${CACHEDIR}/W$2" "${WAYLAND}/$2"
fi
if [ -f "${CACHEDIR}/E$2" ]
then mv -v "${CACHEDIR}/E$2" "${EXTRA}/$2"
fi
;;
disable)
if [ ! -d "${CACHEDIR}" ]
then mkdir -p "${CACHEDIR}"
fi
# backup to cache
if [ -f "${X}/$2" ]
then mv -v "${X}/$2" "${CACHEDIR}/X$2"
fi
if [ -f "${WAYLAND}/$2" ]
then mv -v "${WAYLAND}/$2" "${CACHEDIR}/W$2"
fi
if [ -f "${EXTRA}/$2" ]
then mv -v "${EXTRA}/$2" "${CACHEDIR}/E$2"
fi
;;
*)
usage
;;
esac