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

hist and fc: only run edited commands if changes are saved. #748

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

pghvlaans
Copy link

According to The New KornShell, the full editor history editing commands are only meant to execute command lines that have had saved changes:

"The command is the ksh line that you were editing with the vi built-in editor if you omit n, or command n in the history file. When you exit the vi program, ksh displays and executes the command if you have changed it. Version: With some early releases of the 11/16/88 version of ksh, the file was executed even if you had not changed it." (Bolsky & Korn, pg. 116)

The code needed in hist.c has apparently been missing since 1995 at the latest. This commit would implement (re-implement?) the functionality:

  • bltins/hist.c: If the full editor has been called, only execute the line being viewed if the contents have been changed and saved.
  • sh.1, data/builtins.c: Update the hist documentation accordingly.

@pghvlaans
Copy link
Author

Just a few quick notes about my testing round this time:

  • I no longer have access to a working macOS VM.
  • OmniOS and Haiku both experienced complete test failures on dev and my own branch. I'll try to look into this and open an issue.

@pghvlaans
Copy link
Author

Got rid of a couple of stray variables from testing and renamed some new variables I wasn't happy about.

@posguy99
Copy link

posguy99 commented May 1, 2024

Not documented in the Bolsky (as far as I know) are the ^X prefix commands supported by the emacs line editor. Chief among those is ^X ^E, as you know for bringing the current line into a full screen editor.

ksh, mksh, and bash all execute the line on return from the editor, even if there were no changes.

Since this patch isn't to either editor source file, it affects both?

@pghvlaans
Copy link
Author

ksh, mksh, and bash all execute the line on return from the editor, even if there were no changes.

Indeed. Personally, I think the book got it right and that's a bit of an anti-pattern, since the normal result of exiting an editor without saving is "nothing happens."

Since this patch isn't to either editor source file, it affects both?

Yes, that's right.

@posguy99
Copy link

posguy99 commented May 4, 2024

I tested it locally, works for me in vi or emacs mode.

@pghvlaans
Copy link
Author

Awesome, thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants