1
0
mirror of https://github.com/Mayccoll/Gogh.git synced 2023-08-10 21:12:46 +03:00
Gogh/gogh.sh

345 lines
8.1 KiB
Bash
Raw Normal View History

2017-07-04 23:26:10 +03:00
#!/usr/bin/env bash
2018-11-05 13:28:42 +03:00
# Handle errors gracefully
set -euo 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-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'
2018-11-05 13:28:42 +03:00
'google-light.sh'
'google-dark.sh'
2017-07-04 23:26:10 +03:00
)
2018-11-05 13:28:42 +03:00
cleanup() {
echo
echo "Caught signal..$? Cleaning up"
rm -rf "$scratchdir"
echo "Done..."
exit 1
}
scratchdir=$(mktemp -d -t tmp.XXXXXXXX)
export scratchdir
trap cleanup SIGHUP SIGINT SIGQUIT SIGABRT
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-12-27 19:59:05 +03:00
curlsource() {
2018-11-05 13:28:42 +03:00
local F
F=$(mktemp -t curlsource)
2017-12-27 19:59:05 +03:00
curl -o "$F" -s -L "$1"
source "$F"
rm -f "$F"
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}")
url="https://raw.githubusercontent.com/Mayccoll/Gogh/master/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
bash "$SCRIPT_PATH/themes/$1"
else
2018-11-05 13:28:42 +03:00
if [ "$(uname)" = "Darwin" ]; then
# OSX ships with curl
# Note: sourcing directly from curl does not work
curlsource "${url}"
else
bash <(wget -O - "${url}")
fi
fi
}
remove_file_extension (){
echo "${1%.*}"
2017-07-04 23:26:10 +03:00
}
### Get length of an array
ARRAYLENGTH=${#THEMES[@]}
NUM=1
# |
# | ::::::: Print Colors
# |
echo -e "
Gogh\n
\033[0;30m█████\\033[0m\033[0;31m█████\\033[0m\033[0;32m█████\\033[0m\033[0;33m█████\\033[0m\033[0;34m█████\\033[0m\033[0;35m█████\\033[0m\033[0;36m█████\\033[0m\033[0;37m█████\\033[0m
\033[0m\033[1;30m█████\\033[0m\033[1;31m█████\\033[0m\033[1;32m█████\\033[0m\033[1;33m█████\\033[0m\033[1;34m█████\\033[0m\033[1;35m█████\\033[0m\033[1;36m█████\\033[0m\033[1;37m█████\\033[0m"
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
echo -e " (\\033[0m\033[0;34m $KEY \\033[0m\033[0m) $(capitalize "${FILENAME_SPACE}")"
2017-07-04 23:26:10 +03:00
((NUM++))
done
# |
# | ::::::: Select Option
# |
echo -e "\nUsage : Enter Desired Themes Numbers (\\033[0m\033[0;34mOPTIONS\\033[0m\033[0m) Separated By A Blank Space"
echo -e " Press \033[0;34mENTER\\033[0m 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-05 13:28:42 +03:00
# |
# | ::::::: Get terminal
# |
# |
# | Check for the terminal name (depening on os)
# | ===========================================
OS=$(uname)
if [ "$OS" = "Darwin" ]; then
# |
# | Check for the terminal name and decide how to apply
# | ===========================================
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="$$"
TERMINAL="$(ps -h -o comm -p $pid)"
while [[ "${TERMINAL:(-2)}" == "sh" ]]; do
pid="$(ps -h -o ppid -p $pid)"
TERMINAL="$(ps -h -o comm -p $pid)"
done
fi
# |
# | 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
# | ===========================================
if [[ "$TERMINAL" = "tilix" ]]; then
echo
read -r -p "Tilix detected - use color schemes instead of profiles? [y/N] " -n 1 TILIX_RES
echo
fi
# |
# | ::::::: Export one-off variables
# |
[[ -v TILIX_RES ]] && export TILIX_RES
export TERMINAL LOOP OPTLENGTH=${#OPTION[@]}
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
for OP in "${OPTION[@]#0}"; do
# See Tilix section in apply-colors.sh for usage of LOOP
LOOP=$((${LOOP:-0}+1))
if [[ OP -le ARRAYLENGTH && OP -gt 0 ]]; then
FILENAME=$(remove_file_extension "${THEMES[((OP-1))]}")
FILENAME_SPACE="${FILENAME//-/ }"
2017-12-27 19:45:55 +03:00
echo -e "\nTheme: $(capitalize "${FILENAME_SPACE}")\n\033[0;30m•\\033[0m\033[0;31m•\\033[0m\033[0;32m•\\033[0m\033[0;33m•\\033[0m\033[0;34m•\\033[0m\033[0;35m•\\033[0m\033[0;36m•\\033[0m\033[0;37m•\\033[0m \033[0;37m•\\033[0m\033[0;36m•\\033[0m\033[0;35m•\\033[0m\033[0;34m•\\033[0m\033[0;33m•\\033[0m\033[0;32m•\\033[0m\033[0;31m•\\033[0m\033[0;30m•\\033[0m\n"
SET_THEME="${THEMES[((OP-1))]}"
2017-07-04 23:26:10 +03:00
set_gogh "${SET_THEME}"
else
echo -e "\\033[0m\033[0;31m ~ INVALID OPTION! ~\\033[0m\033[0m"
2017-07-04 23:26:10 +03:00
exit 1
fi
2018-11-05 13:28:42 +03:00
done