diff --git a/PSFzf.TabExpansion.ps1 b/PSFzf.TabExpansion.ps1 index 2a46d6f..371cc1b 100644 --- a/PSFzf.TabExpansion.ps1 +++ b/PSFzf.TabExpansion.ps1 @@ -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 += $_ } diff --git a/README.md b/README.md index 7594bea..bfb16c5 100644 --- a/README.md +++ b/README.md @@ -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 Ctrl+t is pressed by the user. | -| `FZF_ALT_C_COMMAND` | The command specified in this environment variable will be used when Alt+c 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 Ctrl+t is pressed by the user. | +| `FZF_ALT_C_COMMAND` | The command specified in this environment variable will be used when Alt+c 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