| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Investigation of https://github.com/oilshell/oil/issues/268
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # ./plugins-and-shell-state.sh <function name>
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 | # Corrupts shell state in OSH.
|
| 11 | #
|
| 12 | # bash has save_parser_state and restore_parser_state, and bizarrely the exit
|
| 13 | # code and pipe status are part of that!
|
| 14 | #
|
| 15 | # OK variables are protected because they're in a subshell.
|
| 16 |
|
| 17 | PS1='$(echo ${MUTATED=hi }; echo $MUTATED; exit 42) $(echo $?)\$ '
|
| 18 |
|
| 19 | foo() { argv foo "$@"; }
|
| 20 | complete_foo() {
|
| 21 | local first=$1
|
| 22 | local cur=$2
|
| 23 | local prev=$3
|
| 24 |
|
| 25 | for candidate in one two three bin; do
|
| 26 | if [[ $candidate == $cur* ]]; then
|
| 27 | COMPREPLY+=("$candidate")
|
| 28 | fi
|
| 29 | done
|
| 30 |
|
| 31 | COMP_MUTATED='mutated by completion plugin' # visible afterward
|
| 32 |
|
| 33 | return 23 # doesn't appear anywhere?
|
| 34 | }
|
| 35 | complete -F complete_foo foo
|