|
1 | 1 | # helper function for __fzf_search_shell_variables
|
2 | 2 | function __fzf_extract_var_info --argument-names variable_name set_show_output --description "Extract and reformat lines pertaining to \$variable_name from \$set_show_output."
|
3 |
| - # Extract only the lines that begin with... |
4 |
| - # $variable_name: set |
5 |
| - # ...or... |
6 |
| - # $variable_name[ |
7 |
| - string match --entire --regex "^\\\$$variable_name(?:: set|\[)" <$set_show_output | |
| 3 | + # Extract only the lines about the variable, all of which begin with either |
| 4 | + # $variable_name: ...or... $variable_name[ |
| 5 | + string match --regex "^\\\$$variable_name(?::|\[).*" <$set_show_output | |
8 | 6 |
|
9 |
| - # Strip the variable name from the scope info, replacing... |
10 |
| - # $variable_name: set in global scope |
11 |
| - # ...with... |
12 |
| - # set in global scope |
13 |
| - string replace --regex "^\\\$$variable_name: " '' | |
| 7 | + # Strip the variable name prefix, including ": " for scope info lines |
| 8 | + string replace --regex "^\\\$$variable_name(?:: )?" '' | |
14 | 9 |
|
15 |
| - # From the lines of values, keep only the index and value, replacing... |
16 |
| - # $variable_name[1]: length=14 value=|variable_value| |
| 10 | + # Distill the lines of values, replacing... |
| 11 | + # [1]: |value| |
17 | 12 | # ...with...
|
18 |
| - # [1] variable_value |
19 |
| - string replace --regex "^\\\$$variable_name(\[\d+\]).+?\|(.+)\|\$" '\$1 \$2' |
20 |
| - |
21 |
| - # Final output example for $PATH: |
22 |
| - # set in global scope, unexported, with 5 elements |
23 |
| - # [1] /Users/patrickf/.config/fish/functions |
24 |
| - # [2] /usr/local/Cellar/fish/3.1.2/etc/fish/functions |
25 |
| - # [3] /usr/local/Cellar/fish/3.1.2/share/fish/vendor_functions.d |
26 |
| - # [4] /usr/local/share/fish/vendor_functions.d |
27 |
| - # [5] /usr/local/Cellar/fish/3.1.2/share/fish/functions |
| 13 | + # [1] value |
| 14 | + string replace --regex ": \|(.*)\|" ' \$1' |
28 | 15 | end
|
0 commit comments