diff --git a/PSFzf.Base.ps1 b/PSFzf.Base.ps1 index 0d67c62..18c897c 100644 --- a/PSFzf.Base.ps1 +++ b/PSFzf.Base.ps1 @@ -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 @@ -277,6 +277,7 @@ function Invoke-Fzf { [ValidateSet('length','begin','end','index')] [string] $Tiebreak = $null, + [switch]$Disabled, # Interface [Alias('m')] @@ -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=""$_"" " } } diff --git a/PSFzf.Functions.ps1 b/PSFzf.Functions.ps1 index dd80fc9..471f6cd 100644 --- a/PSFzf.Functions.ps1 +++ b/PSFzf.Functions.ps1 @@ -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() diff --git a/PSFzf.Git.ps1 b/PSFzf.Git.ps1 index 9f81175..4f50284 100644 --- a/PSFzf.Git.ps1 +++ b/PSFzf.Git.ps1 @@ -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 @{ @@ -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) @@ -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 } @@ -195,7 +214,7 @@ 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') + "\"" {}" @@ -203,7 +222,7 @@ function Invoke-PsFzfGitBranches() { # 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] } @@ -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 += $_ } @@ -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] } @@ -354,7 +373,7 @@ function Invoke-PsFzfGitPullRequests() { } try { - $borderLabel = "?? Pull Requests" + $borderLabel = "Pull Requests" if ($currentUser) { $borderLabel += " by $currentUser" }