Skip to content

Commit 76cadcb

Browse files
committed
Use single curly brace according to fzf --preview documentation
The fzf documentation says that to use the output of each line inside the preview command, the placeholders should be of the form `{[0-9]+}`. > Also, \fB{q}\fR is replaced to the current query string, and \fB{n}\fR > is replaced to zero-based ordinal index of the line. Use \fB{+n}\fR if > you want all index numbers when multiple lines are selected. > -- https://github.com/junegunn/fzf/blob/master/man/man1/fzf.1#L363-L365 https://github.com/junegunn/fzf The preview commands generated by git-fzf right now use `{{[0-9]+}}` (note the wrapping with the extra curly brace). I am not able to use `{{1}}` to preview with fzf version 0.17.5 or fzf version 0.18. I can't find any documentation about whether this was a breaking change inside of fzf, I can't find any reference to `{{.}}` anywhere in the [changelog][1]. [1]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md
1 parent 648987e commit 76cadcb

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

internal/command/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func newDiffCli(gitOptions []string, fzfQuery string) (*diffCli, error) {
5151
gitObjectRange = gitOptions[0]
5252
}
5353
previewCommand, err := commandFromTemplate("preview", diffFzfPreviewCommand, map[string]interface{}{
54-
"path": "{{2}}",
54+
"path": "{2}",
5555
"objectRange": gitObjectRange,
5656
})
5757
if err != nil {

internal/command/diff_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestNewDiffCommand(t *testing.T) {
3434
fzfQuery: "",
3535
want: &diffCli{
3636
listOptions: []string{},
37-
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s", "git diff --color {{2}}", defaultFzfBindOption),
37+
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s", "git diff --color {2}", defaultFzfBindOption),
3838
},
3939
wantErr: nil,
4040
},
@@ -52,7 +52,7 @@ func TestNewDiffCommand(t *testing.T) {
5252
"--diff-filter",
5353
"A",
5454
},
55-
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s --query config", "git diff --color origin/master {{2}}", defaultFzfBindOption),
55+
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s --query config", "git diff --color origin/master {2}", defaultFzfBindOption),
5656
},
5757
wantErr: nil,
5858
},

internal/command/fzf_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ func TestGetFzfOption(t *testing.T) {
2727
}{
2828
{
2929
name: "no env vars",
30-
previewCommand: "git diff {{1}}",
31-
want: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s", "git diff {{1}}", defaultFzfBindOption),
30+
previewCommand: "git diff {1}",
31+
want: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s", "git diff {1}", defaultFzfBindOption),
3232
},
3333
{
3434
name: "all correct env vars",
35-
previewCommand: "git diff {{1}}",
35+
previewCommand: "git diff {1}",
3636
envVars: map[string]string{
3737
envNameFzfOption: fmt.Sprintf("--preview '$GIT_FZF_FZF_PREVIEW_OPTION' --bind $%s", envNameFzfBindOption),
3838
envNameFzfBindOption: "ctrl-k:kill-line",
3939
},
40-
want: fmt.Sprintf("--preview '%s' --bind %s", "git diff {{1}}", "ctrl-k:kill-line"),
40+
want: fmt.Sprintf("--preview '%s' --bind %s", "git diff {1}", "ctrl-k:kill-line"),
4141
},
4242
{
4343
name: "no env vars",

internal/command/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func newLogCli(gitOptions []string, fzfQuery string) (*logCli, error) {
5151
gitObjectRange = gitOptions[0]
5252
}
5353
previewCommand, err := commandFromTemplate("preview", logFzfPreviewCommand, map[string]interface{}{
54-
"path": "{{1}}",
54+
"path": "{1}",
5555
"objectRange": gitObjectRange,
5656
})
5757
if err != nil {

internal/command/log_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestNewLogCommand(t *testing.T) {
3434
fzfQuery: "",
3535
want: &logCli{
3636
listOptions: []string{},
37-
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s", "git show --color {{1}}", defaultFzfBindOption),
37+
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s", "git show --color {1}", defaultFzfBindOption),
3838
},
3939
wantErr: nil,
4040
},
@@ -52,7 +52,7 @@ func TestNewLogCommand(t *testing.T) {
5252
"--diff-filter",
5353
"A",
5454
},
55-
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s --query config", "git show --color origin/master {{1}}", defaultFzfBindOption),
55+
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s --query config", "git show --color origin/master {1}", defaultFzfBindOption),
5656
},
5757
wantErr: nil,
5858
},

internal/command/stash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewStashSubcommand() *cobra.Command {
4646

4747
func newStashCli(gitOptions []string, fzfQuery string) (*stashCli, error) {
4848
previewCommand, err := commandFromTemplate("preview", stashFzfPreviewCommand, map[string]interface{}{
49-
"stash": "{{1}}",
49+
"stash": "{1}",
5050
})
5151
if err != nil {
5252
return nil, fmt.Errorf("invalid fzf preview command: %w", err)

internal/command/stash_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestNewStashCommand(t *testing.T) {
3434
fzfQuery: "",
3535
want: &stashCli{
3636
listOptions: []string{},
37-
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s", "git stash show --color -p '{{1}}'", defaultFzfBindOption),
37+
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s", "git stash show --color -p '{1}'", defaultFzfBindOption),
3838
},
3939
wantErr: nil,
4040
},
@@ -50,7 +50,7 @@ func TestNewStashCommand(t *testing.T) {
5050
"--diff-filter",
5151
"A",
5252
},
53-
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s --query config", "git stash show --color -p '{{1}}'", defaultFzfBindOption),
53+
fzfOption: fmt.Sprintf("--multi --ansi --inline-info --layout reverse --preview '%s' --preview-window down:70%% --bind %s --query config", "git stash show --color -p '{1}'", defaultFzfBindOption),
5454
},
5555
wantErr: nil,
5656
},

0 commit comments

Comments
 (0)