more fzf utilities

This commit is contained in:
Noah Masur 2021-04-10 17:08:54 -04:00
parent 980d0eda45
commit 99e8dcfd3e
3 changed files with 57 additions and 0 deletions

16
bin/pod Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Credit: https://github.com/junegunn/fzf/blob/master/ADVANCED.md
read -ra tokens < <(
kubectl get pods --all-namespaces |
fzf --info=inline --layout=reverse --header-lines=1 --border \
--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]}" -- /bin/sh

25
bin/quick-edit Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Credit: https://github.com/junegunn/fzf/blob/master/ADVANCED.md
# Requires bash.
# 1. Search for text in files using Ripgrep
# 2. Interactively narrow down the list using fzf
# 3. Open the file in Vim
IFS=: read -ra selected < <(
rg \
--color=always \
--line-number \
--no-heading \
--smart-case \
--iglob !/Library/** \
--iglob !/System/** \
--iglob "!Users/$HOME/Library/*" \
"${*:-}" |
fzf --ansi \
--color "hl:-1:underline,hl+:-1:underline:reverse" \
--delimiter : \
--preview 'bat --color=always {1} --highlight-line {2}' \
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
)
[ -n "${selected[0]}" ] && nvim "${selected[0]}" "+${selected[1]}"

View File

@ -0,0 +1,16 @@
function git-history
if not count $argv > /dev/null
echo "Must provide filename."
return 1
end
set commitline ( git log \
--follow \
--pretty="format:%C(auto)%ar %h%d %s" \
-- ./$argv \
| fzf \
--height 100% \
--preview "git diff --color=always (echo {} | cut -d' ' -f4)^1..(echo {} | cut -d' ' -f4) -- ./$argv" \
)
and set commit (echo $commitline | cut -d" " -f4)
and echo $commit
end