Skip to content

Bash extractor: . "$(cd "$(dirname "$0")/.." && pwd)/lib/f.sh" (the script-dir idiom inline in source) gets no edge #5562

Backlog

Description

@yashsaxena

What happens

A script loads its library with the script-dir idiom written inline in the . (or source) line, with no variable:

. "$(cd "$(dirname "$0")/.." && pwd)/lib/greet.sh"

Graphify finds no file for it: no imports_from edge to lib/greet.sh, and no calls edge to the function the script then calls.
#3416 listed a form of this (its f4, with ${BASH_SOURCE[0]} and no ..); the $0 and /.. form below still gives nothing.

Reproduced on graphifyy 0.9.122 (newest on PyPI), installed with pip, nothing patched, Python 3.12, Ubuntu.

Reproduction

Two files in a new git repo:

# bin/tool
#!/usr/bin/env bash
. "$(cd "$(dirname "$0")/.." && pwd)/lib/greet.sh"
main() { greet world; }
main
# lib/greet.sh
greet() { echo "hello $1"; }

Command:

graphify extract "$PWD" --code-only --out /tmp/out
jq -r '.links[] | select(.relation != "contains" and .relation != "defines")
       | "\(.relation) \(.source) -> \(.target)"' /tmp/out/graphify-out/graph.json

Expected

imports_from bin/tool -> lib/greet.sh
calls bin/tool main -> lib/greet.sh greet

Got

calls bin/tool (script) -> bin/tool main

Cause and fix

The source branch strips a leading ${VAR} or $VAR, but not a leading $(cd "$(dirname "$0")/<rel>" && pwd).
Reading that idiom as the script's own folder plus <rel>, then the literal path after it, fixes it.

We carry this fix as a local patch and can open a PR.

Activity

  1. github-actions commented on Nov 28, 2026

    @github-actions

    Thanks for opening this issue, @yashsaxena. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions