Ticket #3748 (accepted enhancement)

Opened 8 years ago

Last modified 31 hours ago

mksh as a subshell

Reported by: gloomyquazar Owned by: zaytsev
Priority: minor Milestone: 4.8.33
Component: mc-core Version: master
Keywords: subshell mksh Cc:
Blocked By: Blocking:
Branch state: on review Votes for changeset:

Description

Hello.

On my desktop and notebook I use FreeBSD together with mksh, which I like for it's small size, robustness, security... Recently I got to know that MC supports only bash, (t)csh, zsh and something else as main shells, hence my mksh doesn't work as a subshell, I can't just switch with Ctrl+O and work there, so I had to postpone using MC for now. Is there a way to add mksh for supported shells? Without a subshell working in MC gets very unconvenient.

With regards,
Sergey P.

Attachments

mc-mksh-subshell.patch (2.8 KB) - added by gloomyquazar 8 years ago.
mc-mksh-subshell-v2.patch (2.8 KB) - added by gloomyquazar 8 years ago.

Change History

comment:1 follow-up: ↓ 2 Changed 8 years ago by gloomyquazar

It would be nice to also add support for general Bourne /bin/sh as a subshell.

comment:2 in reply to: ↑ 1 Changed 8 years ago by andrew_b

  • Blocked By 3692 added
  • Milestone changed from 4.8.19 to Future Releases

Replying to gloomyquazar:

It would be nice to also add support for general Bourne /bin/sh as a subshell.

#3658

comment:3 Changed 8 years ago by zaytsev

If mksh has an equivalent of precmd (which, I think, it does) and you can cook up a patch to support it that is not impossible.

comment:4 Changed 8 years ago by gloomyquazar

Maybe the function like this will do?

function precmd {

<put something here>

}

PS1="$(precmd) $PS1 "

comment:5 Changed 8 years ago by zaytsev

As I said, if you manage to provide a clean working patch, we might eventually get it in.

Changed 8 years ago by gloomyquazar

comment:6 Changed 8 years ago by gloomyquazar

Could you please check this patch? It works OK for me.

Changed 8 years ago by gloomyquazar

comment:7 Changed 7 years ago by woodsb02

Any progress on this?
The v2 patch looks simple enough.

Last edited 7 years ago by woodsb02 (previous) (diff)

comment:8 follow-up: ↓ 9 Changed 2 months ago by zaytsev

comment:9 in reply to: ↑ 8 Changed 2 months ago by d3m3t3r

Replying to zaytsev:

Somebody turned this in a PR:

https://github.com/MidnightCommander/mc/pull/209

Added support for ksh/oksh/mksh Korn shell variants.

comment:10 Changed 2 months ago by zaytsev

  • Milestone changed from Future Releases to 4.8.33

I assume you tested it and it works for you?

  • I'm surprised that the "precmd" part was so simple. Is that due to static prompt? Is supporting user prompt impossible / problematic?
  • I'm not sure that ksh supports HISTCONTROL... Does it really? If yes, good news.

comment:11 Changed 2 months ago by d3m3t3r

I need to fix it for mksh which is actually dumber than other pdksh/openbsd based variants. mksh doesn't support HISTCONTROL either \x placeholders in PS1 and recognizes not just ENV but $HOME/.mkshrc too.

Couldn't find any "precmd" like functionality in any variant so I suppose user prompt is not possible.

Since mksh seems to be quite different from other variants, would you recommend using distinct SHELL_KSH and SHELL_MKSH types? Or perhaps use single SHELL_KSH type but specific mc_shell->name?

comment:12 Changed 2 months ago by zaytsev

Since mksh seems to be quite different from other variants

I would add SHELL_MKSH if it's different enough, and SHELL_OKSH / SHELL_PDKSH (whichever official names make sense, didn't look into it) for clarity - you can use multiple enum values for the same case.

Couldn't find any "precmd" like functionality in any variant so I suppose user prompt is not possible.

It would be great to have this as a comment. Otherwise our children will wonder...

mksh doesn't support HISTCONTROL

But the others do, or everything is trashed with our cd commands?

comment:13 Changed 2 months ago by d3m3t3r

First, thanks much for the feedback. I've split mksh support under its own SHELL_MKSH type since its features differ so much it makes sense to handle it separately.

Some overview: There seems to be several implementations of ksh around but all but mksh (MirBSD ksh https://github.com/MirBSD/mksh) are based on pdksh (Public Domain ksh), in particular ports of OpenBSD ksh, e.g. https://github.com/dimkr/loksh and https://github.com/ibara/oksh. pdksh supports \x codes, variable and command substitution in PS1, HISTCONTROL (ignorespace & ignoredups) and ENV variable for interactive shell rc-file. mksh, on the other hand, doesn't support \x codes in PS1 either HISTCONTROL. It supports ENV variable for interactive shell rc-file but if it's not set the shell also tries ~/.mkshrc.

comment:14 Changed 2 months ago by d3m3t3r

  • Cc d3m3t3r@… added

comment:15 Changed 8 weeks ago by d3m3t3r

  • Cc d3m3t3r@… removed

comment:16 Changed 8 weeks ago by zaytsev

Sorry, I still don't have time to look into it deeper... but I wonder, can actually the plain POSIX sh be supported with the fallback? Maybe you have the answer since you looked deeper into it.

comment:17 Changed 7 weeks ago by d3m3t3r

but I wonder, can actually the plain POSIX sh be supported with the fallback? Maybe you have the answer since you looked deeper into it.

I don't think the precmd fallback emulation in mc supports the plain POSIX shell because it relies on the command substitution in PS1 which according to the specification (https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_05_03) is unspecified.

comment:18 Changed 7 weeks ago by d3m3t3r

There's summary of the changes in my PR:

  1. Add support for mksh - uses fallback precmd emulation.
  2. Add support for pdksh-based ksh (e.g. OpenBSD's ksh) - supports user prompt.
  3. Enhance fallback precmd emulation to support user prompt (affect ash/dash/mksh).

I tested on Alpine Linux with busybox, dash, mksh, oksh (OpenBSD's ksh port) and loksh (another OpenBSD's ksh port) packages.

comment:19 Changed 2 days ago by zaytsev

  • Status changed from new to accepted
  • Owner set to zaytsev

comment:20 Changed 2 days ago by zaytsev

  • Branch state changed from no branch to on review

Branch: 3748_ksh_support
Initial changeset: b64512b750351d83691c02e5bf118d3e00dae85f

I have added some fixups, but it me it looks good. Thank you for your high quality contribution!

comment:21 Changed 2 days ago by zaytsev

  • Blocked By 3692 removed

comment:22 Changed 45 hours ago by ossi

i haven't looked very closely, but it doesn't seem right to me that a fallback to .profile is forced.

line 385 has a copy&pasto.
line 1199 has incorrect indentation.

comment:23 Changed 45 hours ago by zaytsev

i haven't looked very closely, but it doesn't seem right to me that a fallback to .profile is forced.

Why? It seems to be the default for ksh according to the man pages.

line 385 has a copy&pasto.
line 1199 has incorrect indentation.

Both are fixed in subsequent commits. I didn't want to squash them because of the inline explanations.

comment:24 Changed 42 hours ago by ossi

huh, i didn't notice that this is a patch _series_. 🤦🏻‍♂️
(did i already mention this year that i hate trac as a review platform?)

well, if it's the default, then it needs no override. but i suppose it needs some "convincing", because it's not a login shell.
i'm a bit wary about messing with the startup files in general, because i know what an utter mess it is, how some shells aren't even consistent with themselves (bash has build-time switches), and how everybody tries to work around it their own way. (you will find several "treatises" from me on that matter if you google hard enough.) and sourcing .profile in lieu of an rc file doesn't make things better. ah, well.

the merge's diff shows that the indentation mistake persists.

which inline explanations?
i'm an atomicity pedant, so i'd split the fixup patches and squash the hunks where appropriate. shared authorship can be documented in footers.
in the same vein, a commit near the end of the series contains some unrelated comment whitespace changes that i'd split off (or just discard).
but this is a matter of project policy, so whatever.

comment:25 Changed 31 hours ago by zaytsev

Just tested on OpenIndiana with ksh and ksh93 - the new shell integration is working very nicely and is comfortable to use. The history is clobbered with commands though, because they don't seem to support HISTCONTROL.

I have added a commit to support ksh93 binary, I will squash commits before merge.

Note: See TracTickets for help on using tickets.