barthy-koeln/bash-echolorized

美观且简洁的bash输出

资助包维护!
barthy-koeln

安装: 30

依赖: 1

建议者: 0

安全: 0

星星: 2

观察者: 2

分支: 0

开放问题: 0

语言:Shell

1.0.0 2021-09-28 14:53 UTC

This package is auto-updated.

Last update: 2024-09-29 05:49:13 UTC


README

此库帮助您编写更漂亮的bash脚本,用于CI/CD、git钩子等。

安装

您可以通过composer为PHP项目或npm/yarn为浏览器/Node项目要求此包。

composer require --dev barthy-koeln/bash-echolorized
yarn add -D bash-echolorized

导入与使用

如果通过composer要求此包

#!/usr/bin/env bash

DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")

# if required via composer
source "$DIR/vendor/bin/echolorized"

# if required via yarn/npm
source "$DIR/node_modules/.bin/echolorized"

基本使用

e_info "Checking Twig Code"
e_success "All done"
e_warning "Careful!"
e_error "That did NOT work."

输出

Baisc usage output

高级使用(git pre-commit示例)

colored_output "$GREEN" "\n[EXECUTING PRE COMMIT HOOK]"
e_info "USE ${YELLOW}git commit -n -m 'your message'${RESET} to bypass these checks."
echo -e ''

e_info "Checking YAML config"

if ! "$DIR/console" --quiet lint:yaml config; then
  e_error "Error in YAML config. Run ${YELLOW}bin/console lint:yaml${RESET} to check.\n"
  exit 1
fi

e_success "All good, staging additional changes.\n"
git update-index --again

输出

Advanced usage output with error Advanced usage output with success

tagged_output "$YELLOW" "BUILD" "Fetching dependencies"
tagged_output "$YELLOW" "BUILD" "Building bundles"
tagged_output "$YELLOW" "BUILD" "Making binaries executable"
tagged_output "$GREEN" "TEST" "Tests are green" " "

tagged_output "$RED" "¯\_(ツ)_/¯" "Dunno..?\n" "\n"

tagged_output "$YELLOW" "DIRECTORY" "src"
tagged_output "$GREEN" "FILE" "README.md" "\t"
tagged_output "$GREEN" "FILE" "package.json" "\t"
tagged_output "$GREEN" "FILE" "composer.json" "\t"

输出

Advanced usage output with error

方法

colored_output() {
  # $1: Color
  # $2: Text
}
tagged_output() {
  # $1: Color
  # $2: Tag
  # $3: After tag
  # $4: Before tag (tabs, newlines, ...)
}