I need help understanding what the following code in this documentation means.
LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#} LBUFFER+=${abbreviations[$MATCH]:-$MATCH} I learned that LBUFFER contains the left from the cursor. However, there are 3 things that confuse me.
- What is the
%%doing? Is it escaping%? - What does
(#m)[_a-zA-Z0-9]#do? Is it something likem/[_a-zA-Z0-9]/in Perl? If so, what is done to the matched string? - What is the
:-part doing in the second line?
Thanks.
1 Answer
${a%%b}removes the longest occurrence ofb(which can be a regular expression), froma.[_a-zA-Z0-9]#is a regular expression matching an alphanumeric character (as indicated by the stuff between[]) zero or more times (specified by the#glob operator)(#m)populates the$MATCHvariable after evaluating the previous regular expression.The combination of 1, 2, and 3 means that the stretch of alphanumeric characters at the end of the
$LBUFFERis deleted and stored in$MATCH.${a:-b}makesaequal tobonly ifais not defined.
If you want to learn more, take a look at the expansion chapter of the zsh manual.
2