@@ -33,6 +33,7 @@ EXAMPLES:
3333 $cmd + Create workspace with random name
3434 $cmd -myproject Delete workspace matching myproject
3535 $cmd --delete react Delete workspace matching react
36+ $cmd - Delete the workspace containing the current directory
3637 $cmd -p ~/projects Use custom workspace path
3738 $cmd -l List all workspaces
3839
@@ -241,7 +242,7 @@ delete_workspace() {
241242
242243 # Defensive: ensure resolved path stays inside tries_path
243244 local resolved
244- resolved=$( cd " $full_path " 2> /dev/null && pwd) || {
245+ resolved=$( cd " $full_path " 2> /dev/null && pwd -P ) || {
245246 echo " Error: cannot resolve $full_path "
246247 return 1
247248 }
@@ -252,7 +253,8 @@ delete_workspace() {
252253
253254 # Warn if caller's CWD is inside the workspace being deleted - the parent
254255 # shell will be left in a stale directory (we can't cd it from here).
255- local caller_pwd=" ${PWD:- } "
256+ local caller_pwd
257+ caller_pwd=$( pwd -P 2> /dev/null || echo " " )
256258 if [[ -n " $caller_pwd " && ( " $caller_pwd " == " $resolved " || " $caller_pwd " == " $resolved " /* ) ]]; then
257259 echo " Warning: your shell is inside $resolved - cd elsewhere before/after to avoid a stale CWD"
258260 fi
@@ -285,6 +287,7 @@ main() {
285287 local search_term=" "
286288 local list_mode=false
287289 local delete_name=" "
290+ local delete_cwd=false
288291
289292 # Parse options
290293 while [[ $# -gt 0 ]]; do
@@ -311,6 +314,11 @@ main() {
311314 search_term=" +${1:- } "
312315 shift || true
313316 ;;
317+ -)
318+ # Bare "-" deletes the workspace containing $PWD
319+ delete_cwd=true
320+ shift
321+ ;;
314322 -* )
315323 # -NAME shorthand for deletion (parallels +NAME for creation)
316324 delete_name=" ${1# -} "
@@ -324,14 +332,34 @@ main() {
324332 done
325333
326334 mkdir -p " $tries_path "
327- tries_path=$( cd " $tries_path " && pwd)
335+ tries_path=$( cd " $tries_path " && pwd -P )
328336
329337 # If --list mode, display workspaces and exit
330338 if [[ " $list_mode " == true ]]; then
331339 list_workspaces " $tries_path "
332340 exit $?
333341 fi
334342
343+ # Resolve bare "-" to the workspace containing $PWD
344+ if [[ " $delete_cwd " == true ]]; then
345+ local cwd_resolved
346+ cwd_resolved=$( pwd -P 2> /dev/null) || {
347+ echo " Error: cannot resolve current directory"
348+ exit 1
349+ }
350+ if [[ " $cwd_resolved " == " $tries_path " ]]; then
351+ echo " Error: at workspace root - cd into a workspace first (cwd: $cwd_resolved )"
352+ exit 1
353+ fi
354+ if [[ " $cwd_resolved " != " $tries_path " /* ]]; then
355+ echo " Error: not inside $tries_path (cwd: $cwd_resolved )"
356+ exit 1
357+ fi
358+ # First path component after tries_path is the workspace name
359+ local remainder=" ${cwd_resolved# " $tries_path " / } "
360+ delete_name=" ${remainder%%/* } "
361+ fi
362+
335363 # If delete requested, run delete flow and exit
336364 if [[ -n " $delete_name " ]]; then
337365 delete_workspace " $tries_path " " $delete_name "
0 commit comments