kelleyma49 / psfzf Goto Github PK
View Code? Open in Web Editor NEWA PowerShell wrapper around the fuzzy finder fzf
License: MIT License
A PowerShell wrapper around the fuzzy finder fzf
License: MIT License
[latest PSFzf and PowerShell 6.2.0-preview.2 on Windows]
I suspected because of similar timings for different FZF_DEFAULT_COMMAND
that PSFzf ignores that environment variable. This seems to confirm the problem:
pwsh> $Env:FZF_DEFAULT_COMMAND = 'does_not_exist'
pwsh> fzf
> < [$FZF_DEFAULT_COMMAND failed]
pwsh> Invoke-FuzzySetLocation
> < 2299/2299
After upgrading PSFzf to version 2.1.0, I found that I could not use bat for text preview.
This is my fzf configuration.
$env:FZF_DEFAULT_OPTS="--prompt '⯈ ' --height 50% --layout=reverse --border
--color=dark
--color=fg:-1,bg:-1,hl:#5fff87,fg+:-1,bg+:-1,hl+:#ffaf5f
--color=info:#af87ff,prompt:#5fff87,pointer:#ff87d7,marker:#ff87d7,spinner:#ff87d7"
$env:FD_OPTIONS="--hidden --follow"
$env:FZF_DEFAULT_COMMAND="fd --type f --type l {0}" -f $env:FD_OPTION
$env:FZF_CTRL_T_OPTS='--preview "bat --style=numbers,changes,header --color=always --theme=Dracula --line-range :500 {} || cat {}"'
When in the user directory, it can preview normally.
When entering a random directory, I can't use bat to preview, and the system can't find the specified file.
If I select an item from the output of a long running command, before the command completes, then the command terminates with an error and dumps a traceback on the screen.
As a demonstration, try the following Python script:
import time
for i in range(1000):
print(f"Item {i}",flush=True)
time.sleep(1)
This generates one line of output per second. Run py .\ex.py | invoke-fzf
and select item 3 when it appears. The output is displayed, but then an error appears, along with some traceback output from Python.
>py .\ex.py | invoke-fzf
Item 3
ResourceUnavailable: Program 'py.exe' failed to run: Stopped fzf pipeline inputAt line:1 char:1
+ py .\ex.py | invoke-fzf
+ ~~~~~~~~~~.
PS 20:36 {00:05.139} D:\Work\Scratch
>Traceback (most recent call last):
File ".\ex.py", line 4, in <module>
print(f"Item {i}",flush=True)
OSError: [Errno 22] Invalid argument
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
OSError: [Errno 22] Invalid argument
Note that the prompt is part-way through the output, and if you start typing, what you types overwrites the output just after the >
of the prompt.
if i hit ESC quickly after fd
or Alt-c on a new powershell the prompt disappears from the display until I hit ESC again.
when using ctrl + t, after selecting the file, the file name is marked with '{0}', hence could not autostart it.
i tweaked my PSFzf.psm1 to add '&' before '{0}' and start the file.
eg. .txt file will be opened in notepad by default,
There are cases, for example:
ls|%{$_.Name}|fzf|%{ls -Filter $_}
rather than select the string and search with the target object with it, does this wrapper support
fuzzily selecting object?
When using zsh
you can invoke the history widget and it will use what you already have as input to match commands from history. While PSFzf
doesn't care about what you already have written before invoking it ctrl+r
.
A second point is that it doesn't replace the entire line but rather insert it at the cursor position. I suspect because you had always planned for this to be used on an empty line.
I tried to take a look at the code but sadly my experience with PowerShell scripting is very limited. I suspect you can probably re-use some of the logic in PSFzf.TabExpansion.ps1
specifically the part where you use GetBufferState()
.
P.S. thanks for the amazing work!
If you have PsFzf loading from a path that contains spaces (in my case, from a corporate OneDrive directory where My Documents is mapped) then the preview for tab-completion fails.
I suspect you need to quote the path here:
-File $previewScript
Subj, this causes errors in the Tab preview feature.
Hi,
First of all, thank you for this useful module.
I just noticed something, which may or may not affect #23 (slow start), I noticed that whenever I start a PS session, my $Error
variable is populated with all kinds of errors:
Get-Command : The term 'fgs' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\PSFzf\1.1.23\PSFzf.Functions.ps1:11 char:15
+ ... if (-not (Get-Command -Name $Name -ErrorAction SilentlyContinue)) { ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (fgs:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
Get-Command : The term 'fz' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\PSFzf\1.1.23\PSFzf.Functions.ps1:11 char:15
+ ... if (-not (Get-Command -Name $Name -ErrorAction SilentlyContinue)) { ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (fz:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
Get-Variable : Cannot find a variable with the name 'IsWindows'.
At C:\Program Files\WindowsPowerShell\Modules\ZLocation\1.1.0\ZLocation.Search.psm1:3 char:5
+ if((Get-Variable IsWindows -ErrorAction SilentlyContinue) -eq $null) ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (IsWindows:String) [Get-Variable], ItemNotFoundException
+ FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand
Get-Variable : Cannot find a variable with the name 'IsMacOS'.
At C:\Program Files\WindowsPowerShell\Modules\ZLocation\1.1.0\ZLocation.Service.psm1:61 char:25
+ ... :Mode = if( Get-Variable IsMacOS -ErrorAction SilentlyContinue ) { 'E ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (IsMacOS:String) [Get-Variable], ItemNotFoundException
+ FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand
Get-Command : The term 'cde' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\PSFzf\1.1.23\PSFzf.Functions.ps1:11 char:15
+ ... if (-not (Get-Command -Name $Name -ErrorAction SilentlyContinue)) { ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (cde:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
Get-Command : The term 'fkill' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\PSFzf\1.1.23\PSFzf.Functions.ps1:11 char:15
+ ... if (-not (Get-Command -Name $Name -ErrorAction SilentlyContinue)) { ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (fkill:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
Get-Command : The term 'fh' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\PSFzf\1.1.23\PSFzf.Functions.ps1:11 char:15
+ ... if (-not (Get-Command -Name $Name -ErrorAction SilentlyContinue)) { ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (fh:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
Get-Command : The term 'fasd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\PSFzf\1.1.23\PSFzf.Functions.ps1:83 char:11
+ } elseif (Get-Command fasd -ErrorAction SilentlyContinue) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (fasd:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
Get-Command : The term 'Get-Frecents' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\PSFzf\1.1.23\PSFzf.Functions.ps1:68 char:5
+ if (Get-Command Get-Frecents -ErrorAction SilentlyContinue) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-Frecents:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
Get-Command : The term 'fe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\PSFzf\1.1.23\PSFzf.Functions.ps1:11 char:15
+ ... if (-not (Get-Command -Name $Name -ErrorAction SilentlyContinue)) { ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (fe:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
So, I thought it might be a good idea to use -ErrorAction Ignore
to prevent this from happening
Awesome project!
I was trying to implement this scenario with fzf
and PSReadLine, but didn't succeed.
It would be useful to pipe all history records from PSReadLine to fzf
.
Maybe you know how to get it done?
When invoking Tab completion and CurrentDir ($pwd) is on a network drive or share, $process.Start() fail with error "Directory name is not valid"
psfzf : 2.2.9
Powershell : 5.1
and on powershell 7.2, the shell freeze.
When hitting tab after Get-Module -
:
PS C:\Users\cstrahan> Get-Module -
> - ╭─────────────────────────────────────────────────────────────────────────────────╮
22/22 │ PsFzfTabExpansion-Preview.ps1: A parameter cannot be found that matches paramet │
> -All │ │
-Name │ │
-Debug │ │
-Refresh │ │
-Verbose │ │
-PSEdition │ │
-PSSession │ │
-OutBuffer │ │
-CimSession ╰─────────────────────────────────────────────────────────────────────────────────╯
PS C:\Users\cstrahan> Get-Module -
> - ╭─────────────────────────────────────────────────────────────────────────────────╮
22/22 │ InvalidOperation: C:\Users\cstrahan\Documents\PowerShell\Modules\PSFzf\2.3.1/40 │
-All │ Line | │
-Name │ 6 | $Item = $Item.Trim("'").Trim('"') │
> -Debug │ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ │
-Refresh │ | You cannot call a method on a null-valued expression. │
-Verbose │ │
-PSEdition │ │
-PSSession │ Directory: C:\Users\cstrahan │
-OutBuffer │ Mode LastWriteTime Length Name │
-CimSession ╰─────────────────────────────────────────────────────────────────────────────────╯
Seems to fail here:
This is on the latest alpha of PSFzF
:
PS C:\Users\cstrahan> Get-Module -Name PSFzf
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.3.1 alpha PSFzf {Enable-PsFzfAliases, Invoke-FuzzyEdit, Invoke-FuzzyFasd, Invoke-FuzzyGitStatus…}
(also occurs with latest stable release)
FWIW, this is with the latest version of FZF installed through chocolatey:
C:\Windows\system32>fzf --version
0.28.0 (e4c3ecc)
Anything I can do to help resolve this? This module otherwise seems awesome!
Hello!
fzf does not use FZF_CTRL_T_COMMAND and FZF_ALT_C_COMMAND variables (https://github.com/junegunn/fzf#key-bindings-for-command-line). I think that this is a bug. How can I help with this problem?
Thanks!
height
is setCTRL+R, CTRL+T, etc. have erased prompts after executed. This occurs when Invoke-Fzf is executed from within a PSReadLine keyboard shortcut.
Originally posted by @wjrogers in junegunn/fzf#1341 (comment)
If I call fzf directly at the root of a deep directory tree (for example), I can choose a match and immediately exit without waiting for the full set of available files to be listed.
Doing the same with Invoke-Fzf seems to accept my match, but then I sit waiting with an empty screen for a while before I can do anything with the result. I assume it is waiting for the input set to finish building, but if I already found what i want is there a way to bail out like with fzf directly?
Hi,
Thanks for this plugin, I had to switch from linux to windows and this save me a lot of time.
Script version :
Install-Module -Name PSFzf -AllowPrerelease
pwsh --version
PowerShell 7.2.0
$profile :
Import-Module posh-git
Import-Module oh-my-posh
Import-Module PSFzf
Import-Module ZLocation
Import-Module -Name PSKubectlCompletion
Register-KubectlCompletion
Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion }
Set-PSReadlineOption -Color @{
"Parameter"="$([char]0x1b)[93m"
"Operator"="$([char]0x1b)[93m"
}
Set-PSReadLineOption -PredictionSource History
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'
Set-PoshPrompt -Theme powerlevel10k_rainbow
I have onedrive on this pc, and in my home dir I have something like that:
d---- 11/24/2021 4:20 PM kaniko
d-r-- 10/27/2021 3:08 PM Links
d---- 11/8/2021 6:22 PM linux-install
d---- 11/8/2021 11:13 PM linux-wsl
d-r-- 10/27/2021 3:08 PM Music
d---- 11/16/2021 6:36 PM npm-cache
lar-- 11/26/2021 4:52 PM OneDrive - Yahoo
d-r-- 10/27/2021 3:08 PM Saved Games
d---- 11/25/2021 4:28 PM scoop
d-r-- 11/23/2021 9:21 AM Searches
d---- 11/23/2021 3:40 PM tmp
d---- 11/19/2021 9:45 AM video
d-r-- 11/10/2021 11:25 AM Videos
If I do
cd
cd <TAB>
The terminal is splitted and on the right side I have
The argument 'C:\Users\Ben\OneDrive' is not recognized as the name of a script file. Check the
...
Usage: pwsh[.exe] [-Login] [[-File] <filePath> [args]]
...
As if spaces in path are not protected.
Thanks in advance.
Hi,
If i had some output in my terminal, and then press Ctrl + R, the fzf output appears, and after i select something, the output of the terminal is not restored.
Is there a way to keep the output?
As of (I believe) 1.1.19, I get this warning even though I am using -ArgumentList:
λ Import-Module PSFzf -ArgumentList 'Alt+T','Ctrl+R'
WARNING: PSReadline chord ctrl+r already in use - keyboard handler not installed. To bind your own keyboard chord, use the -ArgumentList parameter when you call Import-Module.
WARNING: PSReadline chord alt+c already in use - keyboard handler not installed. To bind your own keyboard chord, use
the -ArgumentList parameter when you call Import-Module.
WARNING: PSReadline chord alt+a already in use - keyboard handler not installed. To bind your own keyboard chord, use
the -ArgumentList parameter when you call Import-Module.
Despite the warning, the key chord bindings work as expected.
Thanks for this module, very cool.
Although would be even greater if I could get it to work in vs code though, any ideas?
This is a follow-up from my comment #1 (comment)
I think it would be awesome to add PS support to the official fzf repo.
As far as I see it requires just implementing Ctrl-R
, Alt-C
, Ctrl-T
as a standalone key-binding.ps1
file that install script will add dot-source from the $profile
I'm finding that the module import process is not working from the $PROFILE
configuration file. On my work computer, I got it to work consistently by moving the import statement from the top of $PROFILE
to the bottom, but it has not been effective for my laptop. I always have to wait for powershell to load, then run the import statement manually. I assume powershell is loading something asynchronously that is overwriting the chords, but I don't know enough about it to figure out what it could be.
Here's a snippet from my $PROFILE
with the imports.
# Modules
Import-Module PSReadLine
Import-Module PSFzf -ArgumentList 'Ctrl+t', 'Alt+r' -Force
Import-Module Get-ChildItemColor
# Module settings
Set-PSReadLineOption -EditMode Vi
Does anyone have a trick to make sure the chords always work?
$env:EDITOR='notepad'
fe <dir>
Error: file not found
The following command shows, that the editor was called with wrong parameter:
Get-CimInstance Win32_Process -Filter "name='notepad.exe'" | select CommandLine
First, this is a great tool. I would like to be able to specify command line options that this tool sends to fzf
.
This can already be set globally by using fzf's env variable FZF_DEFAULT_OPTS
but that's not what I am looking for. I want to specify default options only for the case when fzf is invoked by PSFzf. Could you add another option or env variable for that ?
For example, zoxide uses another env variable for that - _ZO_FZF_OPTS
: https://github.com/ajeetdsouza/zoxide#environment-variables
It looks like --expect works OK on Windows and would be useful to build PowerShell functions that take different actions on the search results. Could it be added to the Invoke-Fzf wrapper?
Is there a way to prevent the module from importing certain aliases? In my case, specifically, the alias fd
shadows the fd
command (the cool find command).
Is the solution to do something like this? This doesn't seem very clean, as it might end up not removing the alias that was intended.
Import-Module PSFzf -ArgumentList 'Ctrl+T','Ctrl+R'
Remove-Item alias:fd
NOTE: Ctrl+R to search history works perfectly fine
Search is refined by the entered text, and am able to select a result with the arrow keys.
Search stops after the first character is entered, and fzf seems to freeze as it's no longer responsive to arrow keys or the escape key. It's possible to only backspace up to the first character entered, but it doesn't allow deleting that first character. Pressing enter selects the first entry, otherwise the only way to exit is Ctrl+C as it's not responsive to escape.
After attempting to delete the entire search term:
Relevant lines in my profile:
Import-Module PSFzf
Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion }
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'
FZF_DEFAULT_COMMAND = 'fd --type file'
I would like to have the ability to fuzzy search a file and have the current working location set to the directory that contains the selected file.
For example, I have a directory structure like this:
├───backend
│ data.json
│ main.cs
│
└───frontend
│ data.json
│ main.js
└───...
There are times when I want to go to the backend directory to work on a few backend related files and I don't remember the name of the directory, but know the directory contains a file called main.cs. It will be helpful if there's a new command or a new parameter added to one of the existing commands that allows me to fuzzy search the main.cs file and then set the current working directory to backend.
I think this is a common use case that other people may also need.
Win7x64 here and all the instructions are accurate, but all case sensitive. Even if I disable my entire PS profile and run vanilla and only enable psreadline and then psfzf.
So, I literally have to also hold the SHIFT key along with the CTRL and T keys and CTRL and G for this:
Import-Module PSFzf -ArgumentList 'Ctrl+T','Ctrl+G'
But, I only have to press CTRL and T and CTRL and G for this:
Import-Module PSFzf -ArgumentList 'Ctrl+t','Ctrl+g'
And to even further prove that's what's happening, I could not figure out for the life of me why the built-in ALT+ A key
and ALT+ C key
as listed in the Readme also did nothing. It sure seemed like the module was just broken. Then, once I figured out the above, I also went back (in any of the shells since it's a default binding) and first held down SHIFT and then pressed the SHIFT+ALT+a
and SHIFT+ALT+c
, and wholla only with shift to make the literal uppercase "A" and "C" true did the default bindings suddenly work.
This seems to be the case on mult systems I am testing, so is this a new bug or ?
TIA!
The Invoke-Fzf.md
file is not up-to-date. For example, it claims that there's a parameter called InlineInfo
, but when I run Invoke-Fzf -InlineInfo
, I got this error:
Invoke-Fzf: A parameter cannot be found that matches parameter name 'InlineInfo'.
So, its possible that something may be misconfigured, but I have fzf installed with homebrew and working in other shells. However, I cannot import psfzf even though Get-Command can find the fzf binary.
From my shell:
❯ pwsh
PowerShell v6.0.2
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /Users/ryanzeigler> Get-Command fzf*
CommandType Name Version Source
----------- ---- ------- ------
Application fzf 0.0.0.0 /usr/local/bin/fzf
Application fzf 0.0.0.0 /usr/local/opt/fzf/bin/fzf
Application fzf-tmux 0.0.0.0 /usr/local/bin/fzf-tmux
Application fzf-tmux 0.0.0.0 /usr/local/opt/fzf/bin/fzf-tmux
PS /Users/ryanzeigler> Import-Module PSFzf -ArgumentList 'Ctrl+T','Ctrl+R'
Get-Command : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At /usr/local/share/powershell/Modules/PSFzf/1.1.14/PSFzf.psm1:491 char:35
+ $result = Get-Command $_ -ErrorAction SilentlyContinue
+ ~~
+ CategoryInfo : InvalidData: (:) [Get-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetCommandCommand
Resolve-Path : Cannot bind argument to parameter 'Path' because it is null.
At /usr/local/share/powershell/Modules/PSFzf/1.1.14/PSFzf.psm1:493 char:52
+ $script:FzfLocation = Resolve-Path $_.Source
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Resolve-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ResolvePathCommand
Import-Module : Failed to find fzf binary in PATH. You can download a binary from this page: https://github.com/junegunn/fzf-bin/releases
At line:1 char:1
+ Import-Module PSFzf -ArgumentList 'Ctrl+T','Ctrl+R'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Failed to find ...zf-bin/releases:String) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : Failed to find fzf binary in PATH. You can download a binary from this page: https://github.com/junegunn/fzf-bin/releases,Microsoft.PowerShell.Commands.ImportModuleCommand
The pre-release versions of kubectl v1.23.0 include PowerShell completion, which is provided under the hood by spf13/cobra. This works beautifully most of the time in conjunction with Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion }
:
However, there seems to be an issue when there are no completions available:
(Note that pressing Ctrl + C has no effect. I have to press Enter to run the command before I can do anything else.)
I’ll reproduce it in text for legibility, though of course without the formatting:
❯❯ kubectl get pods fAn exception occurred in custom key handler, see $error for more information: Exception calling "CompleteInput" with "3" argument(s): "Cannot process argument because the value of argument "completionText" is null. Change the value of argument "completionText" to a non-null value."
~
❯❯ kubectl get pods f
Error from server (NotFound): pods "f" not found
~ took 1s157ms
❯❯ kubectl asdasdAn exception occurred in custom key handler, see $error for more information: Exception calling "CompleteInput" with "3" argument(s): "Cannot process argument because the value of argument "completionText" is null. Change the value of argument "completionText" to a non-null value."
~ took 1s157ms
❯❯ kubectl asdasd
E1128 12:56:48.823585 19468 run.go:120] "command failed" err="unknown command \"asdasd\" for \"kubectl\""
Now, if I run the command that the application’s completion script runs under the hood, this is what I see:
❯❯ k __complete asdasd
:4
Completion ended with directive: ShellCompDirectiveNoFileComp
Which is the result of this code:
if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
__kubectl_debug "ShellCompDirectiveNoFileComp is called"
if ($Values.Length -eq 0) {
# Just print an empty string here so the
# shell does not start to complete paths.
# We cannot use CompletionResult here because
# it does not accept an empty string as argument.
""
return
}
}
As far as I can tell, the completion script is doing the right thing. Without PsFzf, pressing Tab does nothing if there are no completions, as you’d expect, and lets you continue your input. With PsFzf, pressing Tab with no completions available causes an error and prevents you from using Ctrl + C to cancel the input.
I’m running PsFzf v2.3.1-alpha (which I upgraded to from v2.2.9 in case it fixed this bug) with PowerShell v7.2.0 under Windows 10.0.19043 (64-bit).
When using Invoke-Fzf
, the working directory of the fzf
sub-process isn't changed to match the shell's current directory. When items are relative paths or otherwise depend on the current directory, this causes problems passing them to a preview command.
Using native fzf
from a non-home location:
fzf --preview cd
the preview window outputs my current location.
But using Invoke-Fzf
:
Invoke-Fzf -Preview cd
the preview window displays my home directory.
My actual use case was piping in a set of git branch names, and trying to preview the selected one with git log --graph {}
, only to find that git was erroring on the lack of a .git
subdirectory in the fzf
process's working directory.
Using PSFzf 1.1.24 on Windows 8.1, PowerShell 6.2.2.
I know there is a way to make fzf respect .gitignore files on Bash, but is there a way to do it with PowerShell? I am struggling to figure it out.
I add the following to my PS init script to enable aliases on all shells:
echo "Loading aliases ..."
Enable-PsFzfAliases
echo "Done."
However this slows down the shell initialization by several seconds (5s). Any way to speed things up here?
I use vi-mode on the powershell command line by putting this in my profile:
Set-PSReadlineOption -EditMode vi
When using vi-mode, CTRL-T transposes characters. Is there any way to override the default behavior so that fzf is invoked instead?
When I use any of the CTRL-T
, fe
, or fd
commands in ConEmu, PowerShell console or Windows Terminal, an escape sequence appears at the beginning and end of the line. I assume this is supposed to colour the line?
For example, CTRL-T
gives:
[0m[36m.File1.log[0m
[0m[36m.File2.log[0m
...
And when I select one, the [0m[36m.
and [0m
are included in the selection, which I have to then delete.
I'm sure this used to work. I'm using PSFzF 1.1.26. Update-Module
did not update it when I tried (in case there's a later version).
I've tried on PowerShell versions 5.1 and 6.2 running on Windows 10 1903.
I feel I'm doing something basically wrong! Please can you help correct this.
Thanks
When PSFzf is used with a powerline (e.g. oh-my-posh), the special characters are replaced with question marks after fzf runs.
Reproduction steps:
Tested on latest version (2.2.6)
Additional note: This issue does not occur when fzf is called manually from the command line
Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion }
<TAB>
<ENTER>
the text I typed to narrow down the list of results
the Item I selected appended to my command line
Powershell 5.1.17763.1971
Using all other chords like - R work as expected. I guess I am missing something? Anything else I can try?
Line 94 in 944043f
$result = Get-Content (Get-PSReadlineOption).HistorySavePath | Invoke-Fzf -Reverse -NoSort
Hello
I've enabled PSFzf with the commands:
Remove-PSReadlineKeyHandler 'CTRL+R'
Import-Module PSFzf
This all works. However, when I'm in PowerShell, the tab
key does nothing!
If I use
Import-Module PSFzf -ArgumentList 'Ctrl+T','Ctrl+R', 'Tab'
Then I get fzf invoked when I press tab
.
How do I get the default tab behaviour whilst using PSfzf. Note tab
works fine when using just PSReadline and fzf.
I'm using Windows 10 Creators Update with PowerShell 5.1.
Thanks
Praful
Adding this plugin hogs powershell start time.
This package is awesome! The Alt+C binding is what I’m most interested in. I try to avoid cd
/Set-Location
, though; I’d like to be able to use Push-Location
or even zoxide instead. Would it be possible to add a setting to use a different command? (I tried to do this myself and thought I got it right on the script side, but I couldn’t figure out how to get PowerShell to pick up my changes even after rebuilding and reimporting.)
How to get the chronological order in the history search ? The fzf documentation says : «If you want to see the commands in chronological order, press CTRL-R again which toggles sorting by relevance», but it doesn't look like it's possible with PSFzf.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.