diff --git a/lib/rouge/lexers/shell.rb b/lib/rouge/lexers/shell.rb index 8981698c50..3704066ae0 100644 --- a/lib/rouge/lexers/shell.rb +++ b/lib/rouge/lexers/shell.rb @@ -9,8 +9,11 @@ class Shell < RegexLexer tag 'shell' aliases 'bash', 'zsh', 'ksh', 'sh' - filenames '*.sh', '*.bash', '*.zsh', '*.ksh', '.bashrc', '.zshrc', - '.kshrc', '.profile', 'APKBUILD', 'PKGBUILD', '*.ebuild', + filenames '*.sh', '*.bash', '*.zsh', '*.ksh', '.bashrc', + '.kshrc', '.profile', + '.zshenv', '.zprofile', '.zshrc', '.zlogin', '.zlogout', + 'zshenv', 'zprofile', 'zshrc', 'zlogin', 'zlogout', + 'APKBUILD', 'PKGBUILD', '*.ebuild', '*.eclass', '*.exheres-0', '*.exlib' mimetypes 'application/x-sh', 'application/x-shellscript', 'text/x-sh', @@ -18,6 +21,7 @@ class Shell < RegexLexer def self.detect?(text) return true if text.shebang?(/(ba|z|k)?sh/) + return true if text.start_with?('#compdef', '#autoload') end KEYWORDS = %w( diff --git a/spec/lexers/shell_spec.rb b/spec/lexers/shell_spec.rb index 7383add49a..e0df431236 100644 --- a/spec/lexers/shell_spec.rb +++ b/spec/lexers/shell_spec.rb @@ -47,6 +47,16 @@ assert_guess :filename => 'foo.eclass' assert_guess :filename => 'foo.exheres-0' assert_guess :filename => 'foo.exlib' + assert_guess :filename => '.zshenv' + assert_guess :filename => '.zprofile' + assert_guess :filename => '.zshrc' + assert_guess :filename => '.zlogin' + assert_guess :filename => '.zlogout' + assert_guess :filename => 'zshenv' + assert_guess :filename => 'zprofile' + assert_guess :filename => 'zshrc' + assert_guess :filename => 'zlogin' + assert_guess :filename => 'zlogout' deny_guess :filename => 'foo' end @@ -62,6 +72,9 @@ assert_guess :source => ' #! /bin/bash' assert_guess :source => '#!/usr/bin/env bash' assert_guess :source => '#!/usr/bin/env bash -i' + assert_guess :source => '#compdef myfunction1 mufunction2' + assert_guess :source => '#autoload' + assert_guess :source => '#autoload +X' deny_guess :source => '#!/bin/smash' # not sure why you would do this, but hey, whatevs deny_guess :source => '#!/bin/bash/python'