Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions bin/_helpers
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env bash

#
# Script Output
#

# Determine width of the program
ACTUAL_WIDTH=$(($(tput cols) - 2))
MAX_WIDTH=100

if test "$ACTUAL_WIDTH" -gt "$MAX_WIDTH"; then
WIDTH=$MAX_WIDTH
else
WIDTH=$ACTUAL_WIDTH
fi

declare BG_R
declare BG_G
declare BG_Y
declare BG_B
declare BG_M
declare BG_C
declare BG_N

declare FG_R
declare FG_G
declare FG_Y
declare FG_B
declare FG_M
declare FG_C
declare FG_N

declare BOLD
declare RESET

# Setup Color Outputs
if test -t 1; then
ncolors=$(tput colors)

if test -n "$ncolors" && test "$ncolors" -ge 8; then
COLOR_R=1 # color code - RED
COLOR_G=2 # color code - GREEN
COLOR_Y=3 # color code - YELLOW
COLOR_B=4 # color code - BLUE
COLOR_M=5 # color code - MAGENTA
COLOR_C=6 # color code - CYAN
COLOR_N=246 # color code - NEUTRAL (GRAY)

BG_R="$(tput setab $COLOR_R)" # Background - RED
BG_G="$(tput setab $COLOR_G)" # Background - GREEN
BG_Y="$(tput setab $COLOR_Y)" # Background - YELLOW
BG_B="$(tput setab $COLOR_B)" # Background - BLUE
BG_M="$(tput setab $COLOR_M)" # Background - MAGENTA
BG_C="$(tput setab $COLOR_C)" # Background - CYAN
BG_N="$(tput setab $COLOR_N)" # Background - NEUTRAL (GRAY)

FG_R="$(tput setaf $COLOR_R)" # Foreground - RED
FG_G="$(tput setaf $COLOR_G)" # Foreground - GREEN
FG_Y="$(tput setaf $COLOR_Y)" # Foreground - YELLOW
FG_B="$(tput setaf $COLOR_B)" # Foreground - BLUE
FG_M="$(tput setaf $COLOR_M)" # Foreground - MAGENTA
FG_C="$(tput setaf $COLOR_C)" # Foreground - CYAN
FG_N="$(tput setaf $COLOR_N)" # Foreground - NEUTRAL (GRAY)

BOLD="$(tput bold)"
RESET="$(tput sgr0)"
fi
fi

function join {
local IFS="$1"
shift
echo "$*"
}

function tag {
local STYLE=$1
local LABEL=$2
shift 2

echo "$@" "${STYLE} ${LABEL} ${RESET} "
}

function output_tagged_string() {
tag "$1" "$2" -n
echo "$3"
}

function output_error {
output_tagged_string "$BG_R" "ERROR" "$1"
}

function output_info {
output_tagged_string "$BG_B" "INFO" "$1"
}

export BG_R
export BG_G
export BG_Y
export BG_B
export BG_M
export BG_C
export BG_N

export FG_R
export FG_G
export FG_Y
export FG_B
export FG_M
export FG_C
export FG_N

export BOLD
export RESET

export WIDTH
76 changes: 9 additions & 67 deletions bin/hop
Original file line number Diff line number Diff line change
@@ -1,61 +1,9 @@
#!/usr/bin/env bash

HOP_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
HOP_PATH=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
TOOLKIT_PATH=$(dirname "$HOP_PATH")

#
# Script Output
#

# Determine width of the program
ACTUAL_WIDTH=$(($(tput cols) - 2))
MAX_WIDTH=100

if test "$ACTUAL_WIDTH" -gt "$MAX_WIDTH"; then
WIDTH=$MAX_WIDTH
else
WIDTH=$ACTUAL_WIDTH
fi

# Setup Color Outputs
if test -t 1; then
ncolors=$(tput colors)

if test -n "$ncolors" && test "$ncolors" -ge 8; then
COLOR_R=1 # color code - RED
COLOR_G=2 # color code - GREEN
COLOR_Y=3 # color code - YELLOW
COLOR_B=4 # color code - BLUE
COLOR_M=5 # color code - MAGENTA
COLOR_C=6 # color code - CYAN
COLOR_N=246 # color code - NEUTRAL (GRAY)

BG_R="$(tput setab $COLOR_R)" # Background - RED
BG_G="$(tput setab $COLOR_G)" # Background - GREEN
BG_Y="$(tput setab $COLOR_Y)" # Background - YELLOW
BG_B="$(tput setab $COLOR_B)" # Background - BLUE
#BG_M="$(tput setab $COLOR_M)" # Background - MAGENTA
#BG_C="$(tput setab $COLOR_C)" # Background - CYAN
#BG_N="$(tput setab $COLOR_N)" # Background - NEUTRAL (GRAY)

#FG_R="$(tput setaf $COLOR_R)" # Foreground - RED
#FG_G="$(tput setaf $COLOR_G)" # Foreground - GREEN
#FG_Y="$(tput setaf $COLOR_Y)" # Foreground - YELLOW
#FG_B="$(tput setaf $COLOR_B)" # Foreground - BLUE
FG_M="$(tput setaf $COLOR_M)" # Foreground - MAGENTA
FG_C="$(tput setaf $COLOR_C)" # Foreground - CYAN
FG_N="$(tput setaf $COLOR_N)" # Foreground - NEUTRAL (GRAY)

BOLD="$(tput bold)"
RESET="$(tput sgr0)"
fi
fi

function join {
local IFS="$1"
shift
echo "$*"
}
source "$TOOLKIT_PATH/bin/_helpers"

function describe_command {
local COMMAND_NAME=$1
Expand All @@ -79,19 +27,6 @@ function describe_command {
join " " "${SEGMENTS[@]}" "${RESET}"
}

function tag {
local STYLE=$1
local LABEL=$2
shift 2

echo "$@" "${STYLE} ${LABEL} ${RESET} "
}

function output_error {
tag "$BG_R" "ERROR" -n
echo "$1"
}

EXPLAIN_COUNT=0
function explain {
EXPLAIN_COUNT=$((EXPLAIN_COUNT + 1))
Expand Down Expand Up @@ -159,6 +94,9 @@ function display_help {
describe_command "seed" "hop artisan db:seed"
describe_command "test" "hop artisan test"
describe_command "tinker" "hop artisan tinker"
echo
tag "$BG_Y$BOLD" "Commands"
describe_command "proxy" "\$@" "Start a proxy for this project."
}

if [ $# -lt 1 ] || [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; then
Expand Down Expand Up @@ -411,6 +349,10 @@ case $1 in
shift 1
run_exec_command php vendor/bin/pint
;;
"proxy")
shift 1
bash "$TOOLKIT_PATH/bin/proxy" "$@"
;;
"ps"|"status")
shift 1
run_command ps "$@"
Expand Down
Loading