Skip to content

Commit

Permalink
fix(mr): avoid ${var/pat/$'...'} for compat42 in bash >= 4.3
Browse files Browse the repository at this point in the history
In bash >= 4.3 with `shopt -s compat42` enabled, ${var/pat/$'...'}
would produce extra single quotations around the replacements.  The mr
completion uses $'\n' to insert delimiter, but the delimiter does not
need to be the newline in this context.  In this patch, we can instead
insert a space.
  • Loading branch information
akinomyoga committed Dec 24, 2023
1 parent 0afc2e4 commit b5ae5fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion completions/mr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _comp_cmd_mr()
done
)"
# Split [online|offline] and remove `action` placeholder.
commands="${commands//@(action|[\[\|\]])/$'\n'}"
commands="${commands//@(action|[\[\|\]])/ }"
# Add standard aliases.
commands="${commands} ci co ls"
_comp_split commands "$commands"
Expand Down
3 changes: 3 additions & 0 deletions test/runLint
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ gitgrep "$cmdstart"'((set|shopt)\s+[+-][a-z]+\s+posix\b|(local\s+)?POSIXLY_CORRE

gitgrep '\$\{([^{}\n]|\{.*\})+/([^{}\n]|\{.*\})+/([^{}"\n]|\{.*\})*\$.*\}' \
'$rep of ${var/pat/$rep} needs to be double-quoted for shopt -s patsub_replacement (bash >= 5.2)'

gitgrep '"([^"\n]|\\.)*\$\{([^{}\n]|\{.*\})+/([^{}\n]|\{.*\})+/([^{}"\n]|\{.*\})*"([^{}"\n]|\{.*\})*\$.*\}' \
'$rep of "${var/pat/"$rep"}" should not be quoted for bash-4.2 or shopt -s compat42 (bash >= 4.3)'

0 comments on commit b5ae5fa

Please sign in to comment.