From 3db0dd892fdd9263d1d494dd7ab8a13037c8b1e5 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Wed, 3 May 2017 08:10:56 +0000 Subject: [PATCH] script: split script-mode into shell specific modes - add specific modes for sh, bash, csh, ksh, zsh and tcsh --- script.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/script.c b/script.c index 66e1852..5798748 100644 --- a/script.c +++ b/script.c @@ -266,10 +266,16 @@ start_cmd: static int shell_script_mode_probe(ModeDef *mode, ModeProbeData *p) { + /* Match on file extension, shbang line and .bashrc .bash_history... */ if (match_extension(p->filename, mode->extensions) || match_shell_handler(cs8(p->buf), mode->shell_handlers) - || stristart(p->filename, ".bash", NULL) - || stristart(p->filename, ".profile", NULL)) { + || (*p->filename == '.' + && stristart(p->filename + 1, mode->extensions, NULL))) { + return 82; + } + + if (stristart(p->filename, ".profile", NULL)) { + /* XXX: Should check the user login shell */ return 80; } @@ -283,10 +289,55 @@ static int shell_script_mode_probe(ModeDef *mode, ModeProbeData *p) } /* XXX: should have shell specific variations */ -static ModeDef shell_script_mode = { - .name = "Shell-script", - .extensions = "sh|bash|csh|ksh|zsh", - .shell_handlers = "sh|bash|csh|ksh|zsh", +static ModeDef sh_mode = { + .name = "sh", + .extensions = "sh", + .shell_handlers = "sh", + .mode_probe = shell_script_mode_probe, + .colorize_func = shell_script_colorize_line, + .keywords = shell_script_keywords, +}; + +static ModeDef bash_mode = { + .name = "bash", + .extensions = "bash", + .shell_handlers = "bash", + .mode_probe = shell_script_mode_probe, + .colorize_func = shell_script_colorize_line, + .keywords = shell_script_keywords, +}; + +static ModeDef csh_mode = { + .name = "csh", + .extensions = "csh", + .shell_handlers = "csh", + .mode_probe = shell_script_mode_probe, + .colorize_func = shell_script_colorize_line, + .keywords = shell_script_keywords, +}; + +static ModeDef ksh_mode = { + .name = "ksh", + .extensions = "ksh", + .shell_handlers = "ksh", + .mode_probe = shell_script_mode_probe, + .colorize_func = shell_script_colorize_line, + .keywords = shell_script_keywords, +}; + +static ModeDef zsh_mode = { + .name = "zsh", + .extensions = "zsh", + .shell_handlers = "zsh", + .mode_probe = shell_script_mode_probe, + .colorize_func = shell_script_colorize_line, + .keywords = shell_script_keywords, +}; + +static ModeDef tcsh_mode = { + .name = "tcsh", + .extensions = "tcsh", + .shell_handlers = "tcsh", .mode_probe = shell_script_mode_probe, .colorize_func = shell_script_colorize_line, .keywords = shell_script_keywords, @@ -294,7 +345,12 @@ static ModeDef shell_script_mode = { static int shell_script_init(void) { - qe_register_mode(&shell_script_mode, MODEF_SYNTAX); + qe_register_mode(&sh_mode, MODEF_SYNTAX); + qe_register_mode(&bash_mode, MODEF_SYNTAX); + qe_register_mode(&csh_mode, MODEF_SYNTAX); + qe_register_mode(&ksh_mode, MODEF_SYNTAX); + qe_register_mode(&zsh_mode, MODEF_SYNTAX); + qe_register_mode(&tcsh_mode, MODEF_SYNTAX); return 0; }