Futman
Futman

Reputation: 13

fzf in powershell, indexing, buffering, interrupting

I have two simple functions in $PROFILE:

function fd() {
    Get-ChildItem -Directory -Name | 
    fzf --border=rounded --margin 5% --info=inline-right | 
    Set-Location
}

function fdd() {
    Get-ChildItem -Directory -Name -Recurse | 
    fzf --border=rounded --margin 5% --info=inline-right | 
    Set-Location
}

First works great. Second works great only on small depth of recursion. Is there any way to stop piping as soon as I hit enter in fzf?
Also, I use this approach alongside nano editor:

function fa() {
    $param = Get-ChildItem -File -Name | 
    fzf --border=rounded --margin 5% --info=inline-right --multi

    nano $param
}

function faa() {
    $param = Get-ChildItem -File -Name -Recurse | 
    fzf --border=rounded --margin 5% --info=inline-right --multi

    nano $param
}

This recursion works the same. I suppose Get-ChildItem pipes into fzf until it is done, that's why fzf can't just exit. So, is there a way to cancel pipe?
Also, can anyone suggest a way to check whether $param is null, so if it is so, I just return from the function?
Thanks!

EDIT
I've made checking work:

if ($null -eq $param) {
    return
}

EDIT 2
Okay, as long as I'm aware, I need to send Ctrl+C programmatically after fzf. But it seems fzf cannot exit as long as it gets input from Get-ChildItem.
Another way would be to somehow filter fzf itself to select only directories or only files.

Upvotes: 1

Views: 138

Answers (0)

Related Questions