diff options
author | Tanaka Akira <akr@users.sourceforge.net> | 1999-07-12 17:02:40 +0000 |
---|---|---|
committer | Tanaka Akira <akr@users.sourceforge.net> | 1999-07-12 17:02:40 +0000 |
commit | 1f6786ef7ae24ff858f52c6d4ac2bc23d529c0c1 (patch) | |
tree | 608d6471d477e8d4d9eafa62f521be50c3248f6e /Src/prompt.c | |
parent | 7c670f1e6a0e154f0b1a2d4b6eed0e71c9404b56 (diff) | |
download | zsh-1f6786ef7ae24ff858f52c6d4ac2bc23d529c0c1.tar.gz zsh-1f6786ef7ae24ff858f52c6d4ac2bc23d529c0c1.tar.xz zsh-1f6786ef7ae24ff858f52c6d4ac2bc23d529c0c1.zip |
zsh-3.1.6-test-1 zsh-3.1.6-test-1
Diffstat (limited to 'Src/prompt.c')
-rw-r--r-- | Src/prompt.c | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/Src/prompt.c b/Src/prompt.c index 89407694e..dcba16d56 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -97,6 +97,38 @@ static int dontcount; static char *rstring, *Rstring; +/* + * Expand path p; maximum is npath segments where 0 means the whole path. + * If tilde is 1, try and find a named directory to use. + */ + +static void +promptpath(char *p, int npath, int tilde) +{ + char *modp = p; + Nameddir nd; + + if (tilde && ((nd = finddir(p)))) + modp = tricat("~", nd->nam, p + strlen(nd->dir)); + + if (npath) { + char *sptr; + for (sptr = modp + strlen(modp); sptr > modp; sptr--) { + if (*sptr == '/' && !--npath) { + sptr++; + break; + } + } + if (*sptr == '/' && sptr[1] && sptr != modp) + sptr++; + stradd(sptr); + } else + stradd(modp); + + if (p != modp) + zsfree(modp); +} + /* Perform prompt expansion on a string, putting the result in a * * permanently-allocated string. If ns is non-zero, this string * * may have embedded Inpar and Outpar, which indicate a toggling * @@ -293,49 +325,21 @@ putpromptchar(int doprint, int endchar) } switch (*fm) { case '~': - if ((nd = finddir(pwd))) { - char *t = tricat("~", nd->nam, pwd + strlen(nd->dir)); - stradd(t); - zsfree(t); - break; - } + promptpath(pwd, arg, 1); + break; case 'd': case '/': - stradd(pwd); + promptpath(pwd, arg, 0); break; case 'c': case '.': - { - char *t; - - if ((nd = finddir(pwd))) - t = tricat("~", nd->nam, pwd + strlen(nd->dir)); - else - t = ztrdup(pwd); - if (!arg) - arg++; - for (ss = t + strlen(t); ss > t; ss--) - if (*ss == '/' && !--arg) { - ss++; - break; - } - if(*ss == '/' && ss[1] && ss != t) - ss++; - stradd(ss); - zsfree(t); - break; - } + promptpath(pwd, arg ? arg : 1, 1); + break; case 'C': - if (!arg) - arg++; - for (ss = pwd + strlen(pwd); ss > pwd; ss--) - if (*ss == '/' && !--arg) { - ss++; - break; - } - if (*ss == '/' && ss[1] && (ss != pwd)) - ss++; - stradd(ss); + promptpath(pwd, arg ? arg : 1, 0); + break; + case 'N': + promptpath(scriptname ? scriptname : argzero, arg, 0); break; case 'h': case '!': @@ -536,9 +540,6 @@ putpromptchar(int doprint, int endchar) sprintf(bp, "%ld", (long)lineno); bp += strlen(bp); break; - case 'N': - stradd(scriptname ? scriptname : argzero); - break; case '\0': return 0; case Meta: |