module Rouge module Lexers class Shell < RegexLexer desc "Various shell languages, including sh and bash" tag 'shell' aliases 'bash', 'zsh', 'ksh', 'sh' filenames '*.sh', '*.bash', '*.zsh', '*.ksh', '.bashrc', '.zshrc', '.kshrc', '.profile' mimetypes 'application/x-sh', 'application/x-shellscript' def self.analyze_text(text) text.shebang?(/(ba|z|k)?sh/) ? 1 : 0 end KEYWORDS = %w( if fi else while do done for then return function select continue until esac elif in ).join('|') BUILTINS = %w( alias bg bind break builtin caller cd command compgen complete declare dirs disown echo enable eval exec exit export false fc fg getopts hash help history jobs kill let local logout popd printf pushd pwd read readonly set shift shopt source suspend test time times trap true type typeset ulimit umask unalias unset wait ).join('|') state :basic do rule /#.*$/, Comment rule /\b(#{KEYWORDS})\s*\b/, Keyword rule /\bcase\b/, Keyword, :case rule /\b(#{BUILTINS})\s*\b(?!\.)/, Name::Builtin rule /^\S*[\$%>#] +/, Generic::Prompt rule /(\b\w+)(=)/ do |m| groups Name::Variable, Operator end rule /[\[\]{}()=]/, Operator rule /&&|\|\|/, Operator # rule /\|\|/, Operator rule /<<