Advertisement
Guest User

Untitled

a guest
May 27th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.11 KB | None | 0 0
  1. #! /bin/bash
  2. # -*- mode: sh -*-
  3. #
  4. # Author: Victor Ananjevsky <ananasik@gmail.com>, 2013
  5. #
  6.  
  7. KEY="12"
  8.  
  9. res1=$(mktemp --tmpdir iface1.XXXXXXXX)
  10. res2=$(mktemp --tmpdir iface2.XXXXXXXX)
  11. res3=$(mktemp --tmpdir iface3.XXXXXXXX)
  12.  
  13. rc_file="$HOME/.gtkrc-2.0"
  14.  
  15. #
  16. # Set yad binary location - LGM May 2015
  17. # Add the path to yad in YadLocal below only if the script can't find yad.
  18. YadLocal=""
  19. # Use YadLocal if defined and file is executable
  20. if [ ! -z ${YadLocal} ] && [ -x ${YadLocal} ]; then
  21. YAD=${YadLocal}
  22. # Default location given in original notebook script (yad make install location?)
  23. elif [ -x /usr/desktop/bin/yad ]; then
  24. YAD="/usr/desktop/bin/yad"
  25. # Default Debian, Mint, Ubuntu location
  26. elif [ -x /usr/bin/yad ]; then
  27. YAD="/usr/bin/yad"
  28. else
  29. # Final desperate guess to see if yad is in the $PATH
  30. YAD=$( which yad )
  31. # If yad still not found or still blank error and exit
  32. if [ -z ${YAD} ] || [ ! -x ${YAD} ]; then
  33. echo -e "\nERROR: UNABLE TO LOCATE YAD PROGRAM EXITING...\n \
  34. Please add the full path to yad in 'YadLocal' at the top of ${0}\n" >2; exit
  35. fi
  36. fi
  37.  
  38. # parse rc file
  39. PARSER='
  40. BEGIN { FS="="; OFS="\n"; }
  41. /^gtk-theme-name/ {printf "GTKTHEME=%s\n", $2}
  42. /^gtk-key-theme-name/ {printf "KEYTHEME=%s\n", $2}
  43. /^gtk-icon-theme-name/ {printf "ICONTHEME=%s\n", $2}
  44. /^gtk-cursor-theme-name/ {printf "CURSORTHEME=%s\n", $2}
  45. /^gtk-toolbar-style/ {printf "TBSTYLE=%s\n", $2}
  46. /^gtk-toolbar-icon-size/ {printf "TBICONSIZE=%s\n", $2}
  47. /^gtk-button-images/ {printf "BUTTONIMAGE=%s\n", ($2 == 1) ? "TRUE" : "FALSE"}
  48. /^gtk-menu-images/ {printf "MENUIMAGE=%s\n", ($2 == 1) ? "TRUE" : "FALSE"}
  49. /^gtk-font-name/ {printf "FONTDESCR=%s\n", $2}
  50. /^gtk-xft-antialiasing/ {printf "ANTIALIASING=%s\n", ($2 == 1) ? "TRUE" : "FALSE"}
  51. /^gtk-xft-hinting/ {printf "HINTING=%s\n", ($2 == 1) ? "TRUE" : "FALSE"}
  52. /^gtk-xft-hintstyle/ {printf "HINTSTYLE=%s\n", $2}
  53. /^gtk-xft-rgba/ {printf "RGBA=%s\n", $2}
  54. /^gtk-color-scheme/ {printf "COLORSCHEME=%s\n", $2}
  55. '
  56. eval $(sed -r "s/[ \t]*=[ \t]*/=/" $rc_file | awk "$PARSER")
  57.  
  58. # create list of gtk themes
  59. themelist=
  60. keythemelist="Default"
  61. for d in /usr/share/themes/*; do
  62. theme=${d##*/}
  63. if [[ -e $d/gtk-2.0/gtkrc ]]; then
  64. [[ $themelist ]] && themelist="$themelist!"
  65. [[ $theme == $GTKTHEME ]] && theme="^$theme"
  66. themelist+="$theme"
  67. fi
  68. if [[ -e $d/gtk-2.0-key/gtkrc ]]; then
  69. [[ $theme == $KEYTHEME ]] && theme="^$theme"
  70. keythemelist+="!$theme"
  71. fi
  72. done
  73.  
  74. # create list of icon and cursor themes
  75. iconthemelist="Default"
  76. cursorthemelist="Default"
  77. for d in /usr/share/icons/*; do
  78. theme=${d##*/}
  79. if [[ -e $d/index.theme ]]; then
  80. [[ $theme == $ICONTHEME ]] && theme="^$theme"
  81. iconthemelist+="!$theme"
  82. fi
  83. if [[ -d $d/cursors ]]; then
  84. [[ $theme == $CURSORTHEME ]] && theme="^$theme"
  85. cursorthemelist+="!$theme"
  86. fi
  87. done
  88.  
  89. # create toolbar styles list
  90. tbstylelist="Icons only"!
  91. [[ $TBSTYLE == GTK_TOOLBAR_TEXT ]] && tbstylelist+="^"
  92. tbstylelist+="Text only"!
  93. [[ $TBSTYLE == GTK_TOOLBAR_BOTH ]] && tbstylelist+="^"
  94. tbstylelist+="Text below icons"!
  95. [[ $TBSTYLE == GTK_TOOLBAR_BOTH_HORIZ ]] && tbstylelist+="^"
  96. tbstylelist+="Text beside icons"
  97.  
  98. # create list of toolbar icons sizes
  99. tbiconsizelist="Menu"!
  100. [[ $TBSTYLE == GTK_ICON_SIZE_SMALL_TOOLBAR ]] && tbiconsizelist+="^"
  101. tbiconsizelist+="Small toolbar"!
  102. [[ $TBSTYLE == GTK_ICON_SIZE_LARGE_TOOLBAR ]] && tbiconsizelist+="^"
  103. tbiconsizelist+="Large toolbar"!
  104. [[ $TBSTYLE == GTK_ICON_SIZE_BUTTON ]] && tbiconsizelist+="^"
  105. tbiconsizelist+="Buttons"!
  106. [[ $TBSTYLE == GTK_ICON_SIZE_DND ]] && tbiconsizelist+="^"
  107. tbiconsizelist+="DND"!
  108. [[ $TBSTYLE == GTK_ICON_SIZE_DIALOG ]] && tbiconsizelist+="^"
  109. tbiconsizelist+="Dialog"
  110.  
  111. # theme page
  112. $YAD --plug=$KEY --tabnum=1 --form --separator='\n' --quoted-output \
  113. --field="GTK+ theme::cb" "$themelist" \
  114. --field="GTK+ key theme::cb" "$keythemelist" \
  115. --field="Icons theme::cb" "$iconthemelist" \
  116. --field="Cursor theme::cb" "$cursorthemelist" \
  117. --field="Toolbar style::cb" "$tbstylelist" \
  118. --field="Toolbar icon size::cb" "$tbiconsizelist" \
  119. --field="Button images:chk" "$BUTTONIMAGE" \
  120. --field="Menu images:chk" "$MENUIMAGE" > $res1 &
  121.  
  122. # create list of hinting styles
  123. hintstylelist="None"!
  124. [[ $HINTSTYLE == hintslight ]] && hintstylelist+="^"
  125. hintstylelist+="Slight"!
  126. [[ $HINTSTYLE == hintmedium ]] && hintstylelist+="^"
  127. hintstylelist+="Medium"!
  128. [[ $HINTSTYLE == hintfull ]] && hintstylelist+="^"
  129. hintstylelist+="Full"
  130.  
  131. # create list of rgba types
  132. rgbalist="None"!
  133. [[ $RGBA == rgb ]] && rgbalist+="^"
  134. rgbalist+="RGB"!
  135. [[ $RGBA == gbr ]] && rgbalist+="^"
  136. rgbalist+="BGR"!
  137. [[ $RGBA == vrgb ]] && rgbalist+="^"
  138. rgbalist+="VRGB"!
  139. [[ $RGBA == vgbr ]] && rgbalist+="^"
  140. rgbalist+="VBGR"
  141.  
  142. # fonts page
  143. $YAD --plug=$KEY --tabnum=2 --form --separator='\n' --quoted-output \
  144. --field="Font::fn" "$FONTDESCR" --field=":lbl" "" \
  145. --field="Use antialiasing:chk" "$ANTIALIASING" \
  146. --field="Use hinting:chk" "$HINTING" \
  147. --field="Hinting style::cb" "$hintstylelist" \
  148. --field="RGBA type::cb" "$rgbalist" > $res2 &
  149.  
  150. # parse color scheme
  151. eval $(echo -e $COLORSCHEME | tr ';' '\n' | sed -r 's/:(.*)$/="\1"/')
  152.  
  153. # colors page
  154. $YAD --plug=$KEY --tabnum=3 --form --separator='\n' --quoted-output \
  155. --field="Foreground::clr" $fg_color \
  156. --field="Background::clr" $bg_color \
  157. --field="Text::clr" $text_color \
  158. --field="Base::clr" $base_color \
  159. --field="Selected fore::clr" $selected_fg_color \
  160. --field="Selected back::clr" $selected_bg_color \
  161. --field="Tooltip fore::clr" $tooltip_fg_color \
  162. --field="Tooltip back::clr" $tooltip_bg_color > $res3 &
  163.  
  164. # run main dialog
  165. $YAD --notebook --key=$KEY --tab="Theme" --tab="Fonts" --tab="Colors" \
  166. --title="Interface settings" --image=gnome-settings-theme \
  167. --width=400 --image-on-top --text="Common interface settings"
  168.  
  169. # recreate rc file
  170. if [[ $? -eq 0 ]]; then
  171. eval TAB1=($(< $res1))
  172. eval TAB2=($(< $res2))
  173. eval TAB3=($(< $res3))
  174.  
  175. echo -e "\n# This file was generated automatically\n" > $rc_file
  176.  
  177. echo "gtk-theme-name = \"${TAB1[0]}\"" >> $rc_file
  178. [[ ${TAB1[1]} != Default ]] && echo "gtk-key-theme-name = \"${TAB1[1]}\"" >> $rc_file
  179. [[ ${TAB1[2]} != Default ]] && echo "gtk-icon-theme-name = \"${TAB1[2]}\"" >> $rc_file
  180. [[ ${TAB1[3]} != Default ]] && echo "gtk-cursor-theme-name = \"${TAB1[3]}\"" >> $rc_file
  181. echo >> $rc_file
  182.  
  183. case ${TAB1[4]} in
  184. "Icons only") echo "gtk-toolbar-style = GTK_TOOLBAR_ICONS" >> $rc_file ;;
  185. "Text only") echo "gtk-toolbar-style = GTK_TOOLBAR_TEXT" >> $rc_file ;;
  186. "Text below icons") echo "gtk-toolbar-style = GTK_TOOLBAR_BOTH" >> $rc_file ;;
  187. "Text beside icons") echo "gtk-toolbar-style = GTK_TOOLBAR_BOTH_HORIZ" >> $rc_file ;;
  188. esac
  189. case ${TAB1[5]} in
  190. "Menu") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_MENU" >> $rc_file ;;
  191. "Small toolbar") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_SMALL_TOOLBAR" >> $rc_file ;;
  192. "Large toolbar") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_LARGE_TOOLBAR" >> $rc_file ;;
  193. "Buttons") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_BUTTON" >> $rc_file ;;
  194. "DND") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_DND" >> $rc_file ;;
  195. "Dialog") echo "gtk-toolbar-icon-size = GTK_ICON_SIZE_DIALOG" >> $rc_file ;;
  196. esac
  197. echo >> $rc_file
  198.  
  199. echo -n "gtk-button-images = " >> $rc_file
  200. [[ ${TAB1[6]} == TRUE ]] && echo 1 >> $rc_file || echo 0 >> $rc_file
  201. echo -n "gtk-menu-images = " >> $rc_file
  202. [[ ${TAB1[7]} == TRUE ]] && echo 1 >> $rc_file || echo 0 >> $rc_file
  203. echo >> $rc_file
  204.  
  205. echo -e "gtk-font-name = \"${TAB2[0]}\"\n" >> $rc_file
  206.  
  207. echo -n "gtk-xft-antialiasing = " >> $rc_file
  208. [[ ${TAB2[2]} == TRUE ]] && echo 1 >> $rc_file || echo 0 >> $rc_file
  209. echo -n "gtk-xft-hinting = " >> $rc_file
  210. [[ ${TAB2[3]} == TRUE ]] && echo 1 >> $rc_file || echo 0 >> $rc_file
  211. if [[ ${TAB2[4]} != $"None" ]]; then
  212. case ${TAB2[4]} in
  213. "Slight") echo 'gtk-xft-hintstyle = "hintslight"' >> $rc_file ;;
  214. "Medium") echo 'gtk-xft-hintstyle = "hintmedium"' >> $rc_file ;;
  215. "Full") echo 'gtk-xft-hintstyle = "hintful"' >> $rc_file ;;
  216. esac
  217. fi
  218. if [[ ${TAB2[5]} != $"None" ]]; then
  219. case ${TAB2[5]} in
  220. "RGB") echo 'gtk-xft-rgba = "rgb"' >> $rc_file ;;
  221. "BGR") echo 'gtk-xft-rgba = "bgr"' >> $rc_file ;;
  222. "VRGB") echo 'gtk-xft-rgba = "vrgb"' >> $rc_file ;;
  223. "VBGR") echo 'gtk-xft-rgba = "vbgr"' >> $rc_file ;;
  224. esac
  225. fi
  226. echo >> $rc_file
  227.  
  228. if [ -z ${COLORSCHEME+x} ]
  229. then
  230. echo "COLORSCHEME is unset"
  231. yad --image "dialog-question" --title "Alert" \
  232. --button=gtk-yes:0 --button=gtk-no:1 --text "Do you really want to screw up your color scheme ?!"
  233. ret=$?
  234. [[ $ret -eq 1 ]] && echo "include \"$rc_file.mine\"" >> $rc_file
  235. if [[ $ret -eq 0 ]]; then
  236. echo sucker
  237. echo "gtk-color-scheme = \"fg_color:${TAB3[0]};bg_color:${TAB3[1]};text_color:${TAB3[2]};base_color:${TAB3[3]};selected_fg_color:${TAB3[4]};selected_bg_color:${TAB3[5]};tooltip_fg_color:${TAB3[6]};tooltip_bg_color:${TAB3[7]}\"" >> $rc_file
  238. echo 'style "custom" = "default"' >> $rc_file
  239. echo "{" >> $rc_file
  240. echo "bg[NORMAL] = \"${TAB3[1]}\"" >> $rc_file
  241. echo "fg[NORMAL] = \"${TAB3[0]}\"" >> $rc_file
  242. echo "text[NORMAL] = \"${TAB3[2]}\"" >> $rc_file
  243. echo "base[NORMAL] = \"${TAB3[3]}\"" >> $rc_file
  244. echo "fg[SELECTED] = \"${TAB3[4]}\"" >> $rc_file
  245. echo "bg[SELECTED] = \"${TAB3[5]}\"" >> $rc_file
  246. echo "}" >> $rc_file
  247.  
  248. echo "class \"GtkWidget\" style \"custom\"" >> $rc_file
  249.  
  250. echo "include \"$rc_file.mine\"" >> $rc_file
  251.  
  252. fi
  253. else
  254. echo "var is set to '$COLORSCHEME'"
  255. yad --image "dialog-question" --title "Alert" \
  256. --button=gtk-yes:0 --button=gtk-no:1 --text "Do you want to save your custom colors ?"
  257. ret=$?
  258. [[ $ret -eq 1 ]] && echo "include \"$rc_file.mine\"" >> $rc_file
  259. if [[ $ret -eq 0 ]]; then
  260.  
  261. echo "gtk-color-scheme = \"fg_color:${TAB3[0]};bg_color:${TAB3[1]};text_color:${TAB3[2]};base_color:${TAB3[3]};selected_fg_color:${TAB3[4]};selected_bg_color:${TAB3[5]};tooltip_fg_color:${TAB3[6]};tooltip_bg_color:${TAB3[7]}\"" >> $rc_file
  262. echo 'style "custom" = "default"' >> $rc_file
  263. echo "{" >> $rc_file
  264. echo "bg[NORMAL] = \"${TAB3[1]}\"" >> $rc_file
  265. echo "fg[NORMAL] = \"${TAB3[0]}\"" >> $rc_file
  266. echo "text[NORMAL] = \"${TAB3[2]}\"" >> $rc_file
  267. echo "base[NORMAL] = \"${TAB3[3]}\"" >> $rc_file
  268. echo "fg[SELECTED] = \"${TAB3[4]}\"" >> $rc_file
  269. echo "bg[SELECTED] = \"${TAB3[5]}\"" >> $rc_file
  270. echo "}" >> $rc_file
  271.  
  272. echo "class \"GtkWidget\" style \"custom\"" >> $rc_file
  273.  
  274. echo "include \"$rc_file.mine\"" >> $rc_file
  275.  
  276. fi
  277. fi
  278.  
  279.  
  280. #echo "gtk-color-scheme = \"fg_color:${TAB3[0]};bg_color:${TAB3[1]};text_color:${TAB3[2]};base_color:${TAB3[3]};selected_fg_color:${TAB3[4]};selected_bg_color:${TAB3[5]};tooltip_fg_color:${TAB3[6]};tooltip_bg_color:${TAB3[7]}\"" >> $rc_file
  281. #echo 'style "custom" = "default"' >> $rc_file
  282. #echo "{" >> $rc_file
  283. #echo "bg[NORMAL] = \"${TAB3[1]}\"" >> $rc_file
  284. #echo "fg[NORMAL] = \"${TAB3[0]}\"" >> $rc_file
  285. #echo "text[NORMAL] = \"${TAB3[2]}\"" >> $rc_file
  286. #echo "base[NORMAL] = \"${TAB3[3]}\"" >> $rc_file
  287. #echo "fg[SELECTED] = \"${TAB3[4]}\"" >> $rc_file
  288. #echo "bg[SELECTED] = \"${TAB3[5]}\"" >> $rc_file
  289. #echo "}" >> $rc_file
  290.  
  291. # echo "class \"GtkWidget\" style \"custom\"" >> $rc_file
  292.  
  293.  
  294. echo ${TAB3[1]}
  295.  
  296.  
  297.  
  298.  
  299. #echo "include \"$rc_file.mine\"" >> $rc_file
  300.  
  301. fi
  302.  
  303. # cleanup
  304. rm -f $res1 $res2 $res3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement