#!/bin/bash DESTDIR=${DESTDIR:-/} colors=(Brave Dust Human Illustrious Noble Wine Wise) properties=(bg fg base text selected_bg selected_fg tooltip_bg tooltip_fg frame inactive_frame menubar_bg menubar_fg menuitem_fg) common_bg=#d8d8d8 common_fg=#101010 common_base=#ffffff common_text=#1a1a1a common_menubar_bg=#212121 common_menubar_fg=#cecece common_menuitem_fg=#ffffff Dust_menubar_bg=#27241F Brave_selected_bg=#729fcf Dust_selected_bg=#b49372 Human_selected_bg=#f7a145 Illustrious_selected_bg=#f08290 Noble_selected_bg=#ad7fa8 Wine_selected_bg=#de4e4e Wise_selected_bg=#97bf60 common_selected_fg=#ffffff common_tooltip_bg=#f5f5b5 common_tooltip_fg=#000000 common_frame=#333333 common_inactive_frame=#333333 shopt -s globstar dotglob extglob #sed() { # [[ "$debug" == true ]] && echo "sed $@" # command sed "$@" #} debug() { [[ "$debug" ]] && echo "$@" } install_plank_theme() { [[ ! -d "$1" ]] && mkdir -p "$1" plank_dir="$1" shift cp -vr "$@" "$plank_dir" } install_theme() { check_for_zuki check_for_generated for color in ${colors[@]};do if [[ -d "Shiki-$color" ]];then printf "Installing \"Shiki-$color\"" if [[ "$user_install" ]];then printf "...\n" cp -r "Shiki-$color/" "$DESTDIR$HOME/.themes" else echo " system-wide..." mkdir -p "$DESTDIR/usr/share/themes/" cp -vr "$PWD/Shiki-$color/" "$DESTDIR/usr/share/themes/" fi else generate_theme "$color" fi done if [[ "$user_install" ]];then echo "Installing Xfwm themes..." cp -vr Shiki-*-Xfwm/ "$DESTDIR$HOME/.themes" echo "Installing Openbox themes..." cp -vr Shiki-*-Openbox/ "$DESTDIR$HOME/.themes" echo "Installing Plank themes..." install_plank_theme "$DESTDIR$HOME/.local/share/plank/themes/" ./plank/* else echo "Installing Xfwm themes system-wide..." mkdir -p "$DESTDIR/usr/share/themes/" cp -vr "$PWD"/Shiki-*-Xfwm/ "$DESTDIR/usr/share/themes/" echo "Installing Openbox themes system-wide..." cp -vr "$PWD"/Shiki-*-Openbox/ "$DESTDIR/usr/share/themes/" echo "Installing Plank themes system-wide..." install_plank_theme "$DESTDIR/usr/share/plank/themes/" ./plank/* fi printf '\n' } uninstall_theme() { printf "Uninstalling..." for color in ${colors[@]};do printf " \"Shiki-$color\"" [[ ! -z "$user_uninstall" ]] && rm -rf "$DESTDIR$HOME/.themes/Shiki-$color/" [[ -z "$user_uninstall" ]] && rm -rf "$DESTDIR/usr/share/themes/Shiki-$color/" done echo "Uninstalling Xfwm themes..." [[ ! -z "$user_uninstall" ]] && rm -vr "$DESTDIR$HOME/.themes/"Shiki-*-Xfwm/ [[ -z "$user_uninstall" ]] &&rm -vr "$DESTDIR/usr/share/themes/"Shiki-*-Xfwm/ echo "Uninstalling Openbox themes..." [[ ! -z "$user_uninstall" ]] && rm -vr "$DESTDIR$HOME/.themes/"Shiki-*-Openbox/ [[ -z "$user_uninstall" ]] && rm -vr "$DESTDIR/usr/share/themes/"Shiki-*-Openbox/ printf '\nUninstalling Plank themes...' for theme in plank/*;do theme=$(basename "$theme") printf " \"$theme\"" [[ ! -z "$user_uninstall" ]] && rm -rf "$DESTDIR$HOME/.local/share/plank/themes/$theme" [[ -z "$user_uninstall" ]] && rm -rf "$DESTDIR/usr/share/plank/themes/$theme" done printf '\n\n' } fix_line_endings() { printf "Correcting line endings..." for file in $@;do printf " \"$(basename $file)\"" sed -i.bak 's/\r//' "$file" done printf '\n\n' } patch() { if [[ "$debug" ]];then command patch --verbose "$@" else command patch "$@" fi } patch_theme() { check_for_zuki echo "Patching zuki-themes..." echo "If these files were already patched before, you'll see errors. Ignore them." cd zuki-themes echo "Resetting zuki-themes git repo..." git reset --hard HEAD cd "$OLDPWD" fix_line_endings "./zuki-themes/Zukitwo/gtk-2.0/widgets/panel.rc" "./zuki-themes/Zukitwo/gtk-2.0/gtkrc" "./Shiki-Colors-common/patches/panel.rc.patch" "./Shiki-Colors-common/patches/enable-dark-menubar.patch" yes | patch ./zuki-themes/Zukitwo/gtk-2.0/widgets/panel.rc <./Shiki-Colors-common/patches/panel.rc.patch yes | patch ./zuki-themes/Zukitwo/gtk-2.0/gtkrc <./Shiki-Colors-common/patches/enable-dark-menubar.patch for zuki_theme in ./zuki-themes/*/;do pushd "$zuki_theme/" >/dev/null 2>&1 echo "Removing xfwm4 theme in \"$zuki_theme\"..." rm -rf "xfwm4" popd >/dev/null 2>&1 done OLDIFS="$IFS" IFS=$'\n' for file in $(find ./zuki-themes/ -type f);do sed -i 's/gtk_color_scheme = ./gtk_color_scheme = \"menubar_bg_color:#ffffff\\nmenubar_fg_color:#ffffff\\nmenuitem_fg_color:#ffffff\\n/g' "$file" done printf "\n" IFS="$OLDIFS" OLDIFS= } generate_theme() { color="$1" cp -r "zuki-themes/Zukitwo" "Shiki-$color" echo "Removing xfwm4 theme in \"Shiki-$color\"..." rm -rf "Shiki-$color/xfwm4" cd "Shiki-$color" echo "Creating \"Shiki-$color\"..." file_list=$(find . -type f | grep -v 'make-colors-themes') for property in ${properties[@]};do property_var_name=\$${color}_$property property_var_contents=$(echo \$${color}_bg) if [[ -z "$(eval echo $property_var_name)" ]];then debug " There is no \"$property_var_name\", so we'll just use \"\$common_$property\"" property_var_contents=$(eval echo \$common_$property) else debug " Using \"$property_var_name\"" property_var_contents="$(eval echo $property_var_name)" fi OLDIFS="$IFS" IFS=$'\n' property_var_contents=$(echo "$property_var_contents" | sed 's/\#/\\\#/g') for file in ${file_list};do sed -i "s/${property}_color:\#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]/${property}_color:$property_var_contents/g;s/theme_${property}_color \#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]/theme_${property}_color $property_var_contents/g;s/Zukitwo/Shiki-$color/g;s/define-color theme_${property}_color .*\;/define-color theme_${property}_color $property_var_contents\;/g" "$file" 2>/dev/null >/dev/null done IFS="$OLDIFS" done #rm -rf "xfwm4" cp -vr ../Shiki-Colors-common/* ./ cd "$OLDPWD" } update() { git submodule deinit -f zuki-themes/ git submodule init zuki-themes/ git submodule update -f zuki-themes/ echo "Resetting zuki-themes tree..." git submodule deinit -f zuki-themes/ git submodule init zuki-themes/ echo "Getting latest revision of zuki-themes..." git submodule update -f -- zuki-themes/ cd "$OLDPWD" printf '\n' } clean() { printf "Removing..." for color in ${colors[@]};do printf " \"Shiki-$color/\"" rm -rf "Shiki-$color/" done printf '\n\n' } help() { echo "make-colors-themes - create Shiki-Colors themes" echo "usage: make-colors-themes [actions]" echo echo "arguments:" echo " generate - just generate the theme" echo " install - install the theme system-wide" echo " user-install - install the theme in your ~/.themes directory" echo " uninstall - uninstall the theme" echo " user-uninstall - uninstall the theme from the ~/.themes directory" echo " clean - delete old generated files" echo " patch - patch zuki-themes file" echo " update - update the local copy of the zuki-themes repo" echo " debug - activate debug messages" echo " help - display this message" echo echo "edit the \$colors variables in the script if you'd like to only generate certain colors" echo exit } command_not_found() { echo "make-colors-themes: \`$command\` is not a valid command" } generate_themes() { check_for_zuki generate=true for theme in ${colors[@]};do generate_theme $theme done printf "Now, type \`$0 install\` or \`$0 user_install\` to install.\n" } check_for_zuki() { if [[ ! -d "zuki-themes/Zukitwo" ]];then update fi } check_for_generated() { local color= for color in ${colors[@]};do if [[ ! -d "Shiki-$color/" ]];then generate_theme "$color" fi done } if [[ "$1" ]];then while [[ "$1" ]];do [[ "$1" == "generate" ]] && generate=true && generate_themes [[ "$1" == "install" ]] && install=true && install_theme [[ "$1" == "user-install" ]] && user_install=1 && install_theme [[ "$1" == "user-uninstall" ]] && user_uninstall=1 && uninstall_theme [[ "$1" == "update" ]] && update=true && update [[ "$1" == "uninstall" ]] && uninstall=true && uninstall_theme [[ "$1" == "clean" ]] && clean=true clean [[ "$1" == "patch" ]] && patch=true && patch_theme [[ "$1" == "debug" ]] && debug=true [[ "$1" == "help" ]] && help=true && help [[ ! "$help" && ! "$install" && ! "$user_install" && ! "$user_uninstall" && ! "$update" && ! "$uninstall" && ! "$clean" && ! "$patch" && ! "$debug" && ! "$generate" ]] && command_not_found=1 && command="$1" shift done else help fi