-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[completion] Three improvements for bash_completion.
- Show warning locations for arithmetic errors. This required threading an arena through. - This led me to notice a bug in [ evaluation, which is now fixed with a spec test. We weren't passing exec_opts in the [ case. - It shows that [ is stricter than [[ ! - bash-completion uses printf -v %s and %q, so I wrote some spec tests for these features. However I just replaced these invocations with something like: eval "$3=$ref" So for now OSH doesn't need prinf -v.
- Loading branch information
Andy Chu
committed
Sep 29, 2018
1 parent
f3d9c30
commit d9aa20b
Showing
15 changed files
with
163 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# printf | ||
# bash-completion uses this odd printf -v construction. It seems to mostly use | ||
# %s and %q though. | ||
# | ||
# %s should just be | ||
# declare $var='val' | ||
# | ||
# NOTE: | ||
# /usr/bin/printf %q "'" seems wrong. | ||
# $ /usr/bin/printf %q "'" | ||
# ''\''' | ||
# | ||
# I suppose it is technically correct, but it looks very ugly. | ||
|
||
#### printf -v %s | ||
var=foo | ||
printf -v $var %s 'hello there' | ||
argv "$foo" | ||
## STDOUT: | ||
['hello there'] | ||
## END | ||
|
||
#### printf -v %q | ||
var=foo | ||
printf -v $var %q '"quoted" with spaces and \' | ||
argv "$foo" | ||
## STDOUT: | ||
['\\"quoted\\"\\ with\\ spaces\\ and\\ \\\\'] | ||
## END | ||
|
||
#### declare instead of %s | ||
var=foo | ||
declare $var='hello there' | ||
argv "$foo" | ||
## STDOUT: | ||
['hello there'] | ||
## END | ||
|
||
#### declare instead of %q | ||
var=foo | ||
val='"quoted" with spaces and \' | ||
# I think this is bash 4.4 only. | ||
declare $var="${val@Q}" | ||
argv "$foo" | ||
## STDOUT: | ||
['hello there'] | ||
## END | ||
|
||
#### printf -v dynamic scope | ||
# OK so printf is like assigning to a var. | ||
# printf -v foo %q "$bar" is like | ||
# foo=${bar@Q} | ||
dollar='dollar' | ||
f() { | ||
local mylocal=foo | ||
printf -v dollar %q '$' # assign foo to a quoted dollar | ||
printf -v mylocal %q 'mylocal' | ||
echo dollar=$dollar | ||
echo mylocal=$mylocal | ||
} | ||
echo dollar=$dollar | ||
echo -- | ||
f | ||
echo -- | ||
echo dollar=$dollar | ||
echo mylocal=$mylocal | ||
## STDOUT: | ||
dollar=dollar | ||
-- | ||
dollar=\$ | ||
mylocal=mylocal | ||
-- | ||
dollar=\$ | ||
mylocal= | ||
## END | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters