#!/bin/bash # author sudodus alias nio-wiklund at launchpad # # date editor comment # 2015-04-16 sudodus Created # 2015-04-17 sudodus Auto mode mkdir -p "$HOME/.ztweaks" lst="$HOME/.ztweaks/lst" schk="$HOME/.ztweaks/schk" tchk="$HOME/.ztweaks/tchk" str="$HOME/.ztweaks/str" auto=false ####################################################################### function tmaster { ans= while [ "$ans" != "q" ] do read setx[0] < "$schk" read langset < "$lst" # echo "langset=$langset" # echo "setx[0]=${setx[0]}" if [ "$langset" == "" ] || [ "${setx[0]}" != "TRUE" ] then langstr="Default code: 'us'" else langstr="Current code: '$langset'" fi ans=$(zenity --list --width=640 --height=240 \ --title="zTweaks - master menu" --cancel-label="Quit" \ --window-icon="/usr/share/icons/ztweaks.png" \ --text="Select an action (a line) from the list below" \ --column="Hotkey" --column="Action" \ "a" "Auto to use saved settings and skip further menus" \ "l" "Language (country code) for the keyboard. $langstr" \ "s" "Settings" \ "t" "Touchpad management" \ "q" "Quit" ) if [ $? -ne 0 ] then return fi ans=${ans:0:1} # fix for buggy(?) zenity --list in trusty # echo "xxx $ans xxx" if [ "$ans" == "a" ] then auto=true setter tpad return elif [ "$ans" == "l" ] then sel-lang setter elif [ "$ans" == "s" ] then setter elif [ "$ans" == "t" ] then tpad fi done } ####################################################################### function sel-lang { langlist=$(find /usr/share/X11/xkb/symbols -maxdepth 1 -type f| sed 's#.*/##'| \ sort|grep -v -e altwin -e capslock -e compose -e ctrl -e empty -e eurosign \ -e group -e inet -e keypad -e kpdl -e level -e nbsp -e olpc -e rupeesign \ -e shift -e srvr_ctrl -e terminate -e typo|tr '\n' ' ') read langset < "$lst" if [ "$langset" == "" ] then langset="us" fi langlist="$langset $langlist" #echo "$langlist" langset=$(zenity --list --width=400 --height=500 \ --title="zTweaks - select language for keyboard" --cancel-label="Quit" \ --window-icon="/usr/share/icons/ztweaks.png" \ --text="Current language (country) code: '$langset'" \ --window-icon="/usr/share/icons/ztweaks.png" \ --column="Select from the list or Quit to keep '$langset'" \ $langlist ) if [ $? -ne 0 ] || [ "$langset" == "" ] then return fi echo "${langset//|*}" > "$lst" #cat "$lst" } ####################################################################### function setter { read langset < "$lst" declare -a setx=( "FALSE" "setxkbmap $langset" "setxkbmap us") read setx[0] < "$schk" if $auto then if [ "${setx[0]}" == "TRUE" ] then echo "${setx[1]}" > $str else echo "${setx[2]}" > $str fi else zenity --list --width=640 --height=200 \ --title="zTweaks - select (and save) settings" --cancel-label="Quit" \ --window-icon="/usr/share/icons/ztweaks.png" \ --text="Tick to select items in the list below" \ --checklist \ --separator=" " \ --print-column="2" \ --column="State" --column="Command" --column="Setting" \ "${setx[0]}" "${setx[1]}" "Language (country code) for the keyboard, default 'us'" \ > "$str" if [ $? -ne 0 ] then return fi fi #cat "$str" grep "${setx[1]}" "$str" >/dev/null if [ $? -eq 0 ] then setx[0]="TRUE" # echo "${setx[1]}" ${setx[1]} else setx[0]="FALSE" # echo "${setx[2]}" ${setx[2]} fi echo "${setx[0]}" > "$schk" #echo "${setx[0]}" } ####################################################################### function tpad { read langset < "$lst" declare -a syncl=( "FALSE" "synclient touchpadoff=1" "synclient touchpadoff=0" ) declare -a synda=( "FALSE" "syndaemon -d" "pkill -9 syndaemon" ) read syncl[0] synda[0] < "$tchk" if $auto then if [ "${syncl[0]}" == "TRUE" ] then tmp="${syncl[1]}" fi if [ "${synda[0]}" == "TRUE" ] then if [ "$tmp" != "" ] then tmp="$tmp ${synda[1]}" else tmp="${synda[1]}" fi fi echo "$tmp" > "$str" else zenity --list --width=640 --height=200 \ --title="zTweaks - select (and save) touchpad settings" --cancel-label="Quit" \ --window-icon="/usr/share/icons/ztweaks.png" \ --text="Tick to select items in the list below" \ --checklist \ --separator=" " \ --print-column="2" \ --column="State" --column="Command" --column="Setting" \ "${syncl[0]}" "${syncl[1]}" "Touchpad Off" \ "${synda[0]}" "${synda[1]}" "Touchpad temporary off while typing" \ > "$str" if [ $? -ne 0 ] then return fi fi #cat "$str" grep "${syncl[1]}" "$str" >/dev/null if [ $? -eq 0 ] then syncl[0]="TRUE" # echo "${syncl[1]}" ${syncl[1]} 2> /dev/null else syncl[0]="FALSE" # echo "${syncl[2]}" ${syncl[2]} 2> /dev/null fi grep "${synda[1]}" "$str" >/dev/null if [ $? -eq 0 ] then synda[0]="TRUE" # echo "${synda[1]}" ${synda[1]} else synda[0]="FALSE" # echo "${synda[2]}" ${synda[2]} fi echo "${syncl[0]} ${synda[0]}" > "$tchk" #echo "${syncl[0]} ${synda[0]}" } ####################################################################### # # ztweaks main program # ####################################################################### if [ $# -eq 0 ] then tmaster elif [ "$1" == "auto" ] then auto=true setter tpad else echo "Usage: $0 [auto] # auto to use saved settings and skip menus" fi