This commit is contained in:
2025-03-16 16:30:28 +01:00
parent f17df30623
commit 47d983beda
2 changed files with 59 additions and 19 deletions

View File

@@ -1,31 +1,65 @@
zeditor-remote() (
set -euo pipefail
zeditor-remote() {
if printf '%s\n' "$(gum --version)" "gum version 0.15.1" | sort -C -V; then
maybe_spin="" # doesn't forward stdin
local maybe_spin="" # doesn't forward stdin
else
maybe_spin="gum spin --show-output --show-error --"
local maybe_spin="gum spin --show-output --show-error --"
fi
# echo maybe_spin="$maybe_spin"
host=$(
local host=$(
{
echo localhost
tailscale status --json | jq .Peer[].HostName -r
} | sort -u | fzf --multi --reverse --bind 'ctrl-a:toggle-all' --height=25
tailscale status --json | jq .Peer[].HostName -r | grep -v '^localhost$' | sort -u
} | fzf --multi --reverse --bind 'ctrl-a:toggle-all' --height=25 --cycle \
| sed -e 's/%/%%/g'
)
if [[ -z "$host" ]]; then
exit
return
fi
repos=$(
set +e +o pipefail
$maybe_spin xe -j"$(wc -l <<<"$host")" <<<"$host" -s 'timeout 7 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$1" fd "^\.git$" repos/ --hidden --max-depth 5 -x printf '"'"'"zeditor ssh://%s/~/%s\n"'"'"' "$1" "{//}" 2>/dev/null' | sort
local repos=$(
worker() {
local host="$1"
fdargs=(repos/ --hidden --max-depth 5)
sshargs=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null)
if [[ "$host" = localhost ]]; then
cd "$HOME"
fd "^\.git$" "${fdargs[@]}" -x printf '~/%q\n' "{//}"
else
timeout 5 ssh "${sshargs[@]}" 2>/dev/null "$host" \
fd "^\.git$" "${fdargs[@]}" -x printf "'ssh://$host/~/%q\n'" "'{//}'"
fi
}
$maybe_spin xe <<<"$host" -j"$(wc -l <<<"$host")" -s "$(declare -f worker); worker \"\$@\"" 2>/dev/null ||:
)
if [[ -z "${repos}" ]]; then
echo >&2 "no repos found!"
return 1
fi
choice=$(fzf <<<"$repos" --reverse --height=25)
printf "%s\n" "$choice"
rg <<<"$choice" '^zeditor ssh://([^/]*)/(~/.*)$' -r 'ssh -t $1 "cd $2; $$SHELL -l"' ||:
bash "$choice"
)
local choice=$(sort <<<"$repos" | fzf --reverse --height=25)
if [[ -z "${choice}" ]]; then
return
fi
local zed_cmd="zeditor ${choice}"
local ssh_cd_cmd=$(
rg <<<"$choice" '^ssh://([^/]*)/(~/.*)$' -r 'ssh -t "$1" "cd $2; $$SHELL -l"' ||:
)
[[ -z "$zed_cmd" ]] || echo "$zed_cmd"
[[ -z "$ssh_cd_cmd" ]] || echo "$ssh_cd_cmd"
if [[ -n "$ssh_cd_cmd" ]] && gum confirm "SSH in there?" --default=yes; then
# history -s "${zed_cmd}"
eval ${zed_cmd}
# TODO: find a way to not push the rest of the unpushed history
history -s "${ssh_cd_cmd}"
history -a
eval ${ssh_cd_cmd}
else
# history -s "${zed_cmd}"
eval ${zed_cmd}
cd "${choice}"
fi
}

View File

@@ -6,9 +6,15 @@
home.packages = with pkgs; [
unstable.zed-editor
# needed builtin plugins paths:
unstable.package-version-server # Zed autodownloads this
vscode-langservers-extracted # vscode-{css,eslint,html,json,markdown}-language-server
taplo # toml lsp
# needed community lsp
nixd
nil
unstable.nixfmt-rfc-style
harper
typos-lsp