wok diff slim/stuff/slim-theme @ rev 16113

Up ranger (1.6.1)
author Paul Issott <paul@slitaz.org>
date Fri Mar 21 19:57:11 2014 +0000 (2014-03-21)
parents
children 05ce2fe60fcd
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/slim/stuff/slim-theme	Fri Mar 21 19:57:11 2014 +0000
     1.3 @@ -0,0 +1,135 @@
     1.4 +#/bin/sh
     1.5 +# slim-theme: manage SLiM themes
     1.6 +# Aleksej Bobylev <al.bobylev@gmail.com>, 2013
     1.7 +
     1.8 +ME=$(basename $0)
     1.9 +VERSION=20130525
    1.10 +CONF=/etc/slim.conf
    1.11 +
    1.12 +help()
    1.13 +{
    1.14 +	cat >&2 << EOT
    1.15 +$ME: Manage SLiM themes
    1.16 +
    1.17 +Usage: $ME OPTION [NAME]
    1.18 +
    1.19 +Options:
    1.20 +  -h       Display this short help and exit
    1.21 +  -l       List available themes (comma separated)
    1.22 +  -g       Get the name of current theme (note, it can be comma separated list)
    1.23 +  -s NAME  Set NAME theme as current; name of previous theme will be stored
    1.24 +           (note, you can set comma separated list for random theme behavior)
    1.25 +  -f NAME  Forget about NAME theme and return to previous used theme
    1.26 +  -V       Display information about $ME version
    1.27 +  -t       Translate current theme's strings according to global LANG value
    1.28 +           (note, its done auto when -s processed)
    1.29 +  -T LANG  Same as above, but use specified language
    1.30 +
    1.31 +Set option works like stack: you can "set" theme several times (every time you
    1.32 +install new SLiM theme). Use "forget" option at every theme uninstall to revert
    1.33 +to previous theme, if it was current.
    1.34 +EOT
    1.35 +	exit 0
    1.36 +}
    1.37 +
    1.38 +get_current()	awk '/current_theme/ { print $2 }' $CONF
    1.39 +get_prev()		awk '/previous_theme/ { print $2 }' $CONF
    1.40 +set_current()	sed -i 's|^current_theme .*$|current_theme       '$1'|' $CONF
    1.41 +set_prev()
    1.42 +{
    1.43 +	sed -i '/^previous_theme/d' $CONF
    1.44 +	[ x$1 != x ] && echo "previous_theme      $1" >> $CONF
    1.45 +}
    1.46 +find_theme()
    1.47 +{
    1.48 +	cd /usr/share/slim/themes
    1.49 +	theme=$(ls -Ad $1 2>/dev/null | head -n1)
    1.50 +	[ x$theme == x ] && echo "Theme \"$1\" not exist!" >&2 && exit 1
    1.51 +	echo $theme
    1.52 +}
    1.53 +i18n()
    1.54 +{
    1.55 +	lang=$1
    1.56 +	curr=$(get_current)
    1.57 +	strings=/usr/share/slim/themes/$curr/strings
    1.58 +	[ ! -e $strings ] && exit 0
    1.59 +	conf=/usr/share/slim/themes/$curr/slim.theme
    1.60 +	for str in welcome_msg username_msg password_msg; do
    1.61 +		# ll_CC.UTF-8@euro ; ll_CC.UTF-8 ; ll_CC ; ll ; en
    1.62 +		for langtry in $lang ${lang%@*} ${lang%\.*} ${lang%_*} en; do
    1.63 +			try="$(grep '^'${str:0:1}':'$langtry'	' $strings | cut -d'	' -f2)"
    1.64 +			[ x"$try" != x ] && break
    1.65 +		done
    1.66 +		sed -i 's|^\('$str'\).*$|\1             '"$try"'|' $conf
    1.67 +		echo "$str[$langtry]=$try" >&2
    1.68 +	done
    1.69 +}
    1.70 +
    1.71 +set_theme()
    1.72 +{
    1.73 +	theme=$(find_theme "$1")
    1.74 +	curr=$(get_current)
    1.75 +	prev=$(get_prev)
    1.76 +	if [ x$theme != x$curr ]; then
    1.77 +		echo "Set theme $theme" >&2
    1.78 +		[ x$prev != x ] && curr=$curr:$prev
    1.79 +		set_prev $curr
    1.80 +		set_current $theme
    1.81 +	else
    1.82 +		echo "Already set" >&2
    1.83 +	fi
    1.84 +
    1.85 +	i18n $LANG
    1.86 +	exit 0
    1.87 +}
    1.88 +
    1.89 +forget_theme()
    1.90 +{
    1.91 +	theme=$(find_theme "$1")
    1.92 +	curr=$(get_current)
    1.93 +	prev=$(get_prev)
    1.94 +	echo "Forget theme \"$theme\"" >&2
    1.95 +	if [ x$theme == x$curr ]; then
    1.96 +		last=$(echo $prev | cut -d: -f1); [ x$last == x ] && last=base
    1.97 +		rest=${prev#*:}; [ x$rest == x$prev ] && rest=
    1.98 +		prev=$rest; set_prev $prev
    1.99 +		echo "Back to \"$last\" theme" >&2
   1.100 +		set_current $last
   1.101 +	fi
   1.102 +	prev=$(echo $(echo $prev | tr ':' '\n' | sed "/$theme/d") | tr ' ' ':')
   1.103 +	set_prev $prev
   1.104 +
   1.105 +	exit 0
   1.106 +}
   1.107 +
   1.108 +
   1.109 +# parse only first option
   1.110 +getopts ":lgs:f:VhtT:" opt
   1.111 +case $opt in
   1.112 +	l)
   1.113 +		list=$(find /usr/share/slim/themes/*/slim.theme | sort | awk -F/ '{ print $6 }')
   1.114 +		echo $list | tr ' ' ','; exit 0 ;;
   1.115 +	g)
   1.116 +		get_current; exit 0 ;;
   1.117 +	s)
   1.118 +		set_theme "$OPTARG" ;;
   1.119 +	f)
   1.120 +		forget_theme "$OPTARG" ;;
   1.121 +	V)
   1.122 +		echo $VERSION; exit 0 ;;
   1.123 +	h)
   1.124 +		help; exit 0 ;;
   1.125 +	t)
   1.126 +		i18n $LANG; exit 0 ;;
   1.127 +	T)
   1.128 +		i18n $OPTARG; exit 0 ;;
   1.129 +	*)
   1.130 +		if [ x$OPTARG == xs -o x$OPTARG == xf -o x$OPTARG == xT ]; then
   1.131 +			echo "Option \"$OPTARG\" requires an argument."
   1.132 +		else
   1.133 +			[ x$OPTARG != x ] && echo "Illegal option \"$OPTARG\"."
   1.134 +		fi
   1.135 +		echo "$ME -h for help."; exit 1 ;;
   1.136 +esac
   1.137 +
   1.138 +help