153f5e11ed2f2cd50afe8804ecf1c2d6ef8e1f35

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

installer: use default color sequences on missing tput

Supposed to be POSIX-compatible. Proved to work in dash, yash and whatever
alpine uses. See https://unix.stackexchange.com/a/371873

Diff

  1diff --git a/tools/install.sh b/tools/install.sh
  2index db23d9896997fe92e789ca7267b372a2cd41d34e..e69ce4b83c29508de28b5884de7849bd49d25906 100755
  3--- a/tools/install.sh
  4+++ b/tools/install.sh
  5@@ -27,7 +27,7 @@ command_exists() {
  6 }
  7 
  8 error() {
  9-	echo "Error: $@" >&2
 10+	echo ${RED}"Error: $@"${RESET} >&2
 11 }
 12 
 13 # Set up color sequences
 14@@ -45,14 +45,14 @@ setup_color() {
 15 		YELLOW="$(tput setaf 3)"
 16 		BLUE="$(tput setaf 4)"
 17 		BOLD="$(tput bold)"
 18-		NORMAL="$(tput sgr0)"
 19+		RESET="$(tput sgr0)"
 20 	else
 21-		RED=""
 22-		GREEN=""
 23-		YELLOW=""
 24-		BLUE=""
 25-		BOLD=""
 26-		NORMAL=""
 27+		RED=$(printf '\033[31m')
 28+		GREEN=$(printf '\033[32m')
 29+		YELLOW=$(printf '\033[33m')
 30+		BLUE=$(printf '\033[34m')
 31+		BOLD=$(printf '\033[1m')
 32+		RESET=$(printf '\033[m')
 33 	fi
 34 }
 35 
 36@@ -64,7 +64,7 @@ setup_ohmyzsh() {
 37 	# precedence over umasks except for filesystems mounted with option "noacl".
 38 	umask g-w,o-w
 39 
 40-	echo "${BLUE}Cloning Oh My Zsh...${NORMAL}"
 41+	echo "${BLUE}Cloning Oh My Zsh...${RESET}"
 42 
 43 	command_exists git || {
 44 		error "git is not installed"
 45@@ -84,13 +84,13 @@ setup_ohmyzsh() {
 46 }
 47 
 48 setup_zshrc() {
 49-	echo "${BLUE}Looking for an existing zsh config...${NORMAL}"
 50+	echo "${BLUE}Looking for an existing zsh config...${RESET}"
 51 	if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
 52-		echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${NORMAL}"
 53+		echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${RESET}"
 54 		mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh
 55 	fi
 56 
 57-	echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${NORMAL}"
 58+	echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"
 59 
 60 	cp "$ZSH/templates/zshrc.zsh-template" ~/.zshrc
 61 	sed "/^export ZSH=/ c\\
 62@@ -109,12 +109,12 @@ setup_shell() {
 63 	if ! command_exists chsh; then
 64 		cat <<-EOF
 65 			I can't change your shell automatically because this system does not have chsh.
 66-			${BLUE}Please manually change your default shell to zsh${NORMAL}
 67+			${BLUE}Please manually change your default shell to zsh${RESET}
 68 		EOF
 69 		return
 70 	fi
 71 
 72-	echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
 73+	echo "${BLUE}Time to change your default shell to zsh!${RESET}"
 74 
 75 	# Test for the right location of the "shells" file
 76 	if [ -f /etc/shells ]; then
 77@@ -146,13 +146,13 @@ main() {
 78 	setup_color
 79 
 80 	if ! command_exists zsh; then
 81-		echo "${YELLOW}Zsh is not installed.${NORMAL} Please install zsh first."
 82+		echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first."
 83 		exit 1
 84 	fi
 85 
 86 	if [ -d "$ZSH" ]; then
 87 		cat <<-EOF
 88-			${YELLOW}You already have Oh My Zsh installed.${NORMAL}
 89+			${YELLOW}You already have Oh My Zsh installed.${RESET}
 90 			You'll need to remove '$ZSH' if you want to reinstall.
 91 		EOF
 92 		exit 1
 93@@ -179,7 +179,7 @@ main() {
 94 		p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh
 95 
 96 	EOF
 97-	printf "$NORMAL"
 98+	printf "$RESET"
 99 
100 	exec zsh -l
101 }