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 for customization of preview window on tab completion #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions PSFzf.TabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,33 @@ function script:Invoke-FzfTabCompletionInner() {
$additionalCmd = @{ Preview = $($script:PowershellCmd + " -NoProfile -NonInteractive -File \""$previewScript\"" \""" + $path + "\"" {}") }
}

$previewWindow = 'down:30%'
$altPreviewWindow = 'right:50%'

if (([string]::IsNullOrWhiteSpace($env:_PSFZF_FZF_TAB_PREVIEW_DEFAULT)) -or ($env:_PSFZF_FZF_TAB_PREVIEW_DEFAULT -eq 'down') ) {
$previewWindow = 'down:30%'
$altPreviewWindow = 'right:50%'
}
elseif ($env:_PSFZF_FZF_TAB_PREVIEW_DEFAULT -eq 'right') {
$previewWindow = 'right:50%'
$altPreviewWindow = 'down:30%'
}
elseif ($env:_PSFZF_FZF_TAB_PREVIEW_DEFAULT -eq 'left') {
$previewWindow = 'left:50%'
$altPreviewWindow = 'down:30%'
}
elseif ($env:_PSFZF_FZF_TAB_PREVIEW_DEFAULT -eq 'top') {
$previewWindow = 'top:50%'
$altPreviewWindow = 'left:50%'
}
$changePreviewWindow = "$previewWindow,$altPreviewWindow,border-rounded|hidden|"

$script:fzfOutput = @()
$completionMatches | ForEach-Object { $_.CompletionText } | Invoke-Fzf `
-Layout reverse `
-Expect "$expectTriggers" `
-PreviewWindow 'down:30%' `
-Bind 'tab:down', 'btab:up', 'ctrl-/:change-preview-window(down,right:50%,border-top|hidden|)' `
-PreviewWindow "$previewWindow" `
-Bind 'tab:down', 'btab:up', "ctrl-/:change-preview-window($changePreviewWindow)" `
@additionalCmd | ForEach-Object {
$script:fzfOutput += $_
}
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ Get-ChildItem . -Recurse | ? { $_.PSIsContainer } | Invoke-Fzf | Set-Location
## Overriding Behavior

PsFzf supports overriding behavior by setting these fzf environment variables:
| Env Var Name | Description |
|------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| `_PSFZF_FZF_DEFAULT_OPTS` | If this environment variable is set, then `FZF_DEFAULT_OPTS` is temporarily set with the contents. This allows the user to have different default options for PSFZF and fzf.
| `FZF_DEFAULT_COMMAND` | The command specified in this environment variable will override the default command when PSFZF detects that the current location is a file system provider. |
| `FZF_CTRL_T_COMMAND` | The command specified in this environment variable will be used when <kbd>Ctrl+t</kbd> is pressed by the user. |
| `FZF_ALT_C_COMMAND` | The command specified in this environment variable will be used when <kbd>Alt+c</kbd> is pressed by the user. |
| `PSFZF_EDITOR_OPTIONS` | Contains options passed to the editor application used in the `Invoke-FuzzyEdit()` function |
| Env Var Name | Description |
|----------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `_PSFZF_FZF_DEFAULT_OPTS` | If this environment variable is set, then `FZF_DEFAULT_OPTS` is temporarily set with the contents. This allows the user to have different default options for PSFZF and fzf. |
| `FZF_DEFAULT_COMMAND` | The command specified in this environment variable will override the default command when PSFZF detects that the current location is a file system provider. |
| `FZF_CTRL_T_COMMAND` | The command specified in this environment variable will be used when <kbd>Ctrl+t</kbd> is pressed by the user. |
| `FZF_ALT_C_COMMAND` | The command specified in this environment variable will be used when <kbd>Alt+c</kbd> is pressed by the user. |
| `PSFZF_EDITOR_OPTIONS` | Contains options passed to the editor application used in the `Invoke-FuzzyEdit()` function |
| `_PSFZF_FZF_TAB_PREVIEW_DEFAULT` | This environment variable controls the default location for the preview preview window during tab completion (default: `down`) |

## Helper Functions

Expand Down