Skip to content

preexec, right prompt & ps0 functionality #835

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

Open
tungstengmd opened this issue Mar 23, 2025 · 17 comments
Open

preexec, right prompt & ps0 functionality #835

tungstengmd opened this issue Mar 23, 2025 · 17 comments
Labels
1.1 Issue relevant to dev branch (v1.1.*) enhancement New feature or request

Comments

@tungstengmd
Copy link

i like zsh's preexec feature and was thinking it'd be awesome for a similar feature in ksh
and also the ps0 feature from bash which replaces the prompt before a typed command is executed

@McDutchie McDutchie added enhancement New feature or request 1.1 Issue relevant to dev branch (v1.1.*) labels Mar 23, 2025
@McDutchie
Copy link

I'll think about it.

bash's PS0 variable might not be a bad thing to add, and it should be fairly trivial to implement.

As for zsh's preexec function, ksh's DEBUG trap currently provides very similar functionality, so I don't know about that one.

@tungstengmd
Copy link
Author

i did hear about the DEBUG trap, i mainly forgot about it because of mksh's lack of support for it 😔 but yea ps0 would be nice, it'll make life easier when making transient prompts

@tungstengmd
Copy link
Author

oh and also PLEASE add right prompt functionality bc doing it manually makes history scrolling kill itself 🥺

@tungstengmd tungstengmd changed the title preexec & ps0 functionality preexec, right prompt & ps0 functionality Apr 2, 2025
@posguy99
Copy link

posguy99 commented Apr 2, 2025

oh and also PLEASE add right prompt functionality bc doing it manually makes history scrolling kill itself 🥺

What is "right prompt"? I have a complex prompt with no problem.

@tungstengmd
Copy link
Author

oh and also PLEASE add right prompt functionality bc doing it manually makes history scrolling kill itself 🥺

What is "right prompt"? I have a complex prompt with no problem.

right prompt would be a part of the prompt shifted to the right side of the screen, see starship or powerlevel10k

@tungstengmd
Copy link
Author

i'll use this to add enhancements that'd make this generally nicer for interactive use

  • a good default prompt
  • tab completion for commands
  • make existing file completion and cd case-insensitive
  • key binds that aren't a hacky mess

@nickpapadonis
Copy link

nickpapadonis commented Apr 8, 2025

DEBUG trap and PS0/1 functionality is working in these dot files along with window manager escape codes. MacOS Terminal.app working directory dropdown is correctly updated and the current executed command is displayed in the title. I tested with xterm and rxvt as well. There was a bug recently fixed and the script depends on latest ksh build in order to update using DEBUG trap. See .kshrc .sh-cmnprompt. If you're interested the same prompt and title bar works for .bashrc and .zshrc as well. All tested on Darwin. Also, the dot files have conditional code to display color if the terminal supports it using tput and when Emacs M-x shell is invoked ksh appears to work correctly.

https://github.com/nickpapadonis/home-dot

There were comments on command completion in this. Is case insensitive vs sensitive an option?

@nickpapadonis
Copy link

i'll use this to add enhancements that'd make this generally nicer for interactive use

  • a good default prompt
  • tab completion for commands
  • make existing file completion and cd case-insensitive
  • key binds that aren't a hacky mess

What key bindings are a mess? I noted the biggest problem for me was M-x for Emacs like completion. In Terminal.app it was checking a conditional to allow M-x from Option. For xterm and XQuartz there is an .xmodmap file in the above dot files repo that remaps the command key to Meta, which is also helpful at the prompt.

@tungstengmd
Copy link
Author

i'll use this to add enhancements that'd make this generally nicer for interactive use

  • a good default prompt
  • tab completion for commands
  • make existing file completion and cd case-insensitive
  • key binds that aren't a hacky mess

What key bindings are a mess? I noted the biggest problem for me was M-x for Emacs like completion. In Terminal.app it was checking a conditional to allow M-x from Option. For xterm and XQuartz there is an .xmodmap file in the above dot files repo that remaps the command key to Meta, which is also helpful at the prompt.

i meant to set keybinds in a not-hacky way

@posguy99
Copy link

posguy99 commented Apr 8, 2025

i meant to set keybinds in a not-hacky way

What "hacky" way is there? There's the method from the Bolsky, written by dgk (and shipped with the shell). And there's the RedHat way, with a big case statement. Both seem pretty straightforward.

https://github.com/posguy99/dotfiles/blob/c7e17150b160e2b7e91d8a5db4a4bc036397790d/.ksh/rc/keyboard.ksh

@tungstengmd
Copy link
Author

i meant to set keybinds in a not-hacky way

What "hacky" way is there? There's the method from the Bolsky, written by dgk (and shipped with the shell). And there's the RedHat way, with a big case statement. Both seem pretty straightforward.

https://github.com/posguy99/dotfiles/blob/c7e17150b160e2b7e91d8a5db4a4bc036397790d/.ksh/rc/keyboard.ksh

it just seems awkward to use personally

@nickpapadonis
Copy link

As for zsh's preexec function, ksh's DEBUG trap currently provides very similar functionality, so I don't know about that one.

Does preexec get invoked for all commands in subshells or just the interactive command in top level shell? That may present some difference in functionality with DEBUG trap.

@nickpapadonis
Copy link

bash's PS0 variable might not be a bad thing to add, and it should be fairly trivial to implement.

You can achieve this by aliasing 'cd' to a command that sets the prompt I think.

@tungstengmd
Copy link
Author

bash's PS0 variable might not be a bad thing to add, and it should be fairly trivial to implement.

You can achieve this by aliasing 'cd' to a command that sets the prompt I think.

aliasing a command like cd to a prompt-setting command before changing dir is what i intend to avoid. that's the main reason my prompt is so convoluted [also bc i want a full-featured prompt fully in ksh [lack of starship for ksh]].

@posguy99
Copy link

posguy99 commented Apr 8, 2025

aliasing a command like cd to a prompt-setting command before changing dir is what i intend to avoid. that's the main reason my prompt is so convoluted [also bc i want a full-featured prompt fully in ksh [lack of starship for ksh]].

That doesn't need to be convoluted either. You can even support most of bash prompt escapes with a discipline function.

I didn't write this, credit is in the file and @McDutchie has made a few updates to it.

https://github.com/posguy99/dotfiles/blob/c7e17150b160e2b7e91d8a5db4a4bc036397790d/.ksh/rc/prompt.ksh

@tungstengmd
Copy link
Author

That doesn't need to be convoluted either. You can even support most of bash prompt escapes with a discipline function.
l
https://github.com/posguy99/dotfiles/blob/c7e17150b160e2b7e91d8a5db4a4bc036397790d/.ksh/rc/prompt.ksh

mm, my prompt also does have things like git status and stuff that'd probably be a lil hard to just Turn Into A Bash-Friendly Short Prompt

@posguy99
Copy link

posguy99 commented Apr 9, 2025

mm, my prompt also does have things like git status and stuff that'd probably be a lil hard to just Turn Into A Bash-Friendly Short Prompt

So does mine. That's why I posted the link to it. I think the point I'm trying to make is that you don't necessarily need to add anything to be able to do it.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.1 Issue relevant to dev branch (v1.1.*) enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants