Created
February 7, 2015 19:45
-
-
Save ahausmann/a3370c077f65990f183c to your computer and use it in GitHub Desktop.
Bash script to update cursor settings in X database, gtk2 and gtk3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Identifies which source contains the values that should be applied to all other sources | |
# | |
# Valid values: | |
# gtk3 GTK3 configuration / dconf | |
# Supports cursor theme and size | |
# gtk2 GTK2 configuration (uses gconftool-2) | |
# Supports cursor theme and size | |
# xdefaults Reads values from ~/.Xdefaults | |
# Supports only cursor theme, size will be the default | |
read_from="gtk3" | |
# If this value is 1 the X server database will be updated | |
update_xrdb="1" | |
# If this value is 1 the gtk2 settings will be updated | |
update_gtk2="1" | |
# If this value is 1 the gtk3 settings will be updated | |
update_gtk3="1" | |
# default values | |
cursor="" | |
cursor_size="32" | |
# | |
# Support functions | |
# | |
# Replace a line in a file | |
function updfile(){ | |
file=$1 | |
remove=$2 | |
add=$3 | |
content=$(cat $file|grep -v $remove) | |
echo -e "$content\n$add" > $file | |
} | |
# | |
# Main script | |
# | |
# read current values | |
case $read_from in | |
"gtk3") | |
cursor=$(gsettings get org.gnome.desktop.interface cursor-theme|tr -d "'") | |
cursor_size=$(gsettings get org.gnome.desktop.interface cursor-size|tr -d "'") | |
;; | |
"gtk2") | |
cursor=$(gconftool-2 -g /desktop/gnome/peripherals/mouse/cursor_theme) | |
cursor_size=$(gconftool-2 -g /desktop/gnome/peripherals/mouse/cursor_size) | |
;; | |
"xdefaults") | |
;; | |
"*") | |
echo "Unknown source $read_from. Please choose a valid value." | |
exit 1 | |
;; | |
esac | |
# Apply value to all targets, if possible | |
if [ \( -n $(which xrdb) \) -a \( $update_xrdb = "1" \) ]; then | |
echo "updating xrdb settings" | |
updfile .Xdefaults Xcursor.theme "Xcursor.theme: $cursor" | |
xrdb -merge .Xdefaults | |
fi | |
if [ \( -n $(which gconftool-2) \) -a \( $update_gtk2 = "1" \) ]; then | |
echo "updating gtk2 settings" | |
gconftool-2 --type string -s /desktop/gnome/peripherals/mouse/cursor_theme $cursor | |
gconftool-2 --type int -s /desktop/gnome/peripherals/mouse/cursor_size $cursor_size | |
fi | |
if [ \( -n $(which gsettings) \) -a \( $update_gtk3 = "1" \) ]; then | |
echo "updating gtk3 settings" | |
gsettings set org.gnome.desktop.interface cursor-theme $cursor | |
gsettings set org.gnome.desktop.interface cursor-size $cursor_size | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment