Skip to content

Commit

Permalink
Merge pull request #587 from DannyBen/add/var-aliases
Browse files Browse the repository at this point in the history
Add support for declaring aliases for internal global variables
  • Loading branch information
DannyBen authored Dec 27, 2024
2 parents a815867 + 5264d51 commit fd54157
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/bashly/libraries/settings/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,18 @@ enable_view_markers: development
enable_inspect_args: development
enable_deps_array: always
enable_env_var_names_array: always


#-------------------------------------------------------------------------------
# SCRIPTING OPTIONS
#-------------------------------------------------------------------------------

# These are the public global variables available for use in your partial
# scripts. Adding a new name here will create a reference variable using
# `declare -gn`, allowing you to access the original variable under the new
# name in addition to its original name.
var_aliases:
args: ~
other_args: ~
deps: ~
env_var_names: ~
7 changes: 6 additions & 1 deletion lib/bashly/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class << self
:strict,
:tab_indent,
:target_dir,
:usage_colors
:usage_colors,
:var_aliases
)

def commands_dir
Expand Down Expand Up @@ -133,6 +134,10 @@ def usage_colors
@usage_colors ||= get :usage_colors
end

def var_aliases
@var_aliases ||= get :var_aliases
end

private

def get(key)
Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/views/command/run.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ if has_unique_args_or_flags?
> declare -g -A unique_lookup=()
end

>
Settings.var_aliases.each do |original, refname|
if refname
> declare -gn {{ refname }}={{ original }}
end
end
>
> normalize_input "$@"
> parse_requirements "${input[@]}"

Expand Down

0 comments on commit fd54157

Please sign in to comment.