diff --git a/aliases b/aliases index 0ab6dbc..ab1215e 100644 --- a/aliases +++ b/aliases @@ -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() { diff --git a/bin/compress-video b/bin/compress-video index fe75a33..19669bc 100644 --- a/bin/compress-video +++ b/bin/compress-video @@ -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 diff --git a/bin/sync-android-chrome-tabs b/bin/sync-android-chrome-tabs index 99ac980..7694c94 100644 --- a/bin/sync-android-chrome-tabs +++ b/bin/sync-android-chrome-tabs @@ -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 diff --git a/osx/install b/osx/install index 5f2dcce..3b8ce31 100755 --- a/osx/install +++ b/osx/install @@ -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 diff --git a/osx/pre_install b/osx/pre_install index 250a489..4058667 100755 --- a/osx/pre_install +++ b/osx/pre_install @@ -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 diff --git a/script_helpers/file_ops.sh b/script_helpers/file_ops.sh index 9314009..6eca90e 100644 --- a/script_helpers/file_ops.sh +++ b/script_helpers/file_ops.sh @@ -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 } diff --git a/script_helpers/printing.sh b/script_helpers/printing.sh index 73c5b91..86167cb 100644 --- a/script_helpers/printing.sh +++ b/script_helpers/printing.sh @@ -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" } diff --git a/vim/templates/skeleton.sh b/vim/templates/skeleton.sh index 2eeac86..4c71957 100644 --- a/vim/templates/skeleton.sh +++ b/vim/templates/skeleton.sh @@ -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}"