Skip to content

Commit 20ec3e4

Browse files
authored
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.
1 parent 83cb78f commit 20ec3e4

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ _The prompt used in the screencasts was created using [IlanCosman/tide][]._
6363

6464
## Installation
6565

66-
First, make sure you're using [Fish][] `3.1.2` or newer.
66+
First, make sure you're using [Fish][] `3.2.0` or newer.
6767

6868
```console
6969
$ fish --version
70-
fish, version 3.1.2
70+
fish, version 3.2.0
7171
```
7272

7373
Next, install with [Fisher][].

functions/__fzf_extract_var_info.fish

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
# helper function for __fzf_search_shell_variables
22
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 |
86

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(?:: )?" '' |
149

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|
1712
# ...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'
2815
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# example of when this actually happens: TERM_PROGRAM and TERM_PROGRAM_VERSION
2+
set prefix 1
3+
set prefixed 2
4+
set actual (__fzf_extract_var_info prefix (set --show | psub) | string collect)
5+
set expected "set in global scope, unexported, with 1 elements"\n"[1] 1"
6+
@test "var whose name is the prefix of another var" "$actual" = "$expected"
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set variable "| a | b | c | d |"
1+
set variable "| a | b | c | d |" "1 | 2 | 3"
22
set actual (__fzf_extract_var_info variable (set --show | psub) | string collect)
3-
set expected "set in global scope, unexported, with 1 elements"\n"[1] | a | b | c | d |"
3+
set expected "set in global scope, unexported, with 2 elements"\n"[1] $variable[1]"\n"[2] $variable[2]"
44
@test "vars containing '|'" "$actual" = "$expected"

0 commit comments

Comments
 (0)