feat(nvim): colorize nvim-env output

This commit is contained in:
Price Hiller 2022-07-28 18:27:41 -05:00
parent c24cc569b7
commit 47a9af0a04

View File

@ -377,6 +377,12 @@ nvim-env() {
declare -A nvim_syml_paths=(["$HOME/.config/nvim"]="$nvim_env_full_path/config" ["$HOME/.local/share/nvim"]="$nvim_env_full_path/share")
local red='\033[0;31m'
local cyan='\033[0;36m'
local green='\033[0;32m'
local light_green='\033[1;32m'
local reset='\033[0m'
# Check that the given environment exists
if [[ ! -d "$nvim_env_full_path" ]]; then
printf "Error: Unable to locate environment, \"%s\"\n\t\"%s\"\n" "$nvim_env" "$nvim_env_full_path" >&2
@ -391,13 +397,16 @@ nvim-env() {
# Check that the configuration path exist from our env
if [[ ! -d "$symlink_src" ]]; then
printf "ERROR: Unable to find configuration:\n\t\"%s\" in environment \"%s\"\n\tConsider creating it with \"mkdir -p %s\"\n" "$symlink_src" "$nvim_env" "$symlink_src" >&2
printf "${red}ERROR: Unable to find
configuration:${reset}\n\t\"${cyan}%s${reset}\"${red} in environment
${reset}\"${cyan}%s${reset}\"\n\t${red}Consider creating it with
${reset}\"${cyan}mkdir -p %s${reset}\"\n" "$symlink_src" "$nvim_env" "$symlink_src" >&2
return 1
fi
# If a directory (not a symlink) exists in where we want to write a symlink refuse to overwrite
if [[ -r "$symlink_dst" ]] && [[ ! -L "$symlink_dst" ]]; then
printf "ERROR: Neovim configuration to be replaced is not a symlink, please remove the files before proceeding, issue file:\n\t\"%s\"\n" "$symlink_dst" >&2
printf "${red}ERROR: Neovim configuration to be replaced is not a symlink, please remove the files before proceeding, issue file:${reset}\n\t\"${cyan}%s${reset}\"\n" "$symlink_dst" >&2
return 1
fi
@ -405,24 +414,24 @@ nvim-env() {
if [[ -L "$symlink_dst" ]]; then
local linked_sym
linked_sym="$(readlink "$symlink_dst")"
printf "Attemping to remove symlink:\n\t%s -> %s\n" "$linked_sym" "$symlink_dst"
printf "${light_green}Attemping to remove symlink:${reset}\n\t${cyan}%s${reset} -> ${cyan}%s${reset}\n" "$linked_sym" "$symlink_dst"
if ! rm "$symlink_dst"; then
printf "ERROR: Failed to remove symlink:\n\t%s -> %s\n" "$linked_sym" "$symlink_dst" >&2
printf "${red}ERROR: Failed to remove symlink:${reset}\n\t${cyan}%s${reset} -> ${cyan}%s${reset}\n" "$linked_sym" "$symlink_dst" >&2
return 1
else
printf "Successfully removed symlink:\n\t%s -> %s\n" "$linked_sym" "$symlink_dst"
printf "${light_green}Successfully removed symlink:${reset}\n\t${cyan}%s${reset} -> ${cyan}%s${reset}\n" "$linked_sym" "$symlink_dst"
fi
fi
# Actually write the env now we're past our guards
printf "Linking:\n\t%s -> %s\n" "$symlink_src" "$symlink_dst"
printf "${light_green}Linking:${reset}\n\t${cyan}%s${reset} -> ${cyan}%s${reset}\n" "$symlink_src" "$symlink_dst"
if ! ln -s "$symlink_src" "$symlink_dst"; then
printf "ERROR: Failed to link:\n\t%s -> %s\n" "$symlink_src" "$symlink_dst" >&2
printf "${red}ERROR: Failed to link:${reset}\n\t${cyan}%s${reset} -> ${cyan}%s${reset}\n" "$symlink_src" "$symlink_dst" >&2
return 1
else
printf "Successfully linked:\n\t%s -> %s\n" "$symlink_src" "$symlink_dst"
printf "${light_green}Successfully linked:${reset}\n\t${cyan}%s${reset} -> ${cyan}%s${reset}\n" "$symlink_src" "$symlink_dst"
fi
printf '%.s─' $(seq 1 $(tput cols))
printf "${green}%.s─${reset}" $(seq 1 $(tput cols))
printf "\n"
done
}