kelleyma49 / PSFzf

A PowerShell wrapper around the fuzzy finder fzf
MIT License
755 stars 35 forks source link

Add an ability to use `--bind` multiple times #154

Closed vchirikov closed 2 years ago

vchirikov commented 2 years ago

Hello @kelleyma49, first of all thanks for you work. I tried to use pods() from https://github.com/junegunn/fzf/blob/master/ADVANCED.md#log-tailing with Invoke-Fzf and seems it's impossible at the moment.

I can't figure out how I can provide multiple bind arguments with current code:

Invoke-Fzf `
   -Info inline `
   -Layout reverse `
   -HeaderLines 1 `
   -Prompt "$(kubectl config current-context | sed 's/-context$//')>" `
   -Header "Enter (kubectl exec) / CTRL-O (open log in editor) / CTRL-R (reload) /`n`n" `
   -Bind ('"ctrl-/:change-preview-window(80%,border-bottom|hidden|)","ctrl-o:execute:echo kubectl logs --all-containers --namespace {1} {2}","enter:execute:kubectl exec -it --namespace {1} {2} -- bash || zsh || ash || sh","ctrl-r:reload:kubectl get pods --all-namespaces"') `
   -PreviewWindow 'up:follow' `
   -Preview 'kubectl logs --follow --all-containers --tail=10000 --namespace {1} {2}'

Issue:

ctrl-o output will be something kubectl logs --all-containers --namespace "default" "haproxy-ingress-56b5cf5967-j7fd7",enter:execute:kubectl exec -it --namespace "default" "haproxy-ingress-56b5cf5967-j7fd7" -- bash So seems like it wasn't parsed correctly.

Could you change https://github.com/kelleyma49/PSFzf/blob/393986b0573ee6ac9956d7aaddae11e9ad332ef2/PSFzf.Base.ps1#L338 to string[] or add an option to use -Bind multiple times?

vchirikov commented 2 years ago

I ended without psfzf, with fzf only:

function pod() {
    kubectl get pods --all-namespaces | fzf.exe --info=inline --height 40% --layout=reverse --header-lines=1 `
        --prompt "$(kubectl config current-context | sed 's/-context$//')> " `
        --header "Enter (kubectl exec) / CTRL-O (open log in editor) / CTRL-R (reload) /`n`n" `
        --bind 'ctrl-/:change-preview-window(80%,border-bottom|hidden|)' `
        --bind "enter:execute-silent(wt.exe -w main sp -V pwsh -NoLogo -NoProfile -c kubectl exec -i -t -n {1} {2} -- sh)+abort" `
        --bind 'ctrl-o:execute(kubectl logs --all-containers --namespace {1} {2} | code -)' `
        --bind "ctrl-r:reload(kubectl get pods --all-namespaces)" `
        --preview-window up:follow `
        --preview 'kubectl logs --all-containers --tail=1000 --namespace {1} {2}'
}