Oi: workspace detection instead of raw pwd
- Walk up from pwd looking for workspace indicators (.mdworkspace) - Skip submodules (.git file with /modules/), stop at worktrees - Fall back to nearest real git root (.git directory) - Error if not in any git repo or workspace
This commit is contained in:
parent
6557d80788
commit
ae40aeff1b
36
scripts/Oi
36
scripts/Oi
|
|
@ -10,8 +10,40 @@ die() { printf '%s: %s\n' "$cmd" "$*" >&2; exit 1; }
|
|||
OLLIE=${OLLIE:-$HOME/mnt/ollie}
|
||||
try() { "$@" 2>/dev/null || { ollie-remount && "$@"; }; }
|
||||
|
||||
# Derive deterministic session name from cwd
|
||||
cwd=$(pwd)
|
||||
# Workspace detection: find workspace root (indicator file) or git/worktree root.
|
||||
# Indicators: comma-delimited list of filenames that mark a workspace.
|
||||
WORKSPACE_INDICATORS=".mdworkspace"
|
||||
|
||||
detect_workspace() {
|
||||
local dir="$1"
|
||||
local git_root=""
|
||||
|
||||
while [ "$dir" != "/" ]; do
|
||||
# Check for workspace indicator
|
||||
local IFS=,
|
||||
for ind in $WORKSPACE_INDICATORS; do
|
||||
[ -e "$dir/$ind" ] && { printf '%s\n' "$dir"; return; }
|
||||
done
|
||||
unset IFS
|
||||
# Check for .git
|
||||
if [ -z "$git_root" ] && [ -e "$dir/.git" ]; then
|
||||
if [ -d "$dir/.git" ]; then
|
||||
# Real repo — this is a root
|
||||
git_root="$dir"
|
||||
elif ! grep -q '/modules/' "$dir/.git" 2>/dev/null; then
|
||||
# Worktree (.git file pointing to .git/worktrees/) — treat as root
|
||||
git_root="$dir"
|
||||
fi
|
||||
# Submodule (.git file pointing to .git/modules/) — skip
|
||||
fi
|
||||
dir=$(dirname "$dir")
|
||||
done
|
||||
|
||||
[ -n "$git_root" ] && { printf '%s\n' "$git_root"; return; }
|
||||
return 1
|
||||
}
|
||||
|
||||
cwd=$(detect_workspace "$(pwd)") || die "not in a git repo or workspace"
|
||||
hash=$(printf '%s' "$cwd" | cksum | awk '{print $1}')
|
||||
NAV_NAME="nav-${hash}"
|
||||
NAV_PATH="$OLLIE/s/$NAV_NAME"
|
||||
|
|
|
|||
Reference in New Issue