# -*- coding: utf-8 -*- # module Rouge module Lexers class Shell < RegexLexer title "shell" desc "Various shell languages, including sh and bash" tag 'shell' aliases 'bash', 'zsh', 'ksh', 'sh' filenames '*.sh', '*.bash', '*.zsh', '*.ksh', '.bashrc', '.zshrc', '.kshrc', '.profile', 'PKGBUILD' mimetypes 'application/x-sh', 'application/x-shellscript' def self.detect?(text) return true if text.shebang?(/(ba|z|k)?sh/) 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 ls tar cat grep sudo ).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)/, Name::Builtin rule /(\b\w+)(=)/ do |m| groups Name::Variable, Operator end rule /[\[\]{}()!=>]/, Operator rule /&&|\|\|/, Operator # here-string rule /<<