Skip to content

Commit 59714b6

Browse files
committed
update: add hop proxy command
1 parent f55951c commit 59714b6

File tree

3 files changed

+304
-67
lines changed

3 files changed

+304
-67
lines changed

bin/_helpers

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Script Output
5+
#
6+
7+
# Determine width of the program
8+
ACTUAL_WIDTH=$(($(tput cols) - 2))
9+
MAX_WIDTH=100
10+
11+
if test "$ACTUAL_WIDTH" -gt "$MAX_WIDTH"; then
12+
WIDTH=$MAX_WIDTH
13+
else
14+
WIDTH=$ACTUAL_WIDTH
15+
fi
16+
17+
# Setup Color Outputs
18+
if test -t 1; then
19+
ncolors=$(tput colors)
20+
21+
if test -n "$ncolors" && test "$ncolors" -ge 8; then
22+
COLOR_R=1 # color code - RED
23+
COLOR_G=2 # color code - GREEN
24+
COLOR_Y=3 # color code - YELLOW
25+
COLOR_B=4 # color code - BLUE
26+
COLOR_M=5 # color code - MAGENTA
27+
COLOR_C=6 # color code - CYAN
28+
COLOR_N=246 # color code - NEUTRAL (GRAY)
29+
30+
BG_R="$(tput setab $COLOR_R)" # Background - RED
31+
BG_G="$(tput setab $COLOR_G)" # Background - GREEN
32+
BG_Y="$(tput setab $COLOR_Y)" # Background - YELLOW
33+
BG_B="$(tput setab $COLOR_B)" # Background - BLUE
34+
#BG_M="$(tput setab $COLOR_M)" # Background - MAGENTA
35+
#BG_C="$(tput setab $COLOR_C)" # Background - CYAN
36+
#BG_N="$(tput setab $COLOR_N)" # Background - NEUTRAL (GRAY)
37+
38+
#FG_R="$(tput setaf $COLOR_R)" # Foreground - RED
39+
#FG_G="$(tput setaf $COLOR_G)" # Foreground - GREEN
40+
#FG_Y="$(tput setaf $COLOR_Y)" # Foreground - YELLOW
41+
#FG_B="$(tput setaf $COLOR_B)" # Foreground - BLUE
42+
FG_M="$(tput setaf $COLOR_M)" # Foreground - MAGENTA
43+
FG_C="$(tput setaf $COLOR_C)" # Foreground - CYAN
44+
FG_N="$(tput setaf $COLOR_N)" # Foreground - NEUTRAL (GRAY)
45+
46+
BOLD="$(tput bold)"
47+
RESET="$(tput sgr0)"
48+
fi
49+
fi
50+
51+
function join {
52+
local IFS="$1"
53+
shift
54+
echo "$*"
55+
}
56+
57+
function tag {
58+
local STYLE=$1
59+
local LABEL=$2
60+
shift 2
61+
62+
echo "$@" "${STYLE} ${LABEL} ${RESET} "
63+
}
64+
65+
function output_error {
66+
tag "$BG_R" "ERROR" -n
67+
echo "$1"
68+
}
69+
70+
function output_info {
71+
tag "$BG_B" "INFO" -n
72+
echo "$1"
73+
}

bin/hop

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,9 @@
11
#!/usr/bin/env bash
22

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

6-
#
7-
# Script Output
8-
#
9-
10-
# Determine width of the program
11-
ACTUAL_WIDTH=$(($(tput cols) - 2))
12-
MAX_WIDTH=100
13-
14-
if test "$ACTUAL_WIDTH" -gt "$MAX_WIDTH"; then
15-
WIDTH=$MAX_WIDTH
16-
else
17-
WIDTH=$ACTUAL_WIDTH
18-
fi
19-
20-
# Setup Color Outputs
21-
if test -t 1; then
22-
ncolors=$(tput colors)
23-
24-
if test -n "$ncolors" && test "$ncolors" -ge 8; then
25-
COLOR_R=1 # color code - RED
26-
COLOR_G=2 # color code - GREEN
27-
COLOR_Y=3 # color code - YELLOW
28-
COLOR_B=4 # color code - BLUE
29-
COLOR_M=5 # color code - MAGENTA
30-
COLOR_C=6 # color code - CYAN
31-
COLOR_N=246 # color code - NEUTRAL (GRAY)
32-
33-
BG_R="$(tput setab $COLOR_R)" # Background - RED
34-
BG_G="$(tput setab $COLOR_G)" # Background - GREEN
35-
BG_Y="$(tput setab $COLOR_Y)" # Background - YELLOW
36-
BG_B="$(tput setab $COLOR_B)" # Background - BLUE
37-
#BG_M="$(tput setab $COLOR_M)" # Background - MAGENTA
38-
#BG_C="$(tput setab $COLOR_C)" # Background - CYAN
39-
#BG_N="$(tput setab $COLOR_N)" # Background - NEUTRAL (GRAY)
40-
41-
#FG_R="$(tput setaf $COLOR_R)" # Foreground - RED
42-
#FG_G="$(tput setaf $COLOR_G)" # Foreground - GREEN
43-
#FG_Y="$(tput setaf $COLOR_Y)" # Foreground - YELLOW
44-
#FG_B="$(tput setaf $COLOR_B)" # Foreground - BLUE
45-
FG_M="$(tput setaf $COLOR_M)" # Foreground - MAGENTA
46-
FG_C="$(tput setaf $COLOR_C)" # Foreground - CYAN
47-
FG_N="$(tput setaf $COLOR_N)" # Foreground - NEUTRAL (GRAY)
48-
49-
BOLD="$(tput bold)"
50-
RESET="$(tput sgr0)"
51-
fi
52-
fi
53-
54-
function join {
55-
local IFS="$1"
56-
shift
57-
echo "$*"
58-
}
6+
source "$TOOLKIT_PATH/bin/_helpers"
597

608
function describe_command {
619
local COMMAND_NAME=$1
@@ -79,19 +27,6 @@ function describe_command {
7927
join " " "${SEGMENTS[@]}" "${RESET}"
8028
}
8129

82-
function tag {
83-
local STYLE=$1
84-
local LABEL=$2
85-
shift 2
86-
87-
echo "$@" "${STYLE} ${LABEL} ${RESET} "
88-
}
89-
90-
function output_error {
91-
tag "$BG_R" "ERROR" -n
92-
echo "$1"
93-
}
94-
9530
EXPLAIN_COUNT=0
9631
function explain {
9732
EXPLAIN_COUNT=$((EXPLAIN_COUNT + 1))
@@ -159,6 +94,9 @@ function display_help {
15994
describe_command "seed" "hop artisan db:seed"
16095
describe_command "test" "hop artisan test"
16196
describe_command "tinker" "hop artisan tinker"
97+
echo
98+
tag "$BG_Y$BOLD" "Commands"
99+
describe_command "proxy" "\$@" "Start a proxy for this project."
162100
}
163101

164102
if [ $# -lt 1 ] || [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; then
@@ -411,6 +349,10 @@ case $1 in
411349
shift 1
412350
run_exec_command php vendor/bin/pint
413351
;;
352+
"proxy")
353+
shift 1
354+
bash "$TOOLKIT_PATH/bin/proxy" "$@"
355+
;;
414356
"ps"|"status")
415357
shift 1
416358
run_command ps "$@"

0 commit comments

Comments
 (0)