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

Ticket #3748: add support for ksh in subshell #209

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/man/mc.1.in
zyv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2406,6 +2406,10 @@ and special keyboard maps in ~/.local/share/mc/inputrc (fallback ~/.inputrc).
.B ash/dash
users (BusyBox or Debian) may specify startup commands in ~/.local/share/mc/ashrc (fallback ~/.profile).
.PP
.B ksh
users (ksh, oksh or mksh) may specify startup commands in ~/.local/share/mc/kshrc
(fallback $ENV or ~/.profile).
.PP
.B zsh
users may specify startup commands in ~/.local/share/mc/.zshrc (fallback ~/.zshrc).
.PP
Expand Down
1 change: 1 addition & 0 deletions lib/fileloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define MC_BASHRC_FILE "bashrc"
#define MC_ZSHRC_FILE ".zshrc"
#define MC_ASHRC_FILE "ashrc"
#define MC_KSHRC_FILE "kshrc"
#define MC_INPUTRC_FILE "inputrc"
#define MC_CONFIG_FILE "ini"
#define MC_EXT_FILE "mc.ext.ini"
Expand Down
1 change: 1 addition & 0 deletions lib/mcconfig/paths.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static const struct
{ &mc_data_str, MC_SKINS_DIR },
{ &mc_data_str, VFS_SHELL_PREFIX },
{ &mc_data_str, MC_ASHRC_FILE },
{ &mc_data_str, MC_KSHRC_FILE },
{ &mc_data_str, MC_BASHRC_FILE },
{ &mc_data_str, MC_INPUTRC_FILE },
{ &mc_data_str, MC_ZSHRC_FILE },
Expand Down
21 changes: 21 additions & 0 deletions lib/shell.c
zyv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ mc_shell_get_installed_in_system (void)
mc_shell->path = g_strdup ("/bin/tcsh");
else if (access ("/bin/csh", X_OK) == 0)
mc_shell->path = g_strdup ("/bin/csh");
else if (access ("/bin/ksh", X_OK) == 0)
mc_shell->path = g_strdup ("/bin/ksh");
/* No fish as fallback because it is so much different from other shells and
* in a way exotic (even though user-friendly by name) that we should not
* present it as a subshell without the user's explicit intention. We rather
Expand Down Expand Up @@ -189,6 +191,17 @@ mc_shell_recognize_real_path (mc_shell_t *mc_shell)
mc_shell->type = SHELL_ASH_BUSYBOX;
mc_shell->name = mc_shell->path;
}
else if (strstr (mc_shell->path, "/ksh") != NULL
|| strstr (mc_shell->real_path, "/ksh") != NULL
|| strstr (mc_shell->path, "/oksh") != NULL
|| strstr (mc_shell->real_path, "/oksh") != NULL
|| strstr (mc_shell->path, "/mksh") != NULL
|| strstr (mc_shell->real_path, "/mksh") != NULL)
{
/* Korn shell variants */
mc_shell->type = SHELL_KSH;
mc_shell->name = "ksh";
}
else
mc_shell->type = SHELL_NONE;
}
Expand All @@ -214,6 +227,14 @@ mc_shell_recognize_path (mc_shell_t *mc_shell)
mc_shell->type = SHELL_ASH_BUSYBOX;
mc_shell->name = "ash";
}
else if (strstr (mc_shell->path, "/ksh") != NULL
|| strstr (mc_shell->path, "/oksh") != NULL
|| strstr (mc_shell->path, "/mksh") != NULL
|| getenv ("KSH_VERSION") != NULL)
{
mc_shell->type = SHELL_KSH;
mc_shell->name = "ksh";
}
else
mc_shell->type = SHELL_NONE;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ typedef enum
SHELL_DASH, /* Debian variant of ash */
SHELL_TCSH,
SHELL_ZSH,
SHELL_FISH
SHELL_FISH,
SHELL_KSH
} shell_type_t;

/*** structures declarations (and typedefs of structures)*****************************************/
Expand Down
34 changes: 34 additions & 0 deletions src/subshell/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,33 @@ init_subshell_child (const char *pty_name)

break;

case SHELL_KSH:
/* Do we have a custom init file ~/.local/share/mc/kshrc? */
init_file = mc_config_get_full_path (MC_KSHRC_FILE);

/* Otherwise use ~/.profile if $ENV is not already set */
if (!exist_file (init_file))
{
g_free (init_file);
init_file = NULL;

if (!g_getenv ("ENV"))
{
init_file = g_strdup (".profile");
}
}

/* Put init file to ENV variable used by ash */
if (init_file)
{
g_setenv ("ENV", init_file, TRUE);
}

/* Make MC's special commands not show up in history */
putenv ((char *) "HISTCONTROL=ignorespace");

break;

case SHELL_ZSH:
/* ZDOTDIR environment variable is the only way to point zsh
* to an other rc file than the default. */
Expand Down Expand Up @@ -439,6 +466,7 @@ init_subshell_child (const char *pty_name)
case SHELL_ASH_BUSYBOX:
case SHELL_DASH:
case SHELL_TCSH:
case SHELL_KSH:
execl (mc_global.shell->path, mc_global.shell->path, (char *) NULL);
break;

Expand Down Expand Up @@ -1164,6 +1192,12 @@ init_subshell_precmd (char *precmd, size_t buff_size)
"}; " "PRECMD=precmd; " "PS1='$($PRECMD)$ '\n", subshell_pipe[WRITE]);
break;

case SHELL_KSH:
g_snprintf (precmd, buff_size,
" PS1='$(pwd>&%d; kill -STOP $$)\\u@\\h:\\w\\$ '\n",
subshell_pipe[WRITE]);
break;

case SHELL_ZSH:
g_snprintf (precmd, buff_size,
" mc_print_command_buffer () { printf \"%%s\\\\n\" \"$BUFFER\" >&%d; }\n"
Expand Down