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

Function sh_subst_cd

src/pipeline/pass_shell.c:853–868  ·  view source on GitHub ↗

`cd DIR` as the left half of $(cd DIR && pwd): the directory, or NULL. */

Source from the content-addressed store, hash-verified

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) {
854 cd = sh_unwrap(cd);
855 if (!sh_type(cd, "command")) {
856 return NULL;
857 }
858 sh_argv_t a = {0};
859 sh_argv_build(s, cd, &a);
860 const char *out = NULL;
861 if (a.n > 0 && sh_eq(a.v[0], "cd")) {
862 sh_cwd_t to = {SH_LOST, NULL};
863 (void)sh_cd_target(s, sh_first_operand(&a, SKIP_ONE), &to);
864 out = to.mode == SH_AT ? sh_anchor(s->a, to.dir) : NULL;
865 }
866 sh_argv_free(&a);
867 return out;
868}
869
870static bool sh_is_pwd(sh_t *s, TSNode n) {
871 n = sh_unwrap(n);

Callers 1

sh_eval_substFunction · 0.85

Calls 8

sh_unwrapFunction · 0.85
sh_typeFunction · 0.85
sh_argv_buildFunction · 0.85
sh_eqFunction · 0.85
sh_cd_targetFunction · 0.85
sh_first_operandFunction · 0.85
sh_anchorFunction · 0.85
sh_argv_freeFunction · 0.85

Tested by

no test coverage detected