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

417 lines
12 KiB
Bash
Raw Normal View History

2017-07-04 23:26:10 +03:00
#!/usr/bin/env bash
2018-11-27 23:11:54 +03:00
# Define traps and trapfunctions early in case any errors before script exits
GLOBAL_VAR_CLEANUP(){
[[ -n "$(command -v TILIX_TMP_CLEANUP)" ]] && TILIX_TMP_CLEANUP
unset PROFILE_NAME
unset PROFILE_SLUG
unset TILIX_RES
unset TERMINAL
}
trap 'GLOBAL_VAR_CLEANUP; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
2017-07-04 23:26:10 +03:00
declare -a THEMES=(
2018-11-29 23:48:25 +03:00
'3024-day.sh'
'3024-night.sh'
'aci.sh'
'aco.sh'
'adventuretime.sh'
'afterglow.sh'
'alien-blood.sh'
'argonaut.sh'
'arthur.sh'
'atom.sh'
'azu.sh'
'belafonte-day.sh'
'belafonte-night.sh'
'bim.sh'
'birds-of-paradise.sh'
'blazer.sh'
'borland.sh'
'broadcast.sh'
'brogrammer.sh'
'c64.sh'
'cai.sh'
'chalk.sh'
'chalkboard.sh'
'ciapre.sh'
'clone-of-ubuntu.sh'
'clrs.sh'
'cobalt-neon.sh'
'cobalt2.sh'
'crayon-pony-fish.sh'
'dark-pastel.sh'
'darkside.sh'
'desert.sh'
'dimmed-monokai.sh'
'dracula.sh'
'earthsong.sh'
'elemental.sh'
'elementary.sh'
'elic.sh'
'elio.sh'
'espresso-libre.sh'
'espresso.sh'
'fishtank.sh'
'flat.sh'
'flatland.sh'
'foxnightly.sh'
'freya.sh'
'frontend-delight.sh'
'frontend-fun-forrest.sh'
'frontend-galaxy.sh'
'github.sh'
2018-12-01 22:20:22 +03:00
'google-dark.sh'
2018-11-29 23:48:25 +03:00
'gooey.sh'
'grape.sh'
'grass.sh'
'gruvbox-dark.sh'
'gruvbox.sh'
'hardcore.sh'
'harper.sh'
'hemisu-dark.sh'
'hemisu-light.sh'
'highway.sh'
'hipster-green.sh'
'homebrew.sh'
'hurtado.sh'
'hybrid.sh'
'ic-green-ppl.sh'
'ic-orange-ppl.sh'
'idle-toes.sh'
'ir-black.sh'
'jackie-brown.sh'
'japanesque.sh'
'jellybeans.sh'
'jup.sh'
'kibble.sh'
'later-this-evening.sh'
'lavandula.sh'
'liquid-carbon-transparent.sh'
'liquid-carbon.sh'
'man-page.sh'
'mar.sh'
'material.sh'
'mathias.sh'
'medallion.sh'
'misterioso.sh'
'miu.sh'
'molokai.sh'
'mona-lisa.sh'
'monokai-dark.sh'
'monokai-soda.sh'
'n0tch2k.sh'
'neopolitan.sh'
'nep.sh'
'neutron.sh'
'nightlion-v1.sh'
'nightlion-v2.sh'
'nighty.sh'
'nord-light.sh'
'nord.sh'
'novel.sh'
'obsidian.sh'
'ocean-dark.sh'
'ocean.sh'
'oceanic-next.sh'
'ollie.sh'
'one-dark.sh'
'one-half-black.sh'
'one-light.sh'
'pali.sh'
'paraiso-dark.sh'
'paul-millr.sh'
'pencil-dark.sh'
'pencil-light.sh'
'peppermint.sh'
'pnevma.sh'
'pro.sh'
'red-alert.sh'
'red-sands.sh'
'rippedcasts.sh'
'royal.sh'
'sat.sh'
'sea-shells.sh'
'seafoam-pastel.sh'
'seti.sh'
'shaman.sh'
'shel.sh'
'slate.sh'
'smyck.sh'
'snazzy.sh'
'soft-server.sh'
'solarized-darcula.sh'
'solarized-dark-higher-contrast.sh'
'solarized-dark.sh'
'solarized-light.sh'
'spacedust.sh'
'spacegray-eighties-dull.sh'
'spacegray-eighties.sh'
'spacegray.sh'
'spring.sh'
'square.sh'
'srcery.sh'
'sundried.sh'
'symphonic.sh'
'teerb.sh'
'terminal-basic.sh'
'terminix-dark.sh'
'thayer-bright.sh'
'tin.sh'
'tomorrow-night-blue.sh'
'tomorrow-night-bright.sh'
'tomorrow-night-eighties.sh'
'tomorrow-night.sh'
'tomorrow.sh'
'toy-chest.sh'
'treehouse.sh'
'twilight.sh'
'ura.sh'
'urple.sh'
'vag.sh'
'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-12-01 20:06:39 +03:00
PROGRESS_URL="https://raw.githubusercontent.com/phenonymous/shell-progressbar/1.0/progress.sh"
2018-11-05 13:28:42 +03:00
2017-12-27 19:59:05 +03:00
capitalize() {
2018-11-29 23:48:25 +03:00
local ARGUMENT=$1
local RES=""
local STR=""
local RES_NO_TRAIL_SPACE=""
for CHAR in $ARGUMENT; do
STR=$(echo "${CHAR:0:1}" | tr "[:lower:]" "[:upper:]")"${CHAR:1} "
RES="${RES}${STR}"
RES_NO_TRAIL_SPACE="$(echo -e "${RES}" | sed -e 's/[[:space:]]*$//')"
done
2018-11-29 23:48:25 +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() {
2018-11-29 23:48:25 +03:00
string=$1
string_r="${string%???}"
string_s=${string_r//\./_}
result=$(capitalize "${string_s}")
url="${BASE_URL}/themes/$1"
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
if [[ "$(uname)" = "Darwin" ]]; then
# OSX ships with curl
2018-11-30 01:20:17 +03:00
bash -c "$(curl -sLo- "${url}")"
else
2018-11-29 23:48:25 +03:00
# Linux ships with wget
2018-11-30 01:20:17 +03:00
bash -c "$(wget -qO- "${url}")"
fi
2018-11-29 23:48:25 +03:00
fi
}
2018-11-13 20:51:25 +03:00
remove_file_extension (){
2018-11-29 23:48:25 +03:00
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+=" "
2018-11-27 13:10:12 +03:00
printf '%b\n' "${gogh_str}"
2018-11-30 01:20:17 +03:00
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
2018-11-29 23:48:25 +03:00
KEY=$(printf "%02d" $NUM)
FILENAME=${TH::$((${#TH}-3))}
FILENAME_SPACE=${FILENAME//-/ }
2017-07-04 23:26:10 +03:00
2018-11-29 23:48:25 +03:00
echo -e " ($(tput setaf 4) $KEY $(tput sgr0)) $(capitalize "${FILENAME_SPACE}")"
2017-07-04 23:26:10 +03:00
2018-11-29 23:48:25 +03:00
((NUM++))
2017-07-04 23:26:10 +03:00
done
2018-11-29 23:48: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)"
2018-11-27 13:10:12 +03:00
if [[ "$OS" = "Darwin" ]]; then
2018-11-29 23:48:25 +03:00
TERMINAL=$TERM_PROGRAM
2018-11-27 13:10:12 +03:00
elif [[ "${OS#CYGWIN}" != "${OS}" ]]; then
2018-11-29 23:48:25 +03:00
TERMINAL="mintty"
2018-11-22 02:16:21 +03:00
else
2018-11-29 23:48:25 +03:00
# |
# | 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)"
2018-11-05 13:28:42 +03:00
TERMINAL="$(ps -h -o comm -p $pid)"
2018-11-29 23:48:25 +03:00
done
2018-11-22 02:16:21 +03:00
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
2018-12-01 20:06:39 +03:00
# Note: We use eval here because we want the functions to be available in this script
2018-11-29 23:48:25 +03:00
if [[ "$(uname)" = "Darwin" ]]; then
2018-12-01 20:06:39 +03:00
eval "$(curl -so- ${PROGRESS_URL})" 2> /dev/null
2018-11-29 23:48:25 +03:00
else
2018-12-01 20:06:39 +03:00
eval "$(wget -qO- ${PROGRESS_URL})" 2> /dev/null
2018-11-29 23:48:25 +03:00
fi
2018-11-13 20:51:25 +03:00
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-29 23:48:25 +03:00
echo
read -r -p "Tilix detected - use color schemes instead of profiles? [y/N] " -n 1 TILIX_RES
echo
# |
# | 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
TILIX_TMP_CLEANUP() {
2018-11-29 23:48:25 +03:00
echo
echo "Cleaning up"
rm -rf "$scratchdir"
unset LOOP OPTLENGTH scratchdir
2018-11-29 23:48:25 +03:00
echo "Done..."
exit 0
}
scratchdir=$(mktemp -d -t tmp.XXXXXXXX)
export scratchdir
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-29 23:48:25 +03:00
declare color_dot_str
for c in {0..15}; do
color_dot_str+="$(tput setaf $c)$(tput sgr0)"
[[ $c == 7 ]] && color_dot_str+=" "
done
# 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
2018-11-29 23:48:25 +03:00
# See appy_tilixschemes in apply-colors.sh for usage of LOOP
LOOP=$((${LOOP:-0}+1))
2018-11-22 02:16:21 +03:00
2018-11-29 23:48:25 +03:00
command -v bar::status_changed > /dev/null && bar::status_changed $LOOP ${#OPTION[@]}
2018-11-22 02:16:21 +03:00
2018-11-29 23:48:25 +03:00
if [[ OP -le ARRAYLENGTH && OP -gt 0 ]]; then
2018-11-29 23:48:25 +03:00
FILENAME=$(remove_file_extension "${THEMES[((OP-1))]}")
FILENAME_SPACE="${FILENAME//-/ }"
echo -e "\nTheme: $(capitalize "${FILENAME_SPACE}")"
echo "${color_dot_str}"
echo
2017-12-27 19:45:55 +03:00
2018-11-29 23:48:25 +03:00
SET_THEME="${THEMES[((OP-1))]}"
set_gogh "${SET_THEME}"
else
echo -e "$(tput setaf 1) ~ INVALID OPTION! ~$(tput sgr0)"
exit 1
fi
2018-11-07 01:39:32 +03:00
done
2018-12-01 20:06:39 +03:00
# If you skip || : and the command does not exist the script will exit with code 1
# this will always return exit code 0 if we got this far
command -v bar::stop > /dev/null && bar::stop || :