| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
function Usage() |
| 4 |
{ |
| 5 |
echo -e "$0 - Fcitx Fbterm launch helper" |
| 6 |
echo -e "\t-d [display number]\t\tspecify display number (For example 0)" |
| 7 |
echo -e "\t-l\t\t\t\tLaunch Fcitx automatically" |
| 8 |
echo -e "\t-h\t\t\t\tPrint this help" |
| •9 |
printf "\n%s\n" "Please read /usr/share/doc/fcitx-frontend-fbterm/README.Debian" |
| 10 |
printf "%s\n" "for fcitx-fbterm usage on Debian-based systems." |
| 11 |
} |
| 12 |
|
| 13 |
LAUNCH=0 |
| 14 |
FCITX_RUN=0 |
| 15 |
|
| 16 |
if [ "x$SHELL" = "x" ]; then |
| 17 |
echo "\$SHELL is not set" |
| 18 |
fi |
| 19 |
|
| 20 |
while getopts "d:lh" opt; do |
| 21 |
case $opt in |
| 22 |
d) |
| 23 |
DISPLAY_NUM=$OPTARG |
| 24 |
;; |
| 25 |
l) |
| 26 |
LAUNCH=1 |
| 27 |
;; |
| 28 |
*) |
| 29 |
Usage |
| 30 |
exit 0 |
| 31 |
;; |
| 32 |
esac |
| 33 |
done |
| 34 |
|
| 35 |
if [ "x$DISPLAY_NUM" != "x" ]; then |
| 36 |
export DISPLAY=":$DISPLAY_NUM" |
| 37 |
fi |
| 38 |
|
| 39 |
if [ "x$DISPLAY" != "x" ]; then |
| 40 |
number=`echo $DISPLAY | sed 's|\:\([0-9]\+\)\(\..*\)\?|\1|g'` |
| 41 |
if [ "x$number" == "x" ]; then |
| 42 |
echo '$DISPLAY parse error' |
| 43 |
exit 1 |
| 44 |
fi |
| 45 |
echo "Your display number is $number" |
| 46 |
else |
| 47 |
number=0 |
| 48 |
fi |
| 49 |
|
| 50 |
echo "Test whether fcitx is running correctly with dbus..." |
| 51 |
fcitx-remote > /dev/null 2>&1 |
| 52 |
|
| 53 |
if [ $? == "1" ]; then |
| 54 |
echo "Cannot communicate fcitx with DBus." |
| 55 |
FCITX_RUN=0 |
| 56 |
else |
| 57 |
echo "Fcitx is running correctly." |
| 58 |
FCITX_RUN=1 |
| 59 |
fi |
| 60 |
|
| 61 |
echo '' |
| 62 |
echo '=========================================================' |
| 63 |
|
| 64 |
if [ "$FCITX_RUN" == "0" -a "$LAUNCH" == "1" ]; then |
| 65 |
echo "Try launch fcitx..." |
| 66 |
pgrep -u `whoami` '^fcitx$' > /dev/null 2>&1 |
| 67 |
if [ $? == "0" ]; then |
| 68 |
echo "There is already a fcitx running, Fcitx cannot support multi instance currently" |
| 69 |
exit 1 |
| 70 |
fi |
| 71 |
echo "Launch Fcitx..." |
| 72 |
fcitx -D > /dev/null 2>&1 & |
| 73 |
fcitxpid=$! |
| 74 |
FCITX_RUN=1 |
| 75 |
fi |
| 76 |
|
| 77 |
if [ $FCITX_RUN == "1" ]; then |
| 78 |
echo "Launch fbterm..." |
| 79 |
fbterm -i fcitx-fbterm |
| 80 |
if [ "$LAUNCH" == "1" ] ; then |
| 81 |
if ! test -z "$fcitxpid" ; then |
| 82 |
kill $fcitxpid |
| 83 |
fi |
| 84 |
fi |
| 85 |
else |
| 86 |
echo '=========================================================' |
| 87 |
echo 'Fcitx is not running, you may setup it mannually' |
| 88 |
echo 'The easiest way is set $DISPLAY, start fcitx from X' |
| 89 |
echo 'Then try this helper' |
| 90 |
echo '=========================================================' |
| 91 |
fi |