Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gnumoksha committed Oct 29, 2014
2 parents 37629a6 + ceab3f6 commit d47e69e
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 227 deletions.
21 changes: 20 additions & 1 deletion README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Then you can run the installation script:

And just follow the instructions.

You can also run the `set_dark.sh` or `set_light.sh` script, to directly set
the dark or light solarized theme to the actived gnome-terminal profile.

Uninstall
---------

Expand All @@ -56,6 +59,22 @@ Be sure to have the dconf-cli package installed and do:
Replace PROFILE_ID by your profile ID (you can get it in your profile
configuration in gnome-terminal).

Themes
------

Each theme has is own folder in the `colors` dir. It contains 5 files:

* bd_color: bold color
* bg_color: background color
* fg_color: foreground color
* palette_dconf: palette for dconf (for gnome-terminal 3.8 or higher). Each
color is surrounded of simple quotes, and colors are comma separated.
* palette_gconf: palette for gconf (for gnome-terminal 3.6 or lower). Colors
are separated by colons.

No additional configuration is needed to add a theme, the installation script
just list at launch the children folders in the `colors` dir.

Contributors
------------

Expand Down Expand Up @@ -93,4 +112,4 @@ readme.
[Solarized homepage]: http://ethanschoonover.com/solarized
[Solarized repository]: https://github.com/altercation/solarized
[Gnome Terminal Colors Solarized repository]: https://github.com/sigurdga/gnome-terminal-colors-solarized
[dircolors]: https://github.com/seebi/dircolors-solarized
[dircolors solarised color theme]: https://github.com/seebi/dircolors-solarized
227 changes: 4 additions & 223 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@
#!/usr/bin/env bash

DIRCOLORS_DIR="$(echo ~/.dir_colors)"
DIRCOLORS_SOLARIZED="$(pwd)"
DIRCOLORS_REPO_ADRESS="https://github.com/seebi/dircolors-solarized"
DIRCOLORS_DL_ADRESS="https://raw.github.com/seebi/dircolors-solarized/master/"

dir=$(dirname $0)
gnomeVersion="$(expr "$(gnome-terminal --version)" : '.* \(.*[.].*[.].*\)$')"
dircolors_checked=false

# newGnome=1 if the gnome-terminal version >= 3.8
if [[ ("$(echo "$gnomeVersion" | cut -d"." -f1)" = "3" && \
"$(echo "$gnomeVersion" | cut -d"." -f2)" -ge 8) || \
"$(echo "$gnomeVersion" | cut -d"." -f1)" -ge 4 ]]
then newGnome="1"
dconfdir=/org/gnome/terminal/legacy/profiles:

else
newGnome=0
gconfdir=/apps/gnome-terminal/profiles
fi
dir=$(dirname "$0")

declare -a schemes
schemes=($(cd $dir/colors && echo * && cd - > /dev/null))

declare -a profiles
if [ "$newGnome" = "1" ]
then profiles=($(dconf list $dconfdir/ | grep ^: | sed 's/\///g'))
else
profiles=($(gconftool-2 -R $gconfdir | grep $gconfdir | cut -d/ -f5 | \
cut -d: -f1))
fi

die() {
echo $1
exit ${2:-1}
}

in_array() {
local e
for e in "${@:2}"; do [[ $e == $1 ]] && return 0; done
return 1
}
source $dir/src/tools.sh
source $dir/src/profiles.sh
source $dir/src/dircolors.sh

show_help() {
echo
Expand All @@ -67,49 +32,6 @@ validate_scheme() {
in_array $scheme "${schemes[@]}" || die "$scheme is not a valid scheme" 2
}

create_new_profile() {
profile_id="$(uuidgen)"
dconf write $dconfdir/default "'$profile_id'"
dconf write $dconfdir/list "['$profile_id']"
profile_dir="$dconfdir/:$profile_id"
dconf write $profile_dir/visible-name "'Default'"
}

get_uuid() {
# Print the UUID linked to the profile name sent in parameter
local profile_name=$1
for i in ${!profiles[*]}
do
if [[ "$(dconf read $dconfdir/${profiles[i]}/visible-name)" == \
"'$profile_name'" ]]
then echo "${profiles[i]}"
return 0
fi
done
echo "$profile_name"
}

validate_profile() {
local profile=$1
in_array $profile "${profiles[@]}" || die "$profile is not a valid profile" 3
}

get_profile_name() {
local profile_name

# dconf still return "" when the key does not exist, gconftool-2 return 0,
# but it does priint error message to STDERR, and command substitution
# only gets STDOUT which means nothing at this point.
if [ "$newGnome" = "1" ]
then profile_name="$(dconf read $dconfdir/$1/visible-name | sed s/^\'// | \
sed s/\'$//)"
else
profile_name=$(gconftool-2 -g $gconfdir/$1/visible_name)
fi
[[ -z $profile_name ]] && die "$1 is not a valid profile" 3
echo $profile_name
}

set_profile_colors() {
local profile=$1
local scheme=$2
Expand Down Expand Up @@ -158,45 +80,6 @@ set_profile_colors() {
fi
}

dl_dircolors() {
echo
eval "wget -O "$DIRCOLORS_SOLARIZED/dircolors" \
"$DIRCOLORS_DL_ADRESS/dircolors.ansi-$scheme""
valid=$?
if [ ! "$valid" == "0" -o ! -e "$DIRCOLORS_SOLARIZED/dircolors" ]
then echo -e "Download failed, dircolors will not be copied but you "
echo -en "install it from the official repository : "
echo "$DIRCOLORS_REPO_ADRESS"
return 1
fi
return 0
}

copy_dicolors() {
if [ "$1" != 1 ]
then return
elif [ -f "$DIRCOLORS_DIR/dircolors" ]
eval dl_dircolors
dl_ok=$?
then if [ $dl_ok ]
then mv "$DIRCOLORS_DIR/dircolors" "$DIRCOLORS_DIR/dircolors.old"
echo -e "$DIRCOLORS_DIR/dircolors already exists, moving it as"
echo "dircolors.old"
fi
fi
cp "$DIRCOLORS_SOLARIZED/dircolors" "$DIRCOLORS_DIR/dircolors"
echo
echo "The new dircolors is copied as $DIRCOLORS_DIR/dircolors."
echo
echo "Add \"eval \`dircolors /path/to/dircolorsdb\`\" in your in your shell "
echo "configuration file (.bashrc, .zshrc, etc...) to use the new dircolors."
echo
echo -en "Do not forget to remove the old dircolors in your shell "
echo -en "configuration file if it was named differently than "
echo -en "\"dircolors\".\n"
echo
}

interactive_help() {
echo
echo -en "This script will ask you which color scheme you want, and which "
Expand All @@ -216,38 +99,6 @@ interactive_help() {
echo
}

interactive_dircolors() {
noselect=true
while $noselect
do
echo
echo -en "A dircolors already exists, but can be incompatible with the "
echo -en "solarized color scheme causing some colors problems when doing "
echo -en "a \"ls\".\n"
echo -e "\n"
echo -en "1) Replace the actual dircolors by the seebi' "
echo -en "dircolors-solarized :\n"
echo -en " https://github.com/seebi/dircolors-solarized (the actual "
echo -en "dircolors will be \nkeeped as backup).\n"
echo
echo -en "2) [DEFAULT] I am awared about this potentiall problem and will"
echo -en "check my \n dircolors (default path: ~/.dir_colors/dircolors) "
echo -en "in case of conflict.\n"
echo -e "\n"
read -p "Enter your choice : [2] " selection
selection=${selection:-2}

if [ "$selection" -gt 2 -o "$selection" -lt 1 ]
then echo "$selection is not a valid entry. Please Restart"
echo
noselect=true
else
noselect=false
fi
done
copy_dicolors $selection
}

interactive_select_scheme() {
echo "Please select a color scheme:"
select scheme
Expand All @@ -261,76 +112,6 @@ interactive_select_scheme() {
echo
}

interactive_new_profile() {
local confirmation

echo "No profile found"
echo "You need to create a new default profile to continue. Continue ?"
echo -n "(YES to continue) "

read confirmation
if [[ $(echo $confirmation | tr '[:lower:]' '[:upper:]') != YES ]]
then
die "ERROR: Confirmation failed -- ABORTING!"
fi

echo -e "Profile \"Default\" created\n"
}

check_empty_profile() {
if [ "$profiles" = "" ]
then interactive_new_profile
create_new_profile
profiles=($(dconf list $dconfdir/ | grep ^: | sed 's/\///g'))
fi
}

check_dircolors() {
nonempty=false
if [ -d "$DIRCOLORS_DIR" ]
then [ "$(ls -A $DIRCOLORS_DIR)" ] && nonempty=true || nonempty=false
fi
if [ $nonempty = true ]
then interactive_dircolors
fi
return $(! $nonempty)
}

warning_message_dircolors() {
echo -en "If there is any problem with the colors when doing a \"ls\", "
echo -en "please check your dircolors.\n"
}

interactive_select_profile() {
local profile_key
local profile_name
local profile_names
local profile_count=$#

declare -a profile_names
while [ $# -gt 0 ]
do
profile_names[$(($profile_count - $#))]=$(get_profile_name $1)
shift
done

set -- "${profile_names[@]}"

echo "Please select a Gnome Terminal profile:"
select profile_name
do
if [[ -z $profile_name ]]
then
die "ERROR: Invalid selection -- ABORTING!" 3
fi
profile_key=$(expr ${REPLY} - 1)
break
done
echo

profile=${profiles[$profile_key]}
}

interactive_confirm() {
local confirmation

Expand Down
7 changes: 4 additions & 3 deletions others/extract_base16.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ echo "You maybe want execute \"rm -Rf ../colors/base16-*\" before"
for f in $(ls $DIR/*.sh); do
file_name=$(basename "$f" .sh)
mkdir colors/$file_name 2> /dev/null
# search values
#FIXME extras seds
# '\'' match with a single quote
# Searching for values
# Note: '\'' match with a single quote
#FIXME to many sed's
#
# for dconf '',
dconf_palette=$(sed -rn 's/[ ]*dset palette \"\[{0,1}(.*)\]{0,1}\"/\1/p' $f | sed 's/\]//') && [[ -z "$dconf_palette" ]] && echo "$file_name: dconf palette not found"
dconf_bg_color=$(sed -rn 's/[ ]*dset background-color \"(.*)\"/\1/p' $f | sed 's/'\''//g') && [[ -z "$dconf_bg_color" ]] && echo "$file_name: dconf background-color not found"
Expand Down
4 changes: 4 additions & 0 deletions set_dark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

dir=`dirname "$0"`
source $dir/src/set_theme_default_profile.sh dark $1
4 changes: 4 additions & 0 deletions set_light.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

dir=`dirname "$0"`
source $dir/src/set_theme_default_profile.sh light $1
Loading

0 comments on commit d47e69e

Please sign in to comment.