|
34 | 34 | # if the user hasn't disabled prompt injection, |
35 | 35 | # and we aren't already injecting maws_profile: |
36 | 36 | if [[ -z $MAWS_PROMPT_DISABLE && $PS1 != *'$(maws_profile)' ]]; then |
37 | | - # the original behavior is to always prefix and never suffix, |
38 | | - # so we default to that before overriding it in specific cases. |
39 | | - MAWS_PROMPT_PREFIX=" " |
40 | | - MAWS_PROMPT_SUFFIX="" |
| 37 | + # by default, we prefix but not suffix; good for example '\w\$', |
| 38 | + # but has to be overridden below for various whitespace cases. |
| 39 | + MAWS_PROMPT_PREFIX=" " MAWS_PROMPT_SUFFIX="" |
41 | 40 | # maws_profile is missing from PS1 |
42 | 41 | if [[ $PS1 == *'\$ ' ]]; then |
43 | 42 | # prompt ends with dynamic '\$ ' |
44 | | - if [[ $PS1 == *' \$ ' ]]; then |
45 | | - # the original prompt surrounds the final '\$' with whitespace, |
46 | | - # so we surround the substitution with whitespace to maintain that. |
47 | | - MAWS_PROMPT_PREFIX="" |
48 | | - MAWS_PROMPT_SUFFIX=" " |
49 | | - else |
50 | | - # the original prompt doesn't have whitespace before the final '\$', |
51 | | - # so we only prefix but not suffix with whitespace to maintain that. |
52 | | - MAWS_PROMPT_PREFIX=" " |
53 | | - MAWS_PROMPT_SUFFIX="" |
54 | | - fi |
| 43 | + # if the original prompt surrounds the final '\$' with whitespace, |
| 44 | + # we surround the substitution with whitespace to maintain that. |
| 45 | + [[ $PS1 == *' \$ ' ]] && MAWS_PROMPT_PREFIX="" MAWS_PROMPT_SUFFIX=" " |
55 | 46 | # inject our substitution before the original '$ ' |
56 | 47 | PS1="${PS1%\\$ }\$(maws_profile)\\$ " |
57 | 48 | elif [[ $PS1 == *'$ ' ]]; then |
58 | 49 | # prompt ends with hard-coded '$ ' |
59 | | - if [[ $PS1 == *' $ ' ]]; then |
60 | | - # the original prompt surrounds the final '$' with whitespace, |
61 | | - # so we surround the substitution with whitespace to maintain that. |
62 | | - MAWS_PROMPT_PREFIX="" |
63 | | - MAWS_PROMPT_SUFFIX=" " |
64 | | - else |
65 | | - # the original prompt doesn't have whitespace before the final '$ ', |
66 | | - # so we only prefix but not suffix with whitespace to maintain that. |
67 | | - MAWS_PROMPT_PREFIX=" " |
68 | | - MAWS_PROMPT_SUFFIX="" |
69 | | - fi |
| 50 | + # if the original prompt surrounds the final '$' with whitespace, |
| 51 | + # we surround the substitution with whitespace to maintain that. |
| 52 | + [[ $PS1 == *' $ ' ]] && MAWS_PROMPT_PREFIX="" MAWS_PROMPT_SUFFIX=" " |
70 | 53 | # inject our substitution before the original '$ ' |
71 | 54 | PS1="${PS1%\$ }\$(maws_profile)\$ " |
72 | 55 | elif [[ $PS1 == *'%# ' ]]; then |
73 | 56 | # prompt ends with dynamic '%# ' |
74 | | - if [[ $PS1 == *' %# ' ]]; then |
75 | | - # the original prompt surrounds the final '$' with whitespace, |
76 | | - # so we only suffix bot not prefix with whitespace to maintain that. |
77 | | - MAWS_PROMPT_PREFIX="" |
78 | | - MAWS_PROMPT_SUFFIX=" " |
79 | | - else |
80 | | - # the original prompt doesn't have whitespace before the final '$ ', |
81 | | - # so we only prefix but not suffix with whitespace to maintain that. |
82 | | - MAWS_PROMPT_PREFIX=" " |
83 | | - MAWS_PROMPT_SUFFIX="" |
84 | | - fi |
| 57 | + # if the original prompt surrounds the final '$' with whitespace, |
| 58 | + # we only suffix bot not prefix with whitespace to maintain that. |
| 59 | + [[ $PS1 == *' %# ' ]] && MAWS_PROMPT_PREFIX="" MAWS_PROMPT_SUFFIX=" " |
85 | 60 | # inject our substitution before the original '%# ' |
86 | 61 | PS1="${PS1%\%# }\$(maws_profile)%# " |
87 | 62 | else |
88 | 63 | # we're the last entry in the prompt, so we don't need extra whitespace. |
89 | | - MAWS_PROMPT_SUFFIX="" |
90 | | - if [[ $PS1 == *' ' ]]; then |
91 | | - # the original prompt ends with whitespace, |
92 | | - # so we don't need to prefix whitespace ourselves. |
93 | | - MAWS_PROMPT_PREFIX="" |
94 | | - else |
95 | | - # the original prompt doesn't end with whitespace, |
96 | | - # so we prefix whitespace ourselves. |
97 | | - MAWS_PROMPT_PREFIX=" " |
98 | | - fi |
| 64 | + # if the original prompt ends with whitespace, |
| 65 | + # we don't need to prefix whitespace ourselves. |
| 66 | + [[ $PS1 == *' ' ]] && MAWS_PROMPT_PREFIX="" |
99 | 67 | # inject our substitution before the original '%# ' |
100 | 68 | PS1="${PS1}\$(maws_profile) " |
101 | 69 | fi |
|
0 commit comments