Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing custom fzf opts to individual commands #140

Merged
merged 14 commits into from
Mar 23, 2021

Conversation

PatrickF1
Copy link
Owner

@PatrickF1 PatrickF1 commented Mar 22, 2021

The following variables can store the custom fzf options that will be passed to fzf by their respective feature:
fzf_dir_opts => search directory
fzf_git_status_opts => search git status
fzf_git_log_opts => search git log
fzf_history_opts => search history
fzf_shell_vars_opts => search shell variables

They are always appended last to fzf's argument list so that they can override any fzf options that are hardcoded in by fzf.fish. This might lead to some users shooting themselves in the foot but also unlocks numerous opportunities for the user to customize or augment the existing features.

This was an oft requested feature that I parried for a long time but now I am very excited to finally add. With this, change, some of the cool ideas now made possible include

  • add key bindings within fzf to operate on the selected line, e.g. open file in vim, preview file as image, copy to clipboard, git checkout commit, git reset commit
  • adjust the preview window or command
  • re-populate fzf's input list on demand
  • change the search mode
  • and many, many more

@PatrickF1 PatrickF1 force-pushed the main branch 2 times, most recently from ed5b4fe to 8fbdc23 Compare March 22, 2021 22:26
@PatrickF1 PatrickF1 force-pushed the configure-fzf-opts branch from 1e55e6f to 2a2acca Compare March 22, 2021 22:27
@@ -16,10 +16,10 @@ function __fzf_search_current_dir --description "Search the current directory. R
if string match --quiet -- "*/" $token && test -d "$unescaped_exp_token"
set --append fd_opts --base-directory=$unescaped_exp_token
# use the directory name as fzf's prompt to indicate the search is limited to that directory
set --append fzf_arguments --prompt="$unescaped_exp_token" --preview="__fzf_preview_file $expanded_token{}"
set --prepend fzf_arguments --prompt="$unescaped_exp_token" --preview="__fzf_preview_file $expanded_token{}"
Copy link
Owner Author

@PatrickF1 PatrickF1 Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepend so that $fzf_dir_opts always appears last

@PatrickF1 PatrickF1 changed the title Allow configuring fzf opts by command Allow passing custom fzf opts to individual commands Mar 23, 2021

### Change the command used to preview folders

The search files feature, by default, uses `ls` to preview the contents of a directory. To integrate with the variety of `ls` replacements available, the command used to preview directories is configurable through the `fzf_preview_dir_cmd` variable. For example, in your `config.fish`, you may put:
The search directory feature, by default, uses `ls` to preview the contents of a directory. To integrate with the variety of `ls` replacements available, the command used to preview directories is configurable through the `fzf_preview_dir_cmd` variable. For example, in your `config.fish`, you may put:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally settling on the name search directory to make room for search files by pattern (#118) in the features namespace

@@ -11,9 +11,11 @@ function __fzf_search_git_log --description "Search the output of git log and pr
# see documentation for git format placeholders at https://git-scm.com/docs/git-log#Documentation/git-log.txt-emnem
# %h gives you the abbreviated commit hash, which is useful for saving screen space, but we will have to expand it later below
git log --color=always --format=format:$log_fmt_str | \
fzf --ansi --tiebreak=index \
fzf --ansi \
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broke up options list into one option by line for readability

@PatrickF1 PatrickF1 merged commit b8a99b2 into main Mar 23, 2021
@PatrickF1 PatrickF1 deleted the configure-fzf-opts branch March 23, 2021 04:58
hrshtst pushed a commit to hrshtst/fzf.fish that referenced this pull request Apr 26, 2021
The following variables can store the custom options that will be passed to fzf by their respective feature:
  fzf_dir_opts => search directory
  fzf_git_status_opts => search git status
  fzf_git_log_opts => search git log
  fzf_history_opts => search history
  fzf_shell_vars_opts => search shell variables

They are always appended last to fzf's argument list so that they can override any hardcoded fzf options. This might lead to some users shooting themselves in the foot but also unlocks numerous opportunities for the user to customize or augment the existing features.

This was an oft requested feature that I parried for a long time but now I am very excited to finally add. With this, change, some of the cool ideas now made possible include:
- add key bindings within fzf to operate on the selected line, e.g. open file in vim, preview file as image, copy to clipboard, git checkout commit, git reset commit
- adjust the preview window or command
- re-populate fzf's input list on demand
- change the search mode
- and many, many more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant