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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,26 +1,30 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if which tput >/dev/null 2>&1; then if which tput >/dev/null 2>&1; then
ncolors=$(tput colors) ncolors=$(tput colors)
fi fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)" RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)" GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)" YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)" BLUE="$(tput setaf 4)"
BOLD="$(tput bold)" MAGENTA="$(tput setaf 5)"
NORMAL="$(tput sgr0)" CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else else
RED="" RED=""
GREEN="" GREEN=""
YELLOW="" YELLOW=""
BLUE="" BLUE=""
BOLD="" MAGENTA=""
NORMAL="" CYAN=""
BOLD=""
NORMAL=""
fi fi
error() { error() {
printf "${BOLD}${RED}$1${NORMAL}" printf "${BOLD}${RED}$1${NORMAL}"
} }
fatal() { fatal() {
@ -30,7 +34,7 @@ fatal() {
} }
log() { log() {
msg="$1" msg="$1"
value="$2" value="$2"
printf "@log ${BOLD}${YELLOW}$msg${GREEN}$value${NORMAL}\n" 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) ncolors=$(tput colors)
fi fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)" RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)" GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)" YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)" BLUE="$(tput setaf 4)"
BOLD="$(tput bold)" MAGENTA="$(tput setaf 5)"
NORMAL="$(tput sgr0)" CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else else
RED="" RED=""
GREEN="" GREEN=""
YELLOW="" YELLOW=""
BLUE="" BLUE=""
BOLD="" MAGENTA=""
NORMAL="" CYAN=""
BOLD=""
NORMAL=""
fi fi
error() { error() {
printf "${BOLD}${RED}$1${NORMAL}\n" printf "${BOLD}${RED}$1${NORMAL}\n"
} }
abort() { abort() {
error "\nAborting..." error "\nAborting..."
exit 1 exit 1
} }
set -e set -e
@ -35,7 +39,7 @@ cwd=$PWD
uname_s="$(uname -s)" uname_s="$(uname -s)"
case "${uname_s}" in case "${uname_s}" in
Linux*) machine=Linux;; Linux*) machine=Linux;;
Darwin*) machine=Mac;; Darwin*) machine=MacOS;;
CYGWIN*) machine=Cygwin;; CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;; MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${uname_s}" *) machine="UNKNOWN:${uname_s}"