diff --git a/config/shell/bercail.inc.sh b/config/shell/bercail.inc.sh index 16af3a1..8376632 100644 --- a/config/shell/bercail.inc.sh +++ b/config/shell/bercail.inc.sh @@ -24,10 +24,15 @@ d() { alias dev='worktree-dev' alias t='herdr' +# `wt list --format=json` returns a plain array before worktrunk 0.80 and +# {schema, items: [...]} (path under .worktree.path) from 0.80 on. +_wt_list_items_jq='if type == "object" then .items else . end' + _wt_worktree_path_for_branch() { local branch="$1" wt list --format=json 2>/dev/null \ - | jq -r --arg branch "$branch" 'map(select(.branch == $branch)) | .[0].path' + | jq -r --arg branch "$branch" \ + "${_wt_list_items_jq} | map(select(.branch == \$branch)) | .[0] | (.worktree.path? // .path)" } _wt_branch_exists() { @@ -120,7 +125,7 @@ wts() { local branch="$1" if [[ -z "$branch" ]]; then - branch=$(wt list --format=json 2>/dev/null | jq -r '.[].branch' | fzf --header="Select worktree:" --tiebreak=index) + branch=$(wt list --format=json 2>/dev/null | jq -r "${_wt_list_items_jq} | .[].branch" | fzf --header="Select worktree:" --tiebreak=index) [[ -z "$branch" ]] && { echo "No worktree selected"; return 1; } fi