Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 12 additions & 1 deletion examples/colors/src/lib/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
## Color output will be disabled if `NO_COLOR` environment variable is set
## in compliance with https://no-color.org/
##
## In case you wish to enable auto detection for color output based on the
## terminal being interactive (TTY), call `enable_auto_colors` in your
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
##
enable_auto_colors() {
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
NO_COLOR=1
fi
}

print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
if [[ "${NO_COLOR:-}" == "" ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
Expand Down
13 changes: 12 additions & 1 deletion examples/dependencies-alt/src/lib/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
## Color output will be disabled if `NO_COLOR` environment variable is set
## in compliance with https://no-color.org/
##
## In case you wish to enable auto detection for color output based on the
## terminal being interactive (TTY), call `enable_auto_colors` in your
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
##
enable_auto_colors() {
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
NO_COLOR=1
fi
}

print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
if [[ "${NO_COLOR:-}" == "" ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
Expand Down
13 changes: 12 additions & 1 deletion examples/dependencies/src/lib/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
## Color output will be disabled if `NO_COLOR` environment variable is set
## in compliance with https://no-color.org/
##
## In case you wish to enable auto detection for color output based on the
## terminal being interactive (TTY), call `enable_auto_colors` in your
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
##
enable_auto_colors() {
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
NO_COLOR=1
fi
}

print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
if [[ "${NO_COLOR:-}" == "" ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.2
.\"
.TH "download" "1" "December 2024" "Version 0.1.0" "Sample application"
.TH "download" "1" "January 2025" "Version 0.1.0" "Sample application"
.SH NAME
\f[B]download\f[R] \- Sample application
.SH SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% December 2024
% January 2025

NAME
==================================================
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/libraries/colors/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
## Color output will be disabled if `NO_COLOR` environment variable is set
## in compliance with https://no-color.org/
##
## In case you wish to enable auto detection for color output based on the
## terminal being interactive (TTY), call `enable_auto_colors` in your
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
##
enable_auto_colors() {
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
NO_COLOR=1
fi
}

print_in_color() {
local color="$1"
shift
Expand Down
8 changes: 8 additions & 0 deletions lib/bashly/libraries/libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ colors:
files:
- source: "colors/colors.sh"
target: "%{user_lib_dir}/colors.%{user_ext}"
post_install_message: |
The colors library supports the g`NO_COLOR` standard out of the box.

In case you wish to also enable automatic output of colors based on the
terminal being interactive (TTY), call g`enable_auto_colors` in your
g`src/initialize.sh`. You may run the following command to add this file:

m`$ bashly add hooks`

completions:
help: Generate a bash completions function.
Expand Down
9 changes: 9 additions & 0 deletions spec/approvals/cli/add/colors
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
created spec/tmp/src/lib/colors.sh

The colors library supports the NO_COLOR standard out of the box.

In case you wish to also enable automatic output of colors based on the
terminal being interactive (TTY), call enable_auto_colors in your
src/initialize.sh. You may run the following command to add this file:

$ bashly add hooks

9 changes: 9 additions & 0 deletions spec/approvals/examples/colors
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
+ bashly add colors --force
created src/lib/colors.sh

The colors library supports the NO_COLOR standard out of the box.

In case you wish to also enable automatic output of colors based on the
terminal being interactive (TTY), call enable_auto_colors in your
src/initialize.sh. You may run the following command to add this file:

$ bashly add hooks

+ bashly generate
creating user files in src
skipped src/root_command.sh (exists)
Expand Down
9 changes: 9 additions & 0 deletions spec/approvals/examples/dependencies
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
+ bashly add colors
created src/lib/colors.sh

The colors library supports the NO_COLOR standard out of the box.

In case you wish to also enable automatic output of colors based on the
terminal being interactive (TTY), call enable_auto_colors in your
src/initialize.sh. You may run the following command to add this file:

$ bashly add hooks

+ bashly generate
creating user files in src
created src/download_command.sh
Expand Down
9 changes: 9 additions & 0 deletions spec/approvals/examples/dependencies-alt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
+ bashly add colors
created src/lib/colors.sh

The colors library supports the NO_COLOR standard out of the box.

In case you wish to also enable automatic output of colors based on the
terminal being interactive (TTY), call enable_auto_colors in your
src/initialize.sh. You may run the following command to add this file:

$ bashly add hooks

+ bashly generate
creating user files in src
created src/download_command.sh
Expand Down
2 changes: 1 addition & 1 deletion spec/approvals/examples/render-mandoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ ISSUE TRACKER
AUTHORS
Lana Lang.

Version 0.1.0 December 2024 download(1)
Version 0.1.0 January 2025 download(1)
9 changes: 9 additions & 0 deletions spec/approvals/fixtures/lib-custom-path
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ run ./cli --help to test your bash script
created src/my-libz/sample_function.sh
+ bundle exec bashly add colors
created src/my-libz/colors.sh

The colors library supports the NO_COLOR standard out of the box.

In case you wish to also enable automatic output of colors based on the
terminal being interactive (TTY), call enable_auto_colors in your
src/initialize.sh. You may run the following command to add this file:

$ bashly add hooks

+ bundle exec bashly generate
creating user files in src
skipped src/root_command.sh (exists)
Expand Down
9 changes: 9 additions & 0 deletions spec/approvals/fixtures/partials-extension
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ created ./cli
run ./cli --help to test your bash script
+ bundle exec bashly add colors
created src/lib/colors.bash

The colors library supports the NO_COLOR standard out of the box.

In case you wish to also enable automatic output of colors based on the
terminal being interactive (TTY), call enable_auto_colors in your
src/initialize.sh. You may run the following command to add this file:

$ bashly add hooks

+ bundle exec bashly add completions
created src/lib/send_completions.bash

Expand Down
2 changes: 2 additions & 0 deletions spec/bashly/library_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

describe '#post_install_message' do
context 'when the library has no configured message' do
let(:name) { :config }

it 'returns nil' do
expect(subject.post_install_message).to be_nil
end
Expand Down
Loading