Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.2: Rewrite "info variables -p" #2

Closed
wants to merge 1 commit into from

Conversation

jansorg
Copy link
Collaborator

@jansorg jansorg commented Feb 13, 2024

Rewrite info variables to support line feeds and spaces in values, array keys and array values.

Bash's typeset -p escapes line feeds and other special characters and wraps such values in $''. Array keys with spaces are wrapped into "". Previously, $'' was kept but the escape codes were resolved. The escape codes are now retained in the output of info variables to show each variable and its value on a single line. This is to improve readability and help programmatic parsing of the variable listing.

@jansorg jansorg changed the title Rewrite "info variables -p" 5.2: Rewrite "info variables -p" Feb 13, 2024
if ((_Dbg_typeset_filtered == 1)); then
# grepping for '=' to only accept variables with a value
mapfile -t _Dbg_var_names < <(declare -p $_Dbg_typeset_flags |
grep '=' |
Copy link
Collaborator

@rocky rocky Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously I have been shying away from assuming POSIX command-line arguments. MS windows for example in its native mode might not have "cut" and "grep -v" and "sort".

Creating this pipeline as a bash or zsh function should be doable. And we can test that in isolation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't think about Windows. I'll try to come up with equivalent Bash-only code...

…array keys and array values.

Bash's "typeset -p" escapes line feeds and other special characters and wraps such values in $''. Array keys with spaces are wrapped into "".
Previously, $'' was kept but the escape codes were resolved. The escape codes are now retained in the output of "info variables" to show each variable and its value on a single line. This is to improve readability and help programmatic parsing of the variable listing.
@jansorg jansorg force-pushed the 5.1-jansorg-info-variables branch from 2a19158 to d1fb20c Compare February 14, 2024 15:24
@jansorg
Copy link
Collaborator Author

jansorg commented Jun 17, 2024

Superseded by #23

@jansorg jansorg closed this Jun 17, 2024
@jansorg jansorg deleted the 5.1-jansorg-info-variables branch June 17, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants