$(dirname ..), $(basename ..), $(pwd), $(realpath ..), $(readlink -f ..), * $(git rev-parse --show-toplevel). */
| 826 | /* $(dirname ..), $(basename ..), $(pwd), $(realpath ..), $(readlink -f ..), |
| 827 | * $(git rev-parse --show-toplevel). */ |
| 828 | static 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. */ |
| 853 | static const char *sh_subst_cd(sh_t *s, TSNode cd) { |
no test coverage detected