Skip to content
Open
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
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" "November 2025" "Version 0.1.0" "Sample application"
.TH "download" "1" "December 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
% November 2025
% December 2025

NAME
==================================================
Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/concerns/renderable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def user_file_exist?(file)
File.exist? user_file_path(file)
end

# Returns a wrapped, indented and sanitized string
# Designed to place help and example messages inside bash's 'printf'
def user_string(text, indent: 0)
wrap = Settings.word_wrap - indent
text.wrap(wrap).indent(indent).sanitize_for_print
end

private

def view_path(view)
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/extensions/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def to_path
tr(' ', '/').downcase
end

def wrap(length = 80)
def wrap(length)
strip!
split("\n").collect! do |line|
if line.length > length
Expand Down
3 changes: 3 additions & 0 deletions lib/bashly/libraries/settings/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ strict: false
# (every 2 leading spaces will be converted to a tab character)
tab_indent: false

# Set the character width used to wrap help and example messages
word_wrap: 80

# Choose a post-processor for the generated script:
# formatter: internal # Use Bashly’s built-in formatter (removes extra newlines)
# formatter: external # Run the external command `shfmt --case-indent --indent 2`
Expand Down
7 changes: 6 additions & 1 deletion lib/bashly/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class << self
:tab_indent,
:target_dir,
:usage_colors,
:var_aliases
:var_aliases,
:word_wrap
)

def commands_dir
Expand Down Expand Up @@ -173,6 +174,10 @@ def var_aliases
@var_aliases ||= get :var_aliases
end

def word_wrap
@word_wrap ||= get :word_wrap
end

private

def get(key)
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/views/argument/usage.gtx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= view_marker

> printf " %s\n" "{{ label.color(:arg) }}"
> printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
> printf "{{ user_string help, indent: 4 }}\n"

if allowed
> printf " %s\n" "{{ strings[:allowed] % { values: allowed.join(', ') } }}"
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/views/command/examples_on_error.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ if Settings.show_examples_on_error && examples

> printf "{{ strings[:examples_caption_on_error] }}\n" >&2
examples.each do |example|
> printf "{{ example.wrap(78).indent(2).sanitize_for_print }}\n" >&2
> printf "{{ user_string example, indent: 2 }}\n" >&2
end
end
2 changes: 1 addition & 1 deletion lib/bashly/views/command/usage.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ else
= help_header_override.indent 4
else
> printf "{{ full_name }}\n\n"
> printf "{{ help.wrap(78).indent(2).sanitize_for_print }}\n\n"
> printf "{{ user_string help, indent: 2 }}\n\n"
end
> else
> printf "{{ caption_string.sanitize_for_print }}\n\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/views/command/usage_args.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end
if catch_all.help
>
> echo " {{ catch_all.label }}"
> printf "{{ catch_all.help.wrap(76).indent(4).sanitize_for_print }}\n"
> printf "{{ user_string catch_all.help, indent: 4 }}\n"
> echo
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/views/command/usage_examples.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> printf "%s\n" "{{ strings[:examples].color(:caption) }}"

examples.each do |example|
> printf "{{ example.wrap(78).indent(2).sanitize_for_print }}\n"
> printf "{{ user_string example, indent: 2 }}\n"
end

> echo
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/views/environment_variable/usage.gtx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= view_marker

> printf " %s\n" "{{ usage_string(extended: true).color(:environment_variable) }}"
> printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
> printf "{{ user_string help, indent: 4 }}\n"

if allowed
> printf " %s\n" "{{ strings[:allowed] % { values: allowed.join(', ') } }}"
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/views/flag/usage.gtx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= view_marker

> printf " %s\n" "{{ usage_string(extended: true).color(:flag) }}"
> printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
> printf "{{ user_string help, indent: 4 }}\n"

if allowed
> printf " %s\n" "{{ strings[:allowed] % { values: allowed.join(', ') } }}"
Expand Down
6 changes: 6 additions & 0 deletions schemas/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
"type": "boolean",
"default": false
},
"word_wrap": {
"title": "word wrap",
"description": "Configure the character width used to wrap help and example messages\nhttps://bashly.dev/usage/settings/#word_wrap",
"type": "integer",
"default": 80
},
"compact_short_flags": {
"title": "compact short flags",
"description": "Whether to expand -abc to -a -b -c in the input line\nhttps://bashly.dev/usage/settings/#compact_short_flags",
Expand Down
7 changes: 7 additions & 0 deletions support/schema/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ properties:
https://bashly.dev/usage/settings/#tab_indent
type: boolean
default: false
word_wrap:
title: word wrap
description: |-
Configure the character width used to wrap help and example messages
https://bashly.dev/usage/settings/#word_wrap
type: integer
default: 80
compact_short_flags:
title: compact short flags
description: |-
Expand Down