MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sh_eval_subst_command

Function sh_eval_subst_command

src/pipeline/pass_shell.c:828–850  ·  view source on GitHub ↗

$(dirname ..), $(basename ..), $(pwd), $(realpath ..), $(readlink -f ..), * $(git rev-parse --show-toplevel). */

Source from the content-addressed store, hash-verified

826/* $(dirname ..), $(basename ..), $(pwd), $(realpath ..), $(readlink -f ..),
827 * $(git rev-parse --show-toplevel). */
828static const char *sh_eval_subst_command(sh_t *s, TSNode cmd) {
829 sh_argv_t a = {0};
830 sh_argv_build(s, cmd, &a);
831 const char *out = NULL;
832 const char *name = a.n > 0 ? a.v[0] : NULL;
833 if (sh_eq(name, "dirname") && a.n == PAIR_LEN && a.v[SKIP_ONE]) {
834 out = sh_dirname(s->a, a.v[SKIP_ONE]);
835 } else if (sh_eq(name, "basename") && a.n == PAIR_LEN && a.v[SKIP_ONE]) {
836 out = sh_value_basename(s->a, a.v[SKIP_ONE]);
837 } else if (sh_eq(name, "pwd")) {
838 out = sh_cwd_value(s);
839 } else if (sh_eq(name, "realpath") ||
840 (sh_eq(name, "readlink") && a.n > PAIR_LEN && a.v[SKIP_ONE] &&
841 (sh_eq(a.v[SKIP_ONE], "-f") || sh_eq(a.v[SKIP_ONE], "-e") ||
842 sh_eq(a.v[SKIP_ONE], "-m")))) {
843 out = sh_absolute(s, sh_first_operand(&a, SKIP_ONE));
844 } else if (sh_eq(name, "git") && a.n == 3 && sh_eq(a.v[SKIP_ONE], "rev-parse") &&
845 sh_eq(a.v[PAIR_LEN], "--show-toplevel")) {
846 out = SH_ROOT;
847 }
848 sh_argv_free(&a);
849 return out;
850}
851
852/* `cd DIR` as the left half of $(cd DIR && pwd): the directory, or NULL. */
853static const char *sh_subst_cd(sh_t *s, TSNode cd) {

Callers 1

sh_eval_substFunction · 0.85

Calls 8

sh_argv_buildFunction · 0.85
sh_eqFunction · 0.85
sh_dirnameFunction · 0.85
sh_value_basenameFunction · 0.85
sh_cwd_valueFunction · 0.85
sh_absoluteFunction · 0.85
sh_first_operandFunction · 0.85
sh_argv_freeFunction · 0.85

Tested by

no test coverage detected