summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2021-12-24 14:41:47 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2021-12-24 14:41:47 +0900
commit4311ade53565d27131d929b5a3fb55ce61be1523 (patch)
tree8f2810649ff68c3e78738f4d80384bce532f7203
parentcd2340141100e057005d31e653c0ce7a0f7a4af7 (diff)
ADVANCED.md: Add change-preview-window example
-rw-r--r--ADVANCED.md38
1 files changed, 21 insertions, 17 deletions
diff --git a/ADVANCED.md b/ADVANCED.md
index f00be0c5..111a1ae5 100644
--- a/ADVANCED.md
+++ b/ADVANCED.md
@@ -429,30 +429,34 @@ Admittedly, that was a silly example. Here's a practical one for browsing
Kubernetes pods.
```bash
-#!/usr/bin/env bash
-
-read -ra tokens < <(
- kubectl get pods --all-namespaces |
- fzf --info=inline --layout=reverse --header-lines=1 --border \
+pods() {
+ FZF_DEFAULT_COMMAND="kubectl get pods --all-namespaces" \
+ fzf --info=inline --layout=reverse --header-lines=1 \
--prompt "$(kubectl config current-context | sed 's/-context$//')> " \
- --header $'Press CTRL-O to open log in editor\n\n' \
- --bind ctrl-/:toggle-preview \
- --bind 'ctrl-o:execute:${EDITOR:-vim} <(kubectl logs --namespace {1} {2}) > /dev/tty' \
- --preview-window up,follow \
- --preview 'kubectl logs --follow --tail=100000 --namespace {1} {2}' "$@"
-)
-[ ${#tokens} -gt 1 ] &&
- kubectl exec -it --namespace "${tokens[0]}" "${tokens[1]}" -- bash
+ --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:kubectl exec -it --namespace {1} {2} -- bash > /dev/tty' \
+ --bind 'ctrl-o:execute:${EDITOR:-vim} <(kubectl logs --all-containers --namespace {1} {2}) > /dev/tty' \
+ --bind 'ctrl-r:reload:$FZF_DEFAULT_COMMAND' \
+ --preview-window up:follow \
+ --preview 'kubectl logs --follow --all-containers --tail=10000 --namespace {1} {2}' "$@"
+}
```
![image](https://user-images.githubusercontent.com/700826/113473547-1d7a4880-94a5-11eb-98ef-9aa6f0ed215a.png)
- The preview window will *"log tail"* the pod
- Holding on to a large amount of log will consume a lot of memory. So we
- limited the initial log amount with `--tail=100000`.
-- With `execute` binding, you can press CTRL-O to open the log in your editor
- without leaving fzf
-- Select a pod (with an enter key) to `kubectl exec` into it
+ limited the initial log amount with `--tail=10000`.
+- `execute` bindings allow you to run any command without leaving fzf
+ - Press enter key on a pod 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
----------------------------