Skip to content

Commit

Permalink
Use fzf directly instead of PowerShell function
Browse files Browse the repository at this point in the history
  • Loading branch information
kelleyma49 committed Sep 30, 2024
1 parent bb987d1 commit 744287b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions PSFzf.Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,25 @@ function Invoke-PsFzfRipgrep() {
$env:FZF_DEFAULT_COMMAND = '{0} $(printf %q "{1}")' -f $RG_PREFIX, $INITIAL_QUERY
}
$fzfArguments = @{
Ansi = $true
Disabled = $true
Color = "hl:-1:underline,hl+:-1:underline:reverse"
Query = $INITIAL_QUERY
Prompt = 'ripgrep> '
Delimiter = ':'
Header = '? CTRL-R (Ripgrep mode) ? CTRL -F (fzf mode) ?'
Preview = 'bat --color=always {1} --highlight-line {2}'
PreviewWindow = 'up,60%,border-bottom,+{2}+3/3,~3'
color = "hl:-1:underline,hl+:-1:underline:reverse"
query = $INITIAL_QUERY
prompt = 'ripgrep> '
delimiter = ':'
header = '? CTRL-R (Ripgrep mode) ? CTRL -F (fzf mode) ?'
preview = 'bat --color=always {1} --highlight-line {2}'
'preview-window' = 'up,60%,border-bottom,+{2}+3/3,~3'
}

$fzfArgs = ($fzfArguments.GetEnumerator() | foreach-object { "--{0}=""{1}""" -f $_.Key, $_.Value }) -join ' '

$Bind = @(
'ctrl-r:unbind(change,ctrl-r)+change-prompt(ripgrep> )' + "+disable-search+reload($RG_PREFIX {q} || $trueCmd)+rebind(change,ctrl-f)"
'ctrl-r:unbind(change,ctrl-r)+change-prompt(ripgrep> )' + "+disable-search+reload($RG_PREFIX {q} || $trueCmd)+rebind(change,ctrl-f)"
)
$Bind += 'ctrl-f:unbind(change,ctrl-f)+change-prompt(fzf> )+enable-search+clear-query+rebind(ctrl-r)'
$Bind += "change:reload:$sleepCmd $RG_PREFIX {q} || $trueCmd"
$fzfArgs += ' --ansi --disabled ' + ($Bind | foreach-object { "--bind=""{0}""" -f $_ }) -join ' '

Invoke-Fzf @fzfArguments -Bind $Bind | ForEach-Object { $results += $_ }
Invoke-Expression -Command $('{0} {1}' -f $script:FzfLocation, $fzfArgs) | ForEach-Object { $results += $_ }

# we need this here to prevent the editor launch from inherting FZF_DEFAULT_COMMAND from being overwritten (see #267):
if ($script:OverrideFzfDefaultCommand) {
Expand Down

0 comments on commit 744287b

Please sign in to comment.