MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _bash_inline_script_dir_path

Function _bash_inline_script_dir_path

graphify/extractors/bash.py:144–160  ·  view source on GitHub ↗

The file a ``source`` argument names with the script-dir idiom inline, as in ``. "$(cd "$(dirname "$0")/.." && pwd)/lib/x.sh"``, or None for any other form (#5562). The idiom is the script's folder, up one per ``/..``; a ``..`` in the literal path after it is not followed.

(raw: str, script_dir: Path)

Source from the content-addressed store, hash-verified

142
143
144def _bash_inline_script_dir_path(raw: str, script_dir: Path) -> Path | None:
145 """The file a ``source`` argument names with the script-dir idiom inline, as in
146 ``. "$(cd "$(dirname "$0")/.." && pwd)/lib/x.sh"``, or None for any other form
147 (#5562). The idiom is the script's folder, up one per ``/..``; a ``..`` in the
148 literal path after it is not followed."""
149 if not raw.startswith("$(cd ") or "dirname" not in raw:
150 return None
151 if "BASH_SOURCE" not in raw and "$0" not in raw:
152 return None
153 tail = _BASH_INLINE_PWD_PATH.search(raw)
154 if not tail or ".." in tail.group(1).split("/"):
155 return None
156 hops = _BASH_DIRNAME_IDIOM.search(raw)
157 base = script_dir
158 for _ in range((hops.group(1).count("..") if hops else 0)):
159 base = base.parent
160 return base / tail.group(1)
161
162# A path in the script's own folder, as in `$(dirname "$0")/x.sh` or
163# `$(dirname "${BASH_SOURCE[0]}")/lib/x.sh`: the path after it (#5575).

Callers 1

_process_source_commandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected