Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: P modify in history event



Peter Stephenson wrote on Mon, 18 Nov 2019 09:47 +00:00:
> On Sun, 2019-11-17 at 12:42 -0600, Perry Smith wrote:
> > I’m (slowly) reading through zshexpn and playing with things to
> > learn.  This does not work:
> > 
> > > 
> > > pedz@MysticSlate my-play-dir % echo /this/is/a/../../path
> > > /this/is/a/../../path
> > > pedz@MysticSlate my-play-dir % echo !$:P
> > > zsh: illegal modifier: P
> > even if the file specified exists
> 
> I think it just got missed out of the history modifiers, which are
> handled in a different place from the modifiers in the case of glob
> qualifiers and vaariables.

Thanks for fixing this.  Test added in 030440d5b7bfd2968138836e962f1ef61ea0bae8.

> +++ b/Src/hist.c
> @@ -920,6 +920,16 @@ histsubchar(int c)
> +	    case 'P':
> +		if (*sline != '/') {
> +		    char *here = zgetcwd();
> +		    if (here[strlen(here)-1] != '/')

Can «zgetcwd()» return an empty string?  If that's possible, the
condition will be undefined behaviour («""[-1]»).

> +			sline = zhtricat(metafy(here, -1, META_HEAPDUP), "/", sline);
> +		    else
> +			sline = dyncat(here, sline);
> +		}
> +		sline = xsymlink(sline, 1);
> +		break;

Cheers,

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author