This repository has been archived by the owner on May 8, 2024. It is now read-only.
/
fcitx-fbterm-helper
89 lines (78 loc) · 2.05 KB
/
fcitx-fbterm-helper
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
#!/bin/bash
function Usage()
{
echo -e "$0 - Fcitx Fbterm launch helper"
echo -e "\t-d [display number]\t\tspecify display number (For example 0)"
echo -e "\t-l\t\t\t\tLaunch Fcitx automatically"
echo -e "\t-h\t\t\t\tPrint this help"
}
LAUNCH=0
FCITX_RUN=0
if [ "x$SHELL" = "x" ]; then
echo "\$SHELL is not set"
fi
while getopts "d:lh" opt; do
case $opt in
d)
DISPLAY_NUM=$OPTARG
;;
l)
LAUNCH=1
;;
*)
Usage
exit 0
;;
esac
done
if [ "x$DISPLAY_NUM" != "x" ]; then
export DISPLAY=":$DISPLAY_NUM"
fi
if [ "x$DISPLAY" != "x" ]; then
number=`echo $DISPLAY | sed 's|\:\([0-9]\+\)\(\..*\)\?|\1|g'`
if [ "x$number" == "x" ]; then
echo '$DISPLAY parse error'
exit 1
fi
echo "Your display number is $number"
else
number=0
fi
echo "Test whether fcitx is running correctly with dbus..."
fcitx-remote > /dev/null 2>&1
if [ $? == "1" ]; then
echo "Cannot communicate fcitx with DBus."
FCITX_RUN=0
else
echo "Fcitx is running correctly."
FCITX_RUN=1
fi
echo ''
echo '========================================================='
if [ "$FCITX_RUN" == "0" -a "$LAUNCH" == "1" ]; then
echo "Try launch fcitx..."
pgrep -u `whoami` '^fcitx$' > /dev/null 2>&1
if [ $? == "0" ]; then
echo "There is already a fcitx running, Fcitx cannot support multi instance currently"
exit 1
fi
echo "Launch Fcitx..."
fcitx -D > /dev/null 2>&1 &
fcitxpid=$!
FCITX_RUN=1
fi
if [ $FCITX_RUN == "1" ]; then
echo "Launch fbterm..."
fbterm -i fcitx-fbterm
if [ "$LAUNCH" == "1" ] ; then
if ! test -z "$fcitxpid" ; then
kill $fcitxpid
fi
fi
else
echo '========================================================='
echo 'Fcitx is not running, you may setup it mannually'
echo 'The easiest way is set $DISPLAY, start fcitx from X'
echo 'Then try this helper'
echo '========================================================='
fi