Formatting and more bash colors

This commit is contained in:
Lynda Wang 2020-07-26 13:58:29 -04:00 committed by Michael Campagnaro
parent 74d2cb7c42
commit 8cd9f4aa39
8 changed files with 202 additions and 175 deletions

36
aliases
View File

@ -6,22 +6,26 @@
platform=`uname`
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
####################################################################################################
@ -29,12 +33,12 @@ fi
####################################################################################################
error() {
printf "${BOLD}${RED}$1${NORMAL}\n"
printf "${BOLD}${RED}$1${NORMAL}\n"
}
abort() {
error "\nAborting..."
exit 1
error "\nAborting..."
exit 1
}
reload() {

View File

@ -1,22 +1,26 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
if [[ $1 == "" ]]; then

View File

@ -1,31 +1,35 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
error() {
printf "${BOLD}${RED}$1${NORMAL}"
printf "${BOLD}${RED}$1${NORMAL}"
}
abort() {
error "\nAborting...\n"
exit 1
error "\nAborting...\n"
exit 1
}
set -e
@ -38,12 +42,12 @@ adb forward tcp:9222 localabstract:chrome_devtools_remote
src=_tabs.json
if wget -qO $src http://localhost:9222/json/list; then
ts=`date +"%Y-%m-%d_%H-%M-%S"`
dest="${cwd}/${ts}_android-chrome-tabs.md"
sed -n "/\"url\"/p" $src | sed -e "s/^[ \t]*.\{8\}//" -e "s/.\{2\}$//" > $dest
printf "${BOLD}Saved tabs to: ${YELLOW}$dest${NORMAL}\n"
ts=`date +"%Y-%m-%d_%H-%M-%S"`
dest="${cwd}/${ts}_android-chrome-tabs.md"
sed -n "/\"url\"/p" $src | sed -e "s/^[ \t]*.\{8\}//" -e "s/.\{2\}$//" > $dest
printf "${BOLD}Saved tabs to: ${YELLOW}$dest${NORMAL}\n"
else
error "Unable to download tabs from device!\n"
error "Unable to download tabs from device!\n"
fi
rm $src

View File

@ -1,22 +1,26 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
set -e

View File

@ -1,22 +1,26 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
set -e

View File

@ -11,19 +11,18 @@
# Will return a symlink path in its expanded form. If the path's root is the
# home directory symbol "~" then it'll be replaced by the full home path.
expand_path() {
local ret="$1"
local ret="$1"
IFS="/" read -ra parts <<< "$ret"
if [[ "${parts[0]}" == "~" ]]; then
ret="$HOME"
for ((i=1; i < ${#parts[@]}; i++))
do
ret="$ret/${parts[$i]}"
done
fi
ret=$(readlink -m "$ret")
echo $ret
IFS="/" read -ra parts <<< "$ret"
if [[ "${parts[0]}" == "~" ]]; then
ret="$HOME"
for ((i=1; i < ${#parts[@]}; i++))
do
ret="$ret/${parts[$i]}"
done
fi
ret=$(readlink -m "$ret")
echo $ret
}
unix_to_windows_path() {
@ -42,82 +41,82 @@ unix_to_windows_path() {
}
windows_to_unix_path() {
ret=$1
ret="/${ret/:/}" # Remove drive ':'.
ret="${ret//\\//}" # Replace Windows slashes.
ret="${ret// /\\ }" # Add a backslash before spaces.
echo "$ret"
ret=$1
ret="/${ret/:/}" # Remove drive ':'.
ret="${ret//\\//}" # Replace Windows slashes.
ret="${ret// /\\ }" # Add a backslash before spaces.
echo "$ret"
}
move_file() {
local src="$1"
local src_path=$(dirname "${src}")
local src_name=$(basename "${src}")
local dest=$2
local src_type=$3 # e.g. "script", "dependency", etc
local src="$1"
local src_path=$(dirname "${src}")
local src_name=$(basename "${src}")
local dest=$2
local src_type=$3 # e.g. "script", "dependency", etc
if [[ $src_type != '' ]]; then
src_type="$src_type "
fi
if [[ $src_type != '' ]]; then
src_type="$src_type "
fi
if [[ -e "$src" ]]; then
mkdir -p "$dest"
mv "$src" "$dest"
printf "${BOLD}${GREEN}Moved $src_type$src to $dest${NORMAL}\n"
else
error "Unable to find $src_type$src!\n"
fi
if [[ -e "$src" ]]; then
mkdir -p "$dest"
mv "$src" "$dest"
printf "${BOLD}${GREEN}Moved $src_type$src to $dest${NORMAL}\n"
else
error "Unable to find $src_type$src!\n"
fi
}
copy_file() {
local src="$1"
local src_path=$(dirname "${src}")
local src_name=$(basename "${src}")
local dest=$2
local src_type=$3 # e.g. "script", "dependency", etc
local src="$1"
local src_path=$(dirname "${src}")
local src_name=$(basename "${src}")
local dest=$2
local src_type=$3 # e.g. "script", "dependency", etc
if [[ $src_type != '' ]]; then
src_type="$src_type "
fi
if [[ $src_type != '' ]]; then
src_type="$src_type "
fi
if [[ -e "$src" ]]; then
# @fixme If $dest is a file then strip the file name from the path and mkdir on that instead
echo "MAKE DIR $src $dest"
#mkdir -p "$dest"
cp "$src" "$dest"
printf "${BOLD}${GREEN}Copied $src_type$src to $dest${NORMAL}\n"
else
error "Unable to find $src_type$src!\n"
fi
if [[ -e "$src" ]]; then
# @fixme If $dest is a file then strip the file name from the path and mkdir on that instead
echo "MAKE DIR $src $dest"
#mkdir -p "$dest"
cp "$src" "$dest"
printf "${BOLD}${GREEN}Copied $src_type$src to $dest${NORMAL}\n"
else
error "Unable to find $src_type$src!\n"
fi
}
copy_dir_files() {
local src="$1"
local dest=$2
local src="$1"
local dest=$2
if [[ -d "$src" ]]; then
mkdir -p "$dest"
cp -r $src/* $dest
printf "${BOLD}${GREEN}Copied contents of $src into $dest${NORMAL}\n"
else
error "Unable to find $src!\n"
fi
if [[ -d "$src" ]]; then
mkdir -p "$dest"
cp -r $src/* $dest
printf "${BOLD}${GREEN}Copied contents of $src into $dest${NORMAL}\n"
else
error "Unable to find $src!\n"
fi
}
is_absolute_unix_path() {
if [[ $1 =~ ^/ ]]; then echo 1; else echo 0; fi
if [[ $1 =~ ^/ ]]; then echo 1; else echo 0; fi
}
is_sym_file() {
if [[ $1 =~ ^\.{1} ]]; then echo 1; else echo 0; fi
if [[ $1 =~ ^\.{1} ]]; then echo 1; else echo 0; fi
}
is_windows_path() {
if [[ ! $1 =~ \/+ ]]; then echo 1; else echo 0; fi
if [[ ! $1 =~ \/+ ]]; then echo 1; else echo 0; fi
}
is_unix_path() {
echo $(! is_windows_path "$1")
echo $(! is_windows_path "$1")
}
path_has_a_space() {
@ -200,7 +199,7 @@ link_file() {
fi
if [[ $require_confirmation -eq 1 ]]; then
echo "${BOLD}${BLUE}Will attempt to link ${GREEN}$source_path${BLUE} to ${GREEN}$dest_path${BLUE}"
echo "${BOLD}${BLUE}Will attempt to link ${YELLOW}$source_path${BLUE} to ${YELLOW}$dest_path${BLUE}"
printf "${BOLD}Enter 1 to proceed\n${YELLOW}> ${NORMAL}"
read confirm
if [[ $confirm != 1 ]]; then abort; fi
@ -212,7 +211,7 @@ link_file() {
echo Link cmd:: $link_cmd
fi
printf "${BOLD}*${NORMAL} ${YELLOW}Linking '$source_path'${NORMAL} to ${YELLOW}'$dest_path'${NORMAL}\n"
printf "${BOLD}${GREEN}==> ${NORMAL}Linking ${BOLD}${YELLOW}'$source_path'${NORMAL} to ${BOLD}${YELLOW}'$dest_path'${NORMAL}\n"
eval $link_cmd
}
@ -222,7 +221,7 @@ function setup_file() {
if [ ! -f $dest ]; then
link_file $src $dest $confirm_link
else
printf "${BOLD}*${NORMAL} ${YELLOW}'$dest'${NORMAL} already linked to ${YELLOW}'$src'${NORMAL}\n"
printf "${BOLD}${MAGENTA}==> ${NORMAL}${BOLD}${YELLOW}'$dest'${NORMAL} already linked to ${BOLD}${YELLOW}'$src'${NORMAL}\n"
fi
}
@ -232,7 +231,7 @@ function setup_dir() {
if [ ! -d $dest ]; then
link_file $src $dest $confirm_link
else
printf "${BOLD}*${NORMAL} ${YELLOW}'$dest'${NORMAL} already linked to ${YELLOW}'$src'${NORMAL}\n"
printf "${BOLD}${MAGENTA}==> ${NORMAL}${BOLD}${YELLOW}'$dest'${NORMAL} already linked to ${BOLD}${YELLOW}'$src'${NORMAL}\n"
fi
}

View File

@ -1,26 +1,30 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
error() {
printf "${BOLD}${RED}$1${NORMAL}"
printf "${BOLD}${RED}$1${NORMAL}"
}
fatal() {
@ -30,7 +34,7 @@ fatal() {
}
log() {
msg="$1"
value="$2"
printf "@log ${BOLD}${YELLOW}$msg${GREEN}$value${NORMAL}\n"
msg="$1"
value="$2"
printf "@log ${BOLD}${YELLOW}$msg${GREEN}$value${NORMAL}\n"
}

View File

@ -4,28 +4,32 @@ if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
error() {
printf "${BOLD}${RED}$1${NORMAL}\n"
printf "${BOLD}${RED}$1${NORMAL}\n"
}
abort() {
error "\nAborting..."
exit 1
error "\nAborting..."
exit 1
}
set -e
@ -35,7 +39,7 @@ cwd=$PWD
uname_s="$(uname -s)"
case "${uname_s}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
Darwin*) machine=MacOS;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${uname_s}"