From 47d983bedaa8d3f961920270f12b3c87bb118d43 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 16 Mar 2025 16:30:28 +0100 Subject: [PATCH] zzz --- .../home/profiles/bashrc.d/zeditor-remote.sh | 70 ++++++++++++++----- .../home/profiles/desktop/zed/default.nix | 8 ++- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/users/pbsds/home/profiles/bashrc.d/zeditor-remote.sh b/users/pbsds/home/profiles/bashrc.d/zeditor-remote.sh index 934f7eb..2ae5025 100644 --- a/users/pbsds/home/profiles/bashrc.d/zeditor-remote.sh +++ b/users/pbsds/home/profiles/bashrc.d/zeditor-remote.sh @@ -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 +} diff --git a/users/pbsds/home/profiles/desktop/zed/default.nix b/users/pbsds/home/profiles/desktop/zed/default.nix index ca9d0ad..811167a 100644 --- a/users/pbsds/home/profiles/desktop/zed/default.nix +++ b/users/pbsds/home/profiles/desktop/zed/default.nix @@ -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