From 6bc31a2a4ad9ee7eb6e51640ff5f86387d07219c Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Jul 2021 18:07:14 +0100 Subject: [PATCH] Add some fzf based functions --- zsh/functions.zsh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/zsh/functions.zsh b/zsh/functions.zsh index be578a7..e787057 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -32,3 +32,38 @@ imkey () { echo $imkey } + +# Delete branches selected via fzf +delete-branches () { + git branch | + grep --invert-match '\*' | # Remove current branch + fzf --multi --preview="git log {..}" | + gxargs --no-run-if-empty git branch --delete +} + +# Delete branches selected via fzf (force the deletion) +delete-branches-force () { + git branch | + grep --invert-match '\*' | # Remove current branch + fzf --multi --preview="git log {..}" | + gxargs --no-run-if-empty git branch --delete --force +} + +# Open a PR +function pr-checkout() { + local pr_number + + pr_number=$( + gh api 'repos/:owner/:repo/pulls' --jq '.[] | "#\(.number) \(.title)"' | + fzf | + sd '^\#(\d+)\s.*' '$1' + ) + + if [ -n "$pr_number" ]; then + gh pr checkout "$pr_number" + fi +} + +function watch-file() { + tail -f $1 | bat --paging=never -l log +}