#!/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" printf "\n%s\n" "Please read /usr/share/doc/fcitx-frontend-fbterm/README.Debian" printf "%s\n" "for fcitx-fbterm usage on Debian-based systems." } 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