-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oleksandr Kucherenko
committed
Nov 24, 2023
1 parent
bc13d6c
commit 4b8ff41
Showing
11 changed files
with
121 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,14 @@ | |
- [TDD - Test Driven Development, run tests on file change](#tdd---test-driven-development-run-tests-on-file-change) | ||
- [Usage](#usage) | ||
- [Colors](#colors) | ||
- [Script Dependencies](#script-dependencies) | ||
- [Logger](#logger) | ||
- [Dependencies](#dependencies) | ||
- [Arguments Parsing](#arguments-parsing) | ||
- [Common(s) Functions](#commons-functions) | ||
- [Deploy / GitHub Pages](#deploy--github-pages) | ||
- [Common(s) Functions And Inputs](#commons-functions-and-inputs) | ||
- [UI: Selector](#ui-selector) | ||
- [UI: Ask for Password](#ui-ask-for-password) | ||
- [Profile BASH script execution](#profile-bash-script-execution) | ||
- [Colors support in my terminal](#colors-support-in-my-terminal) | ||
|
||
## Roadmap | ||
|
||
|
@@ -21,10 +23,12 @@ | |
- [ ] Slack notifications helper scripts | ||
- [ ] Telemetry module (report metrics to CI or DataDog) | ||
- [ ] Globals module (declarative way of defining script dependencies to global environment variables) | ||
- [ ] Loggs monitoring documentation (different streams/files/tty for different information: info, debug, telemetry, dependencies) | ||
- [ ] Logs monitoring documentation (different streams/files/tty for different information: info, debug, telemetry, dependencies) | ||
|
||
## Local Dev Environment - Requirements | ||
|
||
![Bootstrap](docs/bootstrap.direnv.gif) | ||
|
||
- DirEnv - https://github.com/direnv/direnv | ||
- ShellFormat - https://github.com/mvdan/sh | ||
- ShellCheck - https://github.com/koalaman/shellcheck | ||
|
@@ -61,6 +65,22 @@ source ".scripts/_colors.sh" | |
echo -e "${cl_red}Hello World${cl_reset}" | ||
``` | ||
|
||
### Script Dependencies | ||
|
||
![Bootstrap](docs/bootstrap.direnv.gif) | ||
|
||
```bash | ||
source ".scripts/_dependencies.sh" | ||
|
||
dependency bash "5.*.*" "brew install bash" | ||
dependency direnv "2.*.*" "curl -sfL https://direnv.net/install.sh | bash" | ||
dependency shellspec "0.28.*" "brew install shellspec" | ||
optional kcov "42" "brew install kcov" | ||
dependency shellcheck "0.9.*" "curl -sS https://webi.sh/shellcheck | sh" | ||
dependency shfmt "3.*.*" "curl -sS https://webi.sh/shfmt | sh" | ||
dependency watchman "2023.07.*.*" "brew install watchman" | ||
``` | ||
|
||
### Logger | ||
|
||
```bash | ||
|
@@ -78,20 +98,6 @@ export DEBUG=*,-common # enable logger output for all tags except common | |
config:logger:Common "$@" # re-configure logger enable/disable for common tag | ||
``` | ||
|
||
### Dependencies | ||
|
||
```bash | ||
source ".scripts/_dependencies.sh" | ||
|
||
dependency bash "5.*.*" "brew install bash" | ||
dependency direnv "2.*.*" "curl -sfL https://direnv.net/install.sh | bash" | ||
dependency shellspec "0.28.*" "brew install shellspec" | ||
optional kcov "42" "brew install kcov" | ||
dependency shellcheck "0.9.*" "curl -sS https://webi.sh/shellcheck | sh" | ||
dependency shfmt "3.*.*" "curl -sS https://webi.sh/shfmt | sh" | ||
dependency watchman "2023.07.*.*" "brew install watchman" | ||
``` | ||
|
||
### Arguments Parsing | ||
|
||
```bash | ||
|
@@ -112,7 +118,7 @@ echo "Is --debug: $DEBUG" | |
parse:arguments "$@" | ||
``` | ||
|
||
### Common(s) Functions | ||
### Common(s) Functions And Inputs | ||
|
||
```bash | ||
source ".scripts/_commons.sh" | ||
|
@@ -128,21 +134,35 @@ echo "Extracted: ${new_value}" | |
# validate/confirm input parameter by user input | ||
# string | ||
# Yes/No | ||
``` | ||
|
||
### UI: Selector | ||
|
||
![Selector](docs/ui.selector.gif) | ||
|
||
# track execution time | ||
```bash | ||
# Select value from short list of choices | ||
declare -A -g connections && connections=(["d"]="production" ["s"]="cors-proxy:staging" ["p"]="cors-proxy:local") | ||
echo -n "Select connection type: " && tput civis # hide cursor | ||
selected=$(input:selector "connections") && echo "${cl_blue}${selected}${cl_reset}" | ||
``` | ||
|
||
## Deploy / GitHub Pages | ||
### UI: Ask for Password | ||
|
||
![Ask for Password](docs/ui.ask-for-password.gif) | ||
|
||
```bash | ||
# generate ssh key for gh-pages publishing | ||
# https://github.com/marketplace/actions/github-pages-action#%EF%B8%8F-create-ssh-deploy-key | ||
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f gh-pages -N "" | ||
source ".scripts/_commons.sh" | ||
|
||
# Usage: | ||
echo -n "Enter password: " | ||
password=$(input:readpwd) && echo "" && echo "Password: $password" | ||
``` | ||
|
||
## Profile BASH script execution | ||
|
||
![Profiler](docs/profiler.version-up.gif) | ||
|
||
```bash | ||
# print timestamp for each line of executed script | ||
PS4='+ $(gdate "+%s.%N ($LINENO) ")' bash -x bin/version-up.sh | ||
|
@@ -157,7 +177,14 @@ PS4='+ $(echo -n "$EPOCHREALTIME [$LINENO]: ")' bash -x bin/version-up.sh 2>trac | |
bin/profiler/profile.sh bin/version-up.sh | ||
``` | ||
|
||
src: https://itecnote.com/tecnote/r-performance-profiling-tools-for-shell-scripts/ | ||
- ref1: https://itecnote.com/tecnote/r-performance-profiling-tools-for-shell-scripts/ | ||
- ref2: https://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/ | ||
|
||
- https://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/ | ||
- | ||
## Colors support in my terminal | ||
|
||
![Terminal Colors](docs/terminal.colors.gif) | ||
|
||
```bash | ||
# print all colors for easier selection | ||
demos/demo.colors.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env bash | ||
|
||
# ESC[38:5:⟨n⟩m Select foreground color where n is a number from the table below | ||
# ESC[48:5:⟨n⟩m Select background color | ||
# "\033[38;5;%dm" "\033[48;5;%dm" "\033[0m" | ||
|
||
function report:colors() { | ||
local contrast=0 reset="" nl="" | ||
|
||
reset=$(printf "\033[0m") | ||
|
||
for ((i = 0; i < 256; i++)); do | ||
local mod8=$(((i + 1) % 8)) | ||
local mod6=$(((i - 15) % 6)) | ||
local c1=$((i > 231 && i < 244)) | ||
local c2=$((i < 17 && i % 8 < 2)) | ||
local c3=$((i > 16 && i < 232)) | ||
local c4=$(((i - 16) % 6 < (i < 100 ? 3 : 2))) | ||
local c5=$(((i - 16) % 36 < 15)) | ||
|
||
# Use conditions to set contrast | ||
contrast=16 && nl="" | ||
if [[ $c1 -eq 1 || $c2 -eq 1 ]] || [[ $c3 -eq 1 && $c4 -eq 1 && $c5 -eq 1 ]]; then contrast=7; fi | ||
|
||
if [ $i -lt 16 ] || [ $i -gt 231 ]; then | ||
[ $mod8 -eq 0 ] && nl=$'\n' | ||
else | ||
[ $mod6 -eq 0 ] && nl=$'\n' | ||
fi | ||
|
||
printf " \033[48;5;%dm\033[38;5;%dm C %03d %s%s" $i $contrast $i "$reset" "$nl" | ||
done | ||
} | ||
|
||
report:colors | ||
|
||
echo "" | ||
echo "Hints:" | ||
echo " - use command 'tput setab [0-255]' to change background color" | ||
echo " - use command 'tput setaf [0-255]' to change foreground color" | ||
echo " - use command 'tput op' to reset colors" | ||
echo "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2034 | ||
|
||
# include other scripts: _colors, _logger, _commons, _dependencies, _arguments | ||
scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../.scripts" | ||
# shellcheck disable=SC1090 source=../.scripts/_commons.sh | ||
source "$scripts_dir/_commons.sh" | ||
|
||
# Usage: | ||
echo -n "Enter password: " | ||
password=$(input:readpwd) && echo "" && echo "Password: $password" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2034 | ||
|
||
# include other scripts: _colors, _logger, _commons, _dependencies, _arguments | ||
scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../.scripts" | ||
# shellcheck disable=SC1090 source=../.scripts/_commons.sh | ||
source "$scripts_dir/_commons.sh" | ||
|
||
# Usage: | ||
declare -A -g connections && connections=(["d"]="production" ["s"]="cors-proxy-staging" ["p"]="cors-proxy-local") | ||
echo -n "Select connection type: " && tput civis # hide cursor | ||
selected=$(input:selector "connections") && echo "${cl_blue}$selected${cl_reset}" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.