From e65e714a6d5af8ed59fa02c3ed16711e3bfcaadf Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 29 May 2024 21:29:22 -0400 Subject: Rewrite ns.sh I first tried to make it into a two-level fzf menu, such that selecting a namespace dropped you into a second fzf interface that let you select the command you want to run. I did this because, often you want to perform multiple actions on the same namespace, rather than jump between namespaces. But this turned out to be unwieldy, so I went back to the single fzf with bindings for actions, and I just cleaned up the code and tried to make everything easier to read or use. --- Biz/Ide/ns.sh | 72 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 24 deletions(-) (limited to 'Biz/Ide') diff --git a/Biz/Ide/ns.sh b/Biz/Ide/ns.sh index 8641207..a56ed89 100755 --- a/Biz/Ide/ns.sh +++ b/Biz/Ide/ns.sh @@ -1,26 +1,50 @@ #!/usr/bin/env bash set -euo pipefail -fd --exclude=_ -t f . "${CODEROOT:?}" | sed "s,${CODEROOT:?}/*,,g" \ - | fzf \ - --bind "alt-space:execute(bild {} ; read -p [fin])" \ - --bind "alt-enter:execute(vim {})" \ - --bind "alt-c:execute(lint -f {} ; read -p [fin])" \ - --bind "enter:execute(repl.sh {})" \ - --bind "ctrl-space:execute(ship.sh {} ; read -p [fin])" \ - --bind "alt-t:execute(bild {} ; run.sh {} test ; read -p [fin])" \ - --bind "ctrl-/:change-preview-window(right,88|right,70%|hidden|)" \ - --bind "alt-0:change-preview(bat -p --color=always {})" \ - --bind "alt-1:change-preview(git log --color=always --date=relative --abbrev-commit --pretty=format:'%Cred%h%Creset %s / %an %Creset%C(yellow)%d%Creset%Cgreen(%cr)%Creset' -- {})" \ - --bind "alt-2:change-preview(git log --color=always {})" \ - --bind "alt-3:change-preview(git log --color=always -p {})" \ - --bind "alt-4:change-preview(git blame -c --date=short {})" \ - --bind "alt-5:change-preview(git log --pretty=short {} | git shortlog -nse)" \ - --bind "alt-6:change-preview(git log --pretty=short {} | git shortlog)" \ - --bind "backward-eof:abort" \ - --bind "pgup:preview-page-up" \ - --bind "pgdn:preview-page-down" \ - --header="repl: enter | edit: alt-enter | bild: alt-space | test: alt-t | lint: alt-c | ship: ctrl-space" \ - --header-first \ - --preview-window="border-sharp,bottom,70%" \ - --preview "bat -p --color=always {}" -### +nss="fd --color=always --exclude=_ -t f . \"${CODEROOT:?}\" | sed \"s,${CODEROOT:?}/*,,g\"" +keybindings=$(cat < ' -s':' -t <<< \"$keybindings\")" + --bind "alt-n:execute(touch {q})+reload($nss)" + --bind "alt-space:execute(bild {} ; read -p [fin])" + --bind "tab:execute($EDITOR {})" + --bind "alt-c:execute(lint -f {} ; read -p [fin])" + --bind "enter:execute(repl.sh {})" + --bind "alt-enter:execute(repl.sh --bash {})" + --bind "ctrl-space:execute(ship.sh {} ; read -p [fin])" + --bind "alt-t:execute(bild {} ; run.sh {} test ; read -p [fin])" + --bind "ctrl-/:change-preview-window(right,88|right,70%|hidden|)" + --bind "alt-0:change-preview(bat -p --color=always {})" + --bind "alt-1:change-preview(git log --color=always --date=relative --abbrev-commit --pretty=format:'%Cred%h%Creset %s / %an %Creset%C(yellow)%d%Creset%Cgreen(%cr)%Creset' -- {})" + --bind "alt-2:change-preview(git log --color=always {})" + --bind "alt-3:change-preview(git log --color=always -p {})" + --bind "alt-4:change-preview(git blame -c --date=short {})" + --bind "alt-5:change-preview(git log --pretty=short {} | git shortlog -nse)" + --bind "alt-6:change-preview(git log --pretty=short {} | git shortlog)" + --bind "backward-eof:abort" + --bind "pgup:preview-page-up" + --bind "pgdn:preview-page-down" + --header-first + --header="? for keybindings" + --border=top + --border-label="$(lolcat -f <<< "hack a namespace")" + --color=label:italic + --preview-window="bottom,80%" + --preview "bat -p --color=always {}" +) +sh -c "$nss" | fzf "${fzf_flags[@]}" + -- cgit v1.2.3