Gogh/gogh.sh

403 lines
12 KiB
Bash
Raw Normal View History

2017-07-04 23:26:10 +03:00
#!/usr/bin/env bash
2018-11-22 16:30:40 +03:00
set -euxo pipefail
2017-07-04 23:26:10 +03:00
declare -a THEMES=(
2017-07-08 01:51:58 +03:00
'3024-day.sh'
'3024-night.sh'
2017-07-04 23:26:10 +03:00
'aci.sh'
'aco.sh'
2017-07-08 01:51:58 +03:00
'adventuretime.sh'
'afterglow.sh'
'alien-blood.sh'
'argonaut.sh'
'arthur.sh'
'atom.sh'
2017-07-04 23:26:10 +03:00
'azu.sh'
2017-07-08 01:51:58 +03:00
'belafonte-day.sh'
'belafonte-night.sh'
2017-07-04 23:26:10 +03:00
'bim.sh'
2017-07-08 01:51:58 +03:00
'birds-of-paradise.sh'
'blazer.sh'
'borland.sh'
'broadcast.sh'
'brogrammer.sh'
'c64.sh'
2017-07-04 23:26:10 +03:00
'cai.sh'
'chalk.sh'
2017-12-04 19:00:45 +03:00
'chalkboard.sh'
2017-07-08 01:51:58 +03:00
'ciapre.sh'
2018-02-26 23:55:18 +03:00
'clone-of-ubuntu.sh'
2017-07-08 01:51:58 +03:00
'clrs.sh'
'cobalt-neon.sh'
2017-12-04 19:00:45 +03:00
'cobalt2.sh'
2017-07-08 01:51:58 +03:00
'crayon-pony-fish.sh'
'dark-pastel.sh'
'darkside.sh'
'desert.sh'
'dimmed-monokai.sh'
2017-07-04 23:26:10 +03:00
'dracula.sh'
2017-07-08 01:51:58 +03:00
'earthsong.sh'
'elemental.sh'
2017-07-04 23:26:10 +03:00
'elementary.sh'
'elic.sh'
'elio.sh'
2017-07-08 01:51:58 +03:00
'espresso-libre.sh'
'espresso.sh'
'fishtank.sh'
2017-07-04 23:26:10 +03:00
'flat.sh'
2017-12-04 19:00:45 +03:00
'flatland.sh'
'foxnightly.sh'
2017-07-04 23:26:10 +03:00
'freya.sh'
2017-07-08 01:51:58 +03:00
'frontend-delight.sh'
'frontend-fun-forrest.sh'
'frontend-galaxy.sh'
'github.sh'
2018-11-06 02:00:17 +03:00
'google-dark.sh'
'google-light.sh'
2018-01-20 00:56:42 +03:00
'gooey.sh'
2017-07-08 01:51:58 +03:00
'grape.sh'
'grass.sh'
2017-07-04 23:26:10 +03:00
'gruvbox-dark.sh'
2017-07-08 01:51:58 +03:00
'gruvbox.sh'
'hardcore.sh'
'harper.sh'
2017-07-04 23:26:10 +03:00
'hemisu-dark.sh'
'hemisu-light.sh'
2017-07-08 01:51:58 +03:00
'highway.sh'
'hipster-green.sh'
'homebrew.sh'
'hurtado.sh'
2017-07-04 23:26:10 +03:00
'hybrid.sh'
2017-07-08 01:51:58 +03:00
'ic-green-ppl.sh'
'ic-orange-ppl.sh'
'idle-toes.sh'
2017-07-04 23:26:10 +03:00
'ir-black.sh'
2017-07-08 01:51:58 +03:00
'jackie-brown.sh'
'japanesque.sh'
'jellybeans.sh'
2017-07-04 23:26:10 +03:00
'jup.sh'
2017-07-08 01:51:58 +03:00
'kibble.sh'
'later-this-evening.sh'
'lavandula.sh'
'liquid-carbon-transparent.sh'
2017-12-04 19:00:45 +03:00
'liquid-carbon.sh'
2017-07-08 01:51:58 +03:00
'man-page.sh'
2017-07-04 23:26:10 +03:00
'mar.sh'
'material.sh'
2017-07-08 01:51:58 +03:00
'mathias.sh'
'medallion.sh'
'misterioso.sh'
2017-07-04 23:26:10 +03:00
'miu.sh'
2017-07-08 01:51:58 +03:00
'molokai.sh'
2017-12-27 20:12:48 +03:00
'mona-lisa.sh'
2017-07-04 23:26:10 +03:00
'monokai-dark.sh'
2017-07-08 01:51:58 +03:00
'monokai-soda.sh'
'n0tch2k.sh'
'neopolitan.sh'
2017-07-04 23:26:10 +03:00
'nep.sh'
2017-07-08 01:51:58 +03:00
'neutron.sh'
'nightlion-v1.sh'
'nightlion-v2.sh'
2018-10-17 00:39:41 +03:00
'nighty.sh'
2017-07-04 23:26:10 +03:00
'nord-light.sh'
'nord.sh'
2017-07-08 01:51:58 +03:00
'novel.sh'
'obsidian.sh'
2017-07-04 23:26:10 +03:00
'ocean-dark.sh'
2017-07-08 01:51:58 +03:00
'ocean.sh'
2017-12-04 19:00:45 +03:00
'oceanic-next.sh'
2017-07-08 01:51:58 +03:00
'ollie.sh'
2017-07-04 23:26:10 +03:00
'one-dark.sh'
2017-12-04 19:00:45 +03:00
'one-half-black.sh'
2017-07-04 23:26:10 +03:00
'one-light.sh'
'pali.sh'
2017-07-08 01:51:58 +03:00
'paraiso-dark.sh'
'paul-millr.sh'
'pencil-dark.sh'
'pencil-light.sh'
2017-07-04 23:26:10 +03:00
'peppermint.sh'
2017-07-08 01:51:58 +03:00
'pnevma.sh'
'pro.sh'
'red-alert.sh'
'red-sands.sh'
'rippedcasts.sh'
'royal.sh'
2017-07-04 23:26:10 +03:00
'sat.sh'
2017-07-08 01:51:58 +03:00
'sea-shells.sh'
2017-12-04 19:00:45 +03:00
'seafoam-pastel.sh'
2017-07-08 01:51:58 +03:00
'seti.sh'
'shaman.sh'
2017-07-04 23:26:10 +03:00
'shel.sh'
2017-07-08 01:51:58 +03:00
'slate.sh'
2017-07-04 23:26:10 +03:00
'smyck.sh'
2017-12-17 17:36:20 +03:00
'snazzy.sh'
2017-07-08 01:51:58 +03:00
'soft-server.sh'
'solarized-darcula.sh'
'solarized-dark-higher-contrast.sh'
2017-07-04 23:26:10 +03:00
'solarized-dark.sh'
'solarized-light.sh'
2017-07-08 01:51:58 +03:00
'spacedust.sh'
'spacegray-eighties-dull.sh'
'spacegray-eighties.sh'
'spacegray.sh'
'spring.sh'
'square.sh'
2017-12-04 19:00:45 +03:00
'srcery.sh'
2017-07-08 01:51:58 +03:00
'sundried.sh'
'symphonic.sh'
'teerb.sh'
'terminal-basic.sh'
'terminix-dark.sh'
'thayer-bright.sh'
2017-07-04 23:26:10 +03:00
'tin.sh'
'tomorrow-night-blue.sh'
'tomorrow-night-bright.sh'
'tomorrow-night-eighties.sh'
'tomorrow-night.sh'
'tomorrow.sh'
2017-07-08 01:51:58 +03:00
'toy-chest.sh'
'treehouse.sh'
'twilight.sh'
2017-07-04 23:26:10 +03:00
'ura.sh'
2017-07-08 01:51:58 +03:00
'urple.sh'
2017-07-04 23:26:10 +03:00
'vag.sh'
2017-07-08 01:51:58 +03:00
'vaughn.sh'
'vibrant-ink.sh'
'warm-neon.sh'
'wez.sh'
'wild-cherry.sh'
'wombat.sh'
'wryan.sh'
'zenburn.sh'
2017-07-04 23:26:10 +03:00
)
2018-11-13 20:51:25 +03:00
# Allow developer to change url to forked url for easier testing
BASE_URL=${BASE_URL:-"https://raw.githubusercontent.com/Mayccoll/Gogh/master"}
2018-11-05 13:28:42 +03:00
2017-12-27 19:59:05 +03:00
capitalize() {
local ARGUMENT=$1
local RES=""
2017-12-27 19:45:55 +03:00
local STR=""
local RES_NO_TRAIL_SPACE=""
2017-12-27 19:59:05 +03:00
for CHAR in $ARGUMENT
do
2017-12-27 19:59:05 +03:00
STR=$(echo "${CHAR:0:1}" | tr "[:lower:]" "[:upper:]")"${CHAR:1} "
2017-12-27 19:45:55 +03:00
RES="${RES}${STR}"
RES_NO_TRAIL_SPACE="$(echo -e "${RES}" | sed -e 's/[[:space:]]*$//')"
done
2017-12-27 19:45:55 +03:00
echo "${RES_NO_TRAIL_SPACE}"
}
2017-10-21 03:05:24 +03:00
2017-12-27 19:59:05 +03:00
set_gogh() {
2017-07-04 23:26:10 +03:00
string=$1
string_r="${string%???}"
string_s=${string_r//\./_}
result=$(capitalize "${string_s}")
2018-11-13 20:51:25 +03:00
url="${BASE_URL}/themes/$1"
2017-10-21 03:05:24 +03:00
2018-11-05 13:28:42 +03:00
export {PROFILE_NAME,PROFILE_SLUG}="$result"
# Evaluate if Gogh was called from local source - i.e cloned repo
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -e "$SCRIPT_PATH/themes/$1" ]; then
2018-11-22 02:16:21 +03:00
(eval "$SCRIPT_PATH/themes/$1")
else
2018-11-05 13:28:42 +03:00
if [ "$(uname)" = "Darwin" ]; then
# OSX ships with curl
2018-11-09 16:51:07 +03:00
(eval "$(curl -sLo- "${url}")")
2018-11-05 13:28:42 +03:00
else
2018-11-09 16:51:07 +03:00
# Linux ships with wget
(eval "$(wget -qO- "${url}")")
2018-11-05 13:28:42 +03:00
fi
fi
}
2018-11-13 20:51:25 +03:00
remove_file_extension (){
echo "${1%.*}"
2017-07-04 23:26:10 +03:00
}
2018-11-13 20:51:25 +03:00
2017-07-04 23:26:10 +03:00
### Get length of an array
ARRAYLENGTH=${#THEMES[@]}
NUM=1
2018-11-13 20:51:25 +03:00
2017-07-04 23:26:10 +03:00
# |
2018-11-13 20:51:25 +03:00
# | ::::::: Print logo
2017-07-04 23:26:10 +03:00
# |
2018-11-13 20:51:25 +03:00
tput clear
if [[ ${COLUMNS:-$(tput cols)} -ge 80 ]]; then
2018-11-22 02:16:21 +03:00
gogh_str=""
gogh_str+=" \n"
gogh_str+=" █████████ █████ \n"
gogh_str+=" ███ ███ ███ \n"
gogh_str+=" ███ ██████ ███████ ███████ \n"
gogh_str+=" ███ ███ ███ ███ ███ ███ ███ \n"
gogh_str+=" ███ █████ ███ ███ ███ ███ ███ ███ \n"
gogh_str+=" ███ ███ ███ ███ ███ ███ ███ ███ \n"
gogh_str+=" █████████ ██████ ███████ ████ █████ \n"
gogh_str+=" $(tput setaf 0)█████████$(tput setaf 1)█████████$(tput setaf 2)█████████$(tput setaf 3)█████████$(tput setaf 4)█████$(tput sgr 0)███$(tput setaf 4)$(tput setaf 5)█████████$(tput setaf 6)█████████$(tput setaf 7)█████████ \n"
gogh_str+=" $(tput setaf 0)█████████$(tput setaf 1)█████████$(tput setaf 2)█████████$(tput setaf 3)█████████$(tput sgr 0)███$(tput setaf 4)██$(tput sgr 0)███$(tput setaf 4)$(tput setaf 5)█████████$(tput setaf 6)█████████$(tput setaf 7)█████████ \n"
gogh_str+=" $(tput setaf 0)█████████$(tput setaf 1)█████████$(tput setaf 2)█████████$(tput setaf 3)█████████$(tput setaf 4)$(tput sgr0)██████$(tput setaf 4)██$(tput setaf 5)█████████$(tput setaf 6)█████████$(tput setaf 7)█████████ \n"
gogh_str+=" $(tput setaf 8)█████████$(tput setaf 9)█████████$(tput setaf 10)█████████$(tput setaf 11)█████████$(tput setaf 12)█████████$(tput setaf 13)█████████$(tput setaf 14)█████████$(tput setaf 15)█████████$(tput sgr 0) \n"
gogh_str+=" $(tput setaf 8)█████████$(tput setaf 9)█████████$(tput setaf 10)█████████$(tput setaf 11)█████████$(tput setaf 12)█████████$(tput setaf 13)█████████$(tput setaf 14)█████████$(tput setaf 15)█████████$(tput sgr 0) \n"
gogh_str+=" $(tput setaf 8)█████████$(tput setaf 9)█████████$(tput setaf 10)█████████$(tput setaf 11)█████████$(tput setaf 12)█████████$(tput setaf 13)█████████$(tput setaf 14)█████████$(tput setaf 15)█████████$(tput sgr 0) \n"
gogh_str+=" "
echo -e "${gogh_str}"
#sleep 2.5
2018-11-13 20:51:25 +03:00
else
echo -e "\nGogh\n"
for c in {0..15}; do
echo -n "$(tput setaf $c)█████$(tput sgr0)"
[[ $c == 7 ]] && echo # new line
done
echo
fi
2017-07-04 23:26:10 +03:00
# |
# | ::::::: Print Themes
# |
echo -e "\nThemes:\n"
2017-07-04 23:26:10 +03:00
for TH in "${THEMES[@]}"; do
KEY=$(printf "%02d" $NUM)
2017-08-31 17:35:37 +03:00
FILENAME=${TH::$((${#TH}-3))}
2017-12-27 19:45:55 +03:00
FILENAME_SPACE=${FILENAME//-/ }
2017-07-04 23:26:10 +03:00
2018-11-13 20:51:25 +03:00
echo -e " ($(tput setaf 4) $KEY $(tput sgr0)) $(capitalize "${FILENAME_SPACE}")"
2017-07-04 23:26:10 +03:00
((NUM++))
done
2018-11-13 20:51:25 +03:00
echo -e " ($(tput setaf 4) ALL $(tput sgr0)) All themes"
2017-07-04 23:26:10 +03:00
# |
# | ::::::: Select Option
# |
2018-11-13 20:51:25 +03:00
echo -e "\nUsage : Enter Desired Themes Numbers ($(tput setaf 4)OPTIONS$(tput sgr0)) Separated By A Blank Space"
echo -e " Press $(tput setaf 4)ENTER$(tput sgr0) without options to Exit\n"
2018-11-05 13:28:42 +03:00
read -r -p 'Enter OPTION(S) : ' -a OPTION
2017-07-04 23:26:10 +03:00
2018-11-13 20:51:25 +03:00
# Automagically generate options if user opts for all themes
[[ "$OPTION" == ALL ]] && OPTION=($(seq -s " " $ARRAYLENGTH))
2017-07-04 23:26:10 +03:00
2018-11-05 13:28:42 +03:00
# |
# | ::::::: Get terminal
# |
2018-11-22 02:16:21 +03:00
if [[ -z "${TERMINAL:-}" ]]; then
# |
# | Check for the terminal name (depening on os)
# | ===========================================
OS="$(uname)"
if [ "$OS" = "Darwin" ]; then
TERMINAL=$TERM_PROGRAM
elif [ "${OS#CYGWIN}" != "${OS}" ]; then
TERMINAL="mintty"
else
# |
# | Depending on how the script was invoked, we need
# | to loop until pid is no longer a subshell
# | ===========================================
pid="$$"
2018-11-05 13:28:42 +03:00
TERMINAL="$(ps -h -o comm -p $pid)"
2018-11-22 02:16:21 +03:00
while [[ "${TERMINAL:(-2)}" == "sh" ]]; do
pid="$(ps -h -o ppid -p $pid)"
TERMINAL="$(ps -h -o comm -p $pid)"
done
fi
2018-11-05 13:28:42 +03:00
fi
2018-11-13 20:51:25 +03:00
# |
# | ::::::: Fancy progressbar for lengthy operations
# |
if [[ ${#OPTION[@]} -gt 5 ]]; then
if [ "$(uname)" = "Darwin" ]; then
eval "$(curl -sLo- "https://git.io/progressbar")" 2> /dev/null
else
eval "$(wget -qO- "https://git.io/progressbar")" 2> /dev/null
fi
fi
2018-11-05 13:28:42 +03:00
# |
# | Tilix supports fg/bg in color schemes - ask wether user wants to go that route
# | This is to avoid creating multiple profiles just for colors
# | ===========================================
2018-11-13 20:51:25 +03:00
if [[ "$TERMINAL" = "tilix" ]] && [[ ${#OPTION[@]} -gt 0 ]]; then
2018-11-05 13:28:42 +03:00
echo
read -r -p "Tilix detected - use color schemes instead of profiles? [y/N] " -n 1 TILIX_RES
echo
2018-11-13 20:51:25 +03:00
# |
# | When selecting multiple themes and user opts for color schemes, we save all themes
# | in a tmpdir and copy the files once all themes has been processed.. If a user
# | desides to abort before all themes has been processed this section will cleanup the tmpdir
# | =======================================
if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then
cleanup() {
echo
echo "Cleaning up"
rm -rf "$scratchdir"
unset LOOP OPTLENGTH
echo "Done..."
exit 0
}
2018-11-05 13:28:42 +03:00
2018-11-13 20:51:25 +03:00
scratchdir=$(mktemp -d -t tmp.XXXXXXXX)
export scratchdir
trap 'cleanup; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
fi
2018-11-06 02:00:17 +03:00
fi
2018-11-13 20:51:25 +03:00
2018-11-05 13:28:42 +03:00
# |
# | ::::::: Export one-off variables
# |
2018-11-07 01:46:42 +03:00
[[ -n "${TILIX_RES:-}" ]] && export TILIX_RES
2018-11-06 02:00:17 +03:00
export TERMINAL LOOP OPTLENGTH=${#OPTION[@]}
2018-11-05 13:28:42 +03:00
2018-11-13 20:51:25 +03:00
2017-07-04 23:26:10 +03:00
# |
# | ::::::: Apply Theme
# |
2018-11-05 13:28:42 +03:00
# Note:
# Constants with a leading 0 are interpreted as octal numbers
# Hence option 08 and 09 will not work
# Solution is to remove the leading 0 from the parsed options
2018-11-22 02:16:21 +03:00
command -v bar::start > /dev/null && bar::start
2018-11-05 13:28:42 +03:00
for OP in "${OPTION[@]#0}"; do
# See Tilix section in apply-colors.sh for usage of LOOP
LOOP=$((${LOOP:-0}+1))
2018-11-22 02:16:21 +03:00
command -v bar::status_changed > /dev/null && bar::status_changed $LOOP ${#OPTION[@]}
if [[ OP -le ARRAYLENGTH && OP -gt 0 ]]; then
FILENAME=$(remove_file_extension "${THEMES[((OP-1))]}")
FILENAME_SPACE="${FILENAME//-/ }"
2018-11-13 20:51:25 +03:00
echo -e "\nTheme: $(capitalize "${FILENAME_SPACE}")"
for c in {0..15}; do
echo -n "$(tput setaf $c)$(tput sgr0)"
[[ $c == 7 ]] && echo -n " "
done
echo
2017-12-27 19:45:55 +03:00
SET_THEME="${THEMES[((OP-1))]}"
2017-07-04 23:26:10 +03:00
set_gogh "${SET_THEME}"
else
2018-11-13 20:51:25 +03:00
echo -e "$(tput setaf 1) ~ INVALID OPTION! ~$(tput sgr0)"
2017-07-04 23:26:10 +03:00
exit 1
fi
2018-11-07 01:39:32 +03:00
done
2018-11-22 02:16:21 +03:00
command -v bar::stop > /dev/null && bar::stop