Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance M-. parsing #802

Open
adavies42 opened this issue Dec 6, 2024 · 2 comments
Open

enhance M-. parsing #802

adavies42 opened this issue Dec 6, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@adavies42
Copy link

afaict M-. currently inserts the last word of the last command as defined only by splitting on spaces

it would be nice to have at least a little of the improvement readline provides for this action, e.g. that it should also split on redirect instructions -- if i do

... >file
cat <M-.>

then in bash the second command is cat file, but in ksh, it's cat >file, which is actively harmful, since it wipes file

however, exactly what to change here should be considered carefully, as readline's version is so "enhanced" that it sometimes returns something that i can't figure out the source of

@McDutchie McDutchie added the enhancement New feature or request label Dec 7, 2024
@McDutchie
Copy link

Took me a minute to figure out the context. This is about ESC . aka ESC _ in emacs.

Any changes here would also affect the _ command in vi, as they use the same hist_word function to find words.

@McDutchie
Copy link

It is probably best to use the same word boundary characters as those introduced for history expansion in 0a71a8a.

Try this patch:

diff --git a/src/cmd/ksh93/edit/history.c b/src/cmd/ksh93/edit/history.c
index 94cf50536..5f0228e6e 100644
--- a/src/cmd/ksh93/edit/history.c
+++ b/src/cmd/ksh93/edit/history.c
@@ -1015,7 +1015,7 @@ char *hist_word(char *string,int size,int word)
 	hist_copy(string,size,(int)hp->histind-1,-1);
 	for(quoted=0;c = *cp;cp++)
 	{
-		is_space = isspace(c) && !quoted;
+		is_space = !quoted && (isspace(c) || strchr("|&;()`<>",c));
 		if(is_space && flag)
 		{
 			*cp = 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants