mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-15 23:03:47 -05:00
ADVANCED.md: Add change-preview-window example
This commit is contained in:
38
ADVANCED.md
38
ADVANCED.md
@@ -429,30 +429,34 @@ Admittedly, that was a silly example. Here's a practical one for browsing
|
|||||||
Kubernetes pods.
|
Kubernetes pods.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
#!/usr/bin/env bash
|
pods() {
|
||||||
|
FZF_DEFAULT_COMMAND="kubectl get pods --all-namespaces" \
|
||||||
read -ra tokens < <(
|
fzf --info=inline --layout=reverse --header-lines=1 \
|
||||||
kubectl get pods --all-namespaces |
|
|
||||||
fzf --info=inline --layout=reverse --header-lines=1 --border \
|
|
||||||
--prompt "$(kubectl config current-context | sed 's/-context$//')> " \
|
--prompt "$(kubectl config current-context | sed 's/-context$//')> " \
|
||||||
--header $'Press CTRL-O to open log in editor\n\n' \
|
--header $'╱ Enter (kubectl exec) ╱ CTRL-O (open log in editor) ╱ CTRL-R (reload) ╱\n\n' \
|
||||||
--bind ctrl-/:toggle-preview \
|
--bind 'ctrl-/:change-preview-window(80%,border-bottom|hidden|)' \
|
||||||
--bind 'ctrl-o:execute:${EDITOR:-vim} <(kubectl logs --namespace {1} {2}) > /dev/tty' \
|
--bind 'enter:execute:kubectl exec -it --namespace {1} {2} -- bash > /dev/tty' \
|
||||||
--preview-window up,follow \
|
--bind 'ctrl-o:execute:${EDITOR:-vim} <(kubectl logs --all-containers --namespace {1} {2}) > /dev/tty' \
|
||||||
--preview 'kubectl logs --follow --tail=100000 --namespace {1} {2}' "$@"
|
--bind 'ctrl-r:reload:$FZF_DEFAULT_COMMAND' \
|
||||||
)
|
--preview-window up:follow \
|
||||||
[ ${#tokens} -gt 1 ] &&
|
--preview 'kubectl logs --follow --all-containers --tail=10000 --namespace {1} {2}' "$@"
|
||||||
kubectl exec -it --namespace "${tokens[0]}" "${tokens[1]}" -- bash
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
- The preview window will *"log tail"* the pod
|
- The preview window will *"log tail"* the pod
|
||||||
- Holding on to a large amount of log will consume a lot of memory. So we
|
- Holding on to a large amount of log will consume a lot of memory. So we
|
||||||
limited the initial log amount with `--tail=100000`.
|
limited the initial log amount with `--tail=10000`.
|
||||||
- With `execute` binding, you can press CTRL-O to open the log in your editor
|
- `execute` bindings allow you to run any command without leaving fzf
|
||||||
without leaving fzf
|
- Press enter key on a pod to `kubectl exec` into it
|
||||||
- Select a pod (with an enter key) to `kubectl exec` into it
|
- Press CTRL-O to open the log in your editor
|
||||||
|
- Press CTRL-R to reload the pod list
|
||||||
|
- Press CTRL-/ repeatedly to to rotate through a different sets of preview
|
||||||
|
window options
|
||||||
|
1. `80%,border-bottom`
|
||||||
|
1. `hidden`
|
||||||
|
1. Empty string after `|` translates to the default options from `--preview-window`
|
||||||
|
|
||||||
Key bindings for git objects
|
Key bindings for git objects
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user