Skip to content

Commit

Permalink
Fix Invoke-PsFzfRipgrep throws unknown action: change-prompt afte…
Browse files Browse the repository at this point in the history
…r updating to 2.6.1 #273 (#277)

* Fix `Invoke-PsFzfRipgrep` throws `unknown action: change-prompt` after updating to 2.6.1 #273

- Add 'Disabled' param
- Restore unicode icons for git functions and only show in Terminal or non-Windows
- Minor formatting fix

* Fix debug output
  • Loading branch information
kelleyma49 authored Sep 23, 2024
1 parent c604e1b commit 8734f2e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
4 changes: 3 additions & 1 deletion PSFzf.Base.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function Set-PsFzfOption{
if ($EnableAliasFuzzySetLocation) { SetPsFzfAlias "fd" Invoke-FuzzySetLocation }
if ($EnableAliasFuzzyZLocation) { SetPsFzfAlias "fz" Invoke-FuzzyZLocation }
if ($EnableAliasFuzzyGitStatus) { SetPsFzfAlias "fgs" Invoke-FuzzyGitStatus }
if ($EnableAliasFuzzyScoop) { SetPsFzfAlias "fs" Invoke-FuzzyScoop }
if ($EnableAliasFuzzyScoop) { SetPsFzfAlias "fs" Invoke-FuzzyScoop }
if ($EnableAliasFuzzySetEverything) {
if (${function:Set-LocationFuzzyEverything}) {
SetPsFzfAlias "cde" Set-LocationFuzzyEverything
Expand Down Expand Up @@ -277,6 +277,7 @@ function Invoke-Fzf {
[ValidateSet('length','begin','end','index')]
[string]
$Tiebreak = $null,
[switch]$Disabled,

# Interface
[Alias('m')]
Expand Down Expand Up @@ -350,6 +351,7 @@ function Invoke-Fzf {
if ($PSBoundParameters.ContainsKey('ReverseInput') -and $ReverseInput) { $arguments += '--tac '}
if ($PSBoundParameters.ContainsKey('Phony') -and $Phony) { $arguments += '--phony '}
if ($PSBoundParameters.ContainsKey('Tiebreak') -and ![string]::IsNullOrWhiteSpace($Tiebreak)) { $arguments += "--tiebreak=$Tiebreak "}
if ($PSBoundParameters.ContainsKey('Disabled') -and $Disabled) { $arguments += '--disabled '}
if ($PSBoundParameters.ContainsKey('Multi') -and $Multi) { $arguments += '--multi '}
if ($PSBoundParameters.ContainsKey('NoMouse') -and $NoMouse) { $arguments += '--no-mouse '}
if ($PSBoundParameters.ContainsKey('Bind') -and $Bind.Length -ge 1) { $Bind | ForEach-Object { $arguments += "--bind=""$_"" " } }
Expand Down
30 changes: 18 additions & 12 deletions PSFzf.Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,25 @@ function Invoke-PsFzfRipgrep() {
$trueCmd = 'true'
$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'
}
$Bind = @(
'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"

Invoke-Fzf @fzfArguments -Bind $Bind | ForEach-Object { $results += $_ }

& $script:FzfLocation --ansi `
--color "hl:-1:underline,hl+:-1:underline:reverse" `
--disabled --query "$INITIAL_QUERY" `
--bind "change:reload:$sleepCmd $RG_PREFIX {q} || $trueCmd" `
--bind "ctrl-f:unbind(change,ctrl-f)+change-prompt" + '( +✅ fzf> )' + "+enable-search+clear-query+rebind(ctrl-r)" `
--bind "ctrl-r:unbind(ctrl-r)+change-prompt" + '(🔎 ripgrep> )' + "+disable-search+reload($RG_PREFIX {q} || $trueCmd)+rebind(change,ctrl-f)" `
--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' | `
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) {
$script:OverrideFzfDefaultCommand.Restore()
Expand Down
35 changes: 27 additions & 8 deletions PSFzf.Git.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ else {
$script:pwshExec = "powershell"
}

$script:IsWindowsCheck = ($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows

if ($RunningInWindowsTerminal -or -not $script:IsWindowsCheck) {
$script:filesString = '📁 Files'
$script:hashesString = '🍡 Hashes'
$script:allBranchesString = '🌳 All branches'
$script:branchesString = '🌲 Branches'
$script:tagsString = '📛 Tags'
$script:stashesString = '🥡 Stashes'
}
else {
$script:filesString = 'Files'
$script:hashesString = 'Hashes'
$script:allBranchesString = 'All branches'
$script:branchesString = 'Branches'
$script:tagsString = 'Tags'
$script:stashesString = 'Stashes'
}

function Get-GitFzfArguments() {
# take from https://github.com/junegunn/fzf-git.sh/blob/f72ebd823152fa1e9b000b96b71dd28717bc0293/fzf-git.sh#L89
return @{
Expand Down Expand Up @@ -148,7 +167,7 @@ function Invoke-PsFzfGitFiles() {
$fzfArguments['Bind'] += $headerStrings[1], $gitStageBind, $gitResetBind
Invoke-Expression "& $statusCmd" | `
Invoke-Fzf @fzfArguments `
-BorderLabel '?? Files' `
-BorderLabel "$script:filesString" `
-Preview "$previewCmd" -Header $headerStr | `
foreach-object {
$result += $_.Substring('?? '.Length)
Expand All @@ -172,8 +191,8 @@ function Invoke-PsFzfGitHashes() {
$fzfArguments = Get-GitFzfArguments
& git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" $(Get-ColorAlways).Trim() --graph | `
Invoke-Fzf @fzfArguments -NoSort `
-BorderLabel '?? Hashes' `
-Preview "$previewCmd" | ForEach-Object {
-BorderLabel "$script:hashesString"
-Preview "$previewCmd" | ForEach-Object {
if ($_ -match '\d\d-\d\d-\d\d\s+([a-f0-9]+)\s+') {
$result += $Matches.1
}
Expand All @@ -195,15 +214,15 @@ function Invoke-PsFzfGitBranches() {
$fzfArguments = Get-GitFzfArguments
$fzfArguments['PreviewWindow'] = 'down,border-top,40%'
$gitBranchesHelperPath = Join-Path $PsScriptRoot 'helpers/PsFzfGitBranches.sh'
$ShortcutBranchesAll = "ctrl-a:change-prompt(?? All branches> )+reload(" + """${script:bashPath}"" '${gitBranchesHelperPath}' all-branches)"
$ShortcutBranchesAll = "ctrl-a:change-prompt" + "($script:allBranchesString> )+reload(" + """${script:bashPath}"" '${gitBranchesHelperPath}' all-branches)"
$fzfArguments['Bind'] += 'ctrl-/:change-preview-window(down,70%|hidden|)', $ShortcutBranchesAll

$previewCmd = "${script:bashPath} \""" + $(Join-Path $PsScriptRoot 'helpers/PsFzfGitBranches-Preview.sh') + "\"" {}"
$result = @()
# use pwsh to prevent bash from trying to write to host output:
$branches = & $script:pwshExec -NoProfile -NonInteractive -Command "& ${script:bashPath} '$gitBranchesHelperPath' branches"
$branches |
Invoke-Fzf @fzfArguments -Preview "$previewCmd" -BorderLabel '?? Branches' -HeaderLines 2 -Tiebreak begin -ReverseInput | `
Invoke-Fzf @fzfArguments -Preview "$previewCmd" -BorderLabel "$script:branchesString" -HeaderLines 2 -Tiebreak begin -ReverseInput | `
ForEach-Object {
$result += $($_.Substring('* '.Length) -split ' ')[0]
}
Expand All @@ -226,7 +245,7 @@ function Invoke-PsFzfGitTags() {
$previewCmd = "git show --color=always {}"
$result = @()
git tag --sort -version:refname |
Invoke-Fzf @fzfArguments -Preview "$previewCmd" -BorderLabel '?? Tags' | `
Invoke-Fzf @fzfArguments -Preview "$previewCmd" -BorderLabel "$script:tagsString" | `
ForEach-Object {
$result += $_
}
Expand All @@ -251,7 +270,7 @@ function Invoke-PsFzfGitStashes() {

$result = @()
git stash list --color=always |
Invoke-Fzf @fzfArguments -Header $header -Delimiter ':' -Preview "$previewCmd" -BorderLabel '?? Stashes' | `
Invoke-Fzf @fzfArguments -Header $header -Delimiter ':' -Preview "$previewCmd" -BorderLabel "$script:stashesString" | `
ForEach-Object {
$result += $_.Split(':')[0]
}
Expand Down Expand Up @@ -354,7 +373,7 @@ function Invoke-PsFzfGitPullRequests() {
}

try {
$borderLabel = "?? Pull Requests"
$borderLabel = "Pull Requests"
if ($currentUser) {
$borderLabel += " by $currentUser"
}
Expand Down

0 comments on commit 8734f2e

Please sign in to comment.