`cd DIR` as the left half of $(cd DIR && pwd): the directory, or NULL. */
| 851 | |
| 852 | /* `cd DIR` as the left half of $(cd DIR && pwd): the directory, or NULL. */ |
| 853 | static 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 | |
| 870 | static bool sh_is_pwd(sh_t *s, TSNode n) { |
| 871 | n = sh_unwrap(n); |
no test coverage detected