From 99e8dcfd3e2fa34d70220e895aebc65ef0b2df2e Mon Sep 17 00:00:00 2001 From: Noah Masur Date: Sat, 10 Apr 2021 17:08:54 -0400 Subject: [PATCH] more fzf utilities --- bin/pod | 16 ++++++++++++++ bin/quick-edit | 25 ++++++++++++++++++++++ fish.configlink/functions/git-history.fish | 16 ++++++++++++++ 3 files changed, 57 insertions(+) create mode 100755 bin/pod create mode 100755 bin/quick-edit create mode 100644 fish.configlink/functions/git-history.fish diff --git a/bin/pod b/bin/pod new file mode 100755 index 0000000..c1d491a --- /dev/null +++ b/bin/pod @@ -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 diff --git a/bin/quick-edit b/bin/quick-edit new file mode 100755 index 0000000..9ad7913 --- /dev/null +++ b/bin/quick-edit @@ -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]}" diff --git a/fish.configlink/functions/git-history.fish b/fish.configlink/functions/git-history.fish new file mode 100644 index 0000000..1865a54 --- /dev/null +++ b/fish.configlink/functions/git-history.fish @@ -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