lib7 Yeah, those 2 features of mc
rely on the running shell a) being able to execute commands found in PS1
(like, PS1='$(hostname):$(pwd)$ '
) or b) have a $PROMPT_COMMAND
like in bash
. Not all shells support these so the mc
devs. disable the subshell functionality when they detect an unknown shell.
Subshell functionality works if your shell is bash
ordash
, but, NetBSD's /bin/sh
doesn't unless mc
enables set -o promptcmds
--which it doesn't.
Anyway, to get both features working with /bin/sh
and /bin/ksh
, just edit /usr/pkg/libexec/mc/mc-wrapper.sh
(or copy the file locally) and change:
/usr/pkg/bin/mc -P "$MC_PWD_FILE" "$@"
to
SHELL=/usr/pkg/bin/bash /usr/pkg/bin/mc -P "$MC_PWD_FILE" "$@"
if you have bash
installed. Then, setup the standard alias to use it:
alias mc='. /usr/pkg/libexec/mc/mc-wrapper.sh'
If you feel brave, you can also try this patch:
diff -urN mc-4.8.28.orig/lib/shell.c mc-4.8.28/lib/shell.c
--- mc-4.8.28.orig/lib/shell.c 2022-03-20 10:02:46.000000000 +0000
+++ mc-4.8.28/lib/shell.c 2022-12-16 13:03:50.701126585 +0000
@@ -175,6 +175,18 @@
mc_shell->type = SHELL_DASH;
mc_shell->name = "dash";
}
+ else if (strstr (mc_shell->path, "/ksh") != NULL
+ || strstr (mc_shell->real_path, "/ksh") != NULL)
+ {
+ mc_shell->type = SHELL_KSH;
+ mc_shell->name = "ksh";
+ }
+ else if (strstr (mc_shell->path, "/ksh93") != NULL
+ || strstr (mc_shell->real_path, "/ksh93") != NULL)
+ {
+ mc_shell->type = SHELL_KSH;
+ mc_shell->name = "ksh";
+ }
else if (strstr (mc_shell->real_path, "/busybox") != NULL)
{
/* If shell is symlinked to busybox, assume it is an ash, even though theoretically
diff -urN mc-4.8.28.orig/lib/shell.h mc-4.8.28/lib/shell.h
--- mc-4.8.28.orig/lib/shell.h 2022-03-20 10:02:46.000000000 +0000
+++ mc-4.8.28/lib/shell.h 2022-12-16 13:10:51.281193118 +0000
@@ -16,6 +16,7 @@
SHELL_BASH,
SHELL_ASH_BUSYBOX, /* BusyBox default shell (ash) */
SHELL_DASH, /* Debian variant of ash */
+ SHELL_KSH, /* KornShell '88 & 93 */
SHELL_TCSH,
SHELL_ZSH,
SHELL_FISH
diff -urN mc-4.8.28.orig/src/subshell/common.c mc-4.8.28/src/subshell/common.c
--- mc-4.8.28.orig/src/subshell/common.c 2022-03-20 10:02:47.000000000 +0000
+++ mc-4.8.28/src/subshell/common.c 2022-12-16 12:56:13.084222139 +0000
@@ -344,6 +344,8 @@
break;
case SHELL_ASH_BUSYBOX:
+ case SHELL_SH:
+ case SHELL_KSH:
case SHELL_DASH:
/* Do we have a custom init file ~/.local/share/mc/ashrc? */
init_file = mc_config_get_full_path (MC_ASHRC_FILE);
@@ -426,6 +428,8 @@
break;
case SHELL_ASH_BUSYBOX:
+ case SHELL_SH:
+ case SHELL_KSH:
case SHELL_DASH:
case SHELL_TCSH:
case SHELL_FISH:
@@ -581,7 +585,7 @@
bytes =
read (command_buffer_pipe[READ], subshell_command_buffer, sizeof (subshell_command_buffer));
- if (bytes == 0 || bytes == sizeof (subshell_command_buffer))
+ if (bytes <= 0 || bytes == sizeof (subshell_command_buffer))
return FALSE;
command_buffer_char_length = bytes - 1;
@@ -613,7 +617,7 @@
bytes =
read (command_buffer_pipe[READ], subshell_cursor_buffer, sizeof (subshell_cursor_buffer));
- if (bytes == 0)
+ if (bytes <= 0)
return FALSE;
subshell_cursor_buffer[bytes - 1] = '\0';
@@ -727,6 +731,9 @@
if (mc_global.mc_run_mode != MC_RUN_FULL)
return;
+ if (subshell_prompt_temp_buffer == NULL)
+ return;
+
if (subshell_prompt_temp_buffer->len != 0)
g_string_assign (subshell_prompt, subshell_prompt_temp_buffer->str);
@@ -1113,6 +1120,8 @@
* "PRECMD=precmd; "
* "PS1='$(eval $PRECMD)\\u@\\h:\\w\\$ '\n",
*/
+ case SHELL_SH:
+ case SHELL_KSH:
case SHELL_DASH:
/* Debian ash needs a precmd emulation via PS1, similar to BusyBox ash,
* but does not support escape sequences for user, host and cwd in prompt.
@@ -1134,6 +1143,7 @@
* "PS1='$($PRECMD)$ '\n",
*/
g_snprintf (precmd, buff_size,
+ "(set -o promptcmds 2>/dev/null) && set -o promptcmds; "
"precmd() { "
"if [ ! \"${PWD##$HOME}\" ]; then "
"MC_PWD=\"~\"; "
It makes these things happen out-of-the-box (and also fixes a segfault which exists in mc
when you subshell out and back onto mc
the first time: try Ctrl-O Ctrl-O
after you run mc
).
I'd planned to send it upstream, but, those guys released a new version right about then, and I just never got around to making a new patch.