-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require fish 3.2.0, update variable preview extraction (#146)
Now that fish 3.2.0 has been out for almost a month, it's time to make it the minimum required version. Thankfully, the only new expectation made by the plugin is around the new `set --show` format. It has been simplified (see fish-shell/fish-shell#6944) such that the search shell variable preview logic, which uses `set --show`, can be greatly simplified. While this is technically backwards incompatible with fish 3.1.2, the only negative consequence for users who haven't upgraded should be that their variable preview won't be as clean and condensed but will still have all the essentials.
- Loading branch information
Showing
4 changed files
with
19 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,15 @@ | ||
# helper function for __fzf_search_shell_variables | ||
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." | ||
# Extract only the lines that begin with... | ||
# $variable_name: set | ||
# ...or... | ||
# $variable_name[ | ||
string match --entire --regex "^\\\$$variable_name(?:: set|\[)" <$set_show_output | | ||
# Extract only the lines about the variable, all of which begin with either | ||
# $variable_name: ...or... $variable_name[ | ||
string match --regex "^\\\$$variable_name(?::|\[).*" <$set_show_output | | ||
|
||
# Strip the variable name from the scope info, replacing... | ||
# $variable_name: set in global scope | ||
# ...with... | ||
# set in global scope | ||
string replace --regex "^\\\$$variable_name: " '' | | ||
# Strip the variable name prefix, including ": " for scope info lines | ||
string replace --regex "^\\\$$variable_name(?:: )?" '' | | ||
|
||
# From the lines of values, keep only the index and value, replacing... | ||
# $variable_name[1]: length=14 value=|variable_value| | ||
# Distill the lines of values, replacing... | ||
# [1]: |value| | ||
# ...with... | ||
# [1] variable_value | ||
string replace --regex "^\\\$$variable_name(\[\d+\]).+?\|(.+)\|\$" '\$1 \$2' | ||
|
||
# Final output example for $PATH: | ||
# set in global scope, unexported, with 5 elements | ||
# [1] /Users/patrickf/.config/fish/functions | ||
# [2] /usr/local/Cellar/fish/3.1.2/etc/fish/functions | ||
# [3] /usr/local/Cellar/fish/3.1.2/share/fish/vendor_functions.d | ||
# [4] /usr/local/share/fish/vendor_functions.d | ||
# [5] /usr/local/Cellar/fish/3.1.2/share/fish/functions | ||
# [1] value | ||
string replace --regex ": \|(.*)\|" ' \$1' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# example of when this actually happens: TERM_PROGRAM and TERM_PROGRAM_VERSION | ||
set prefix 1 | ||
set prefixed 2 | ||
set actual (__fzf_extract_var_info prefix (set --show | psub) | string collect) | ||
set expected "set in global scope, unexported, with 1 elements"\n"[1] 1" | ||
@test "var whose name is the prefix of another var" "$actual" = "$expected" |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
set variable "| a | b | c | d |" | ||
set variable "| a | b | c | d |" "1 | 2 | 3" | ||
set actual (__fzf_extract_var_info variable (set --show | psub) | string collect) | ||
set expected "set in global scope, unexported, with 1 elements"\n"[1] | a | b | c | d |" | ||
set expected "set in global scope, unexported, with 2 elements"\n"[1] $variable[1]"\n"[2] $variable[2]" | ||
@test "vars containing '|'" "$actual" = "$expected" |