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)
| 142 | |
| 143 | |
| 144 | def _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). |
no outgoing calls
no test coverage detected