Zed terminal integration: auto-create workspace scoped to project directory #841
Unanswered
sumit-poudel
asked this question in
Q&A
Replies: 3 comments
|
I'm also in the same dilemma. zed-industries/zed#62072 |
0 replies
|
@sumit-poudel I vibe coded a script which partially solves the problem. Details
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat << 'EOF'
Usage: herdr-open [DIR]
Opens or creates a Herdr workspace for the given directory.
Default: current directory.
EOF
exit "${1:-0}"
}
dir="${1:-.}"
dir="$(cd "$dir" 2> /dev/null && pwd)" || {
echo >&2 "Directory does not exist: ${1:-.}"
exit 1
}
herdr workspace list --format json > /dev/null 2>&1 || true
# Find an existing workspace bound to this directory (worktree source or plain cwd).
find_workspace() {
local target="$1"
herdr workspace list > /dev/null 2>&1 || true
}
# Collect workspace IDs whose root path matches $dir.
candidate_ids=$(
herdr workspace list 2> /dev/null \
| yq -r '.result.workspaces[].workspace_id' || true
)
matched_workspace_id=""
for ws_id in $candidate_ids; do
info=$(herdr workspace get "$ws_id" 2> /dev/null || true)
# Check worktree list first.
wt=$(herdr worktree list 2> /dev/null || true)
if [ -n "$wt" ]; then
open_id=$(printf '%s' "$wt" | yq -r --arg dir "$dir" '
.result.worktrees[]
| select(.path == $dir)
| .open_workspace_id // ""
' 2> /dev/null || true)
if [ "$open_id" = "$ws_id" ]; then
matched_workspace_id="$ws_id"
break
fi
fi
# Fallback: match workspace label against basename of dir.
label=$(printf '%s' "$info" | yq -r '
.result.workspace.label // ""
' 2> /dev/null || true)
if [ "${label}" = "$(basename "$dir")" ]; then
matched_workspace_id="$ws_id"
break
fi
done
if [ -n "$matched_workspace_id" ]; then
echo "Found existing Herdr workspace: $matched_workspace_id ($dir)"
herdr workspace focus "$matched_workspace_id"
exec herdr
fi
# Decide whether we can create a git worktree.
if git -C "$dir" rev-parse --is-inside-work-tree > /dev/null 2>&1; then
if [ -d "$dir/.git" ] || [ -f "$dir/.git" ]; then
echo "Directory already contains a Git checkout. Creating plain Herdr workspace for $dir..."
herdr workspace create \
--cwd "$dir" \
--label "$(basename "$dir")" \
--focus
exec herdr
else
branch="$(git -C "$dir" branch --show-current 2> /dev/null || echo main)"
echo "Creating Git worktree workspace for $dir..."
# --path uses the directory itself as the checkout path.
herdr worktree create \
--path "$dir" \
--branch "$branch" \
--label "$(basename "$dir")" \
--focus
exec herdr
fi
else
echo "Directory is not a Git repo. Creating plain Herdr workspace for $dir..."
herdr workspace create \
--cwd "$dir" \
--label "$(basename "$dir")" \
--focus
exec herdr
fi
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
question
I'm migrating from tmux to Herdr. In tmux, I used this Zed terminal config to automatically create or attach to a named session scoped to the current project directory:
But Herdr docs only show
--cwdas a flag forworkspace create, so I'm in an awkward dilemma where I can't create a workspace without a session already running, and opening a session won't open the workspace.The closest working config I've found:
I can attach to the session only and
cdmy way to the project, but I'd prefer not to if possible.context
No response
All reactions