# -*- coding: utf-8 -*- # # frozen_string_literal: true 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', 'APKBUILD', 'PKGBUILD', '*.ebuild', '*.eclass', '*.exheres-0', '*.exlib' mimetypes 'application/x-sh', 'application/x-shellscript', 'text/x-sh', 'text/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 enable eval exec exit export false fc fg getopts hash help history jobs let local logout mapfile popd pushd pwd read readonly set shift shopt source suspend test time times trap true type typeset ulimit umask unalias unset wait cat tac nl od base32 base64 fmt pr fold head tail split csplit wc sum cksum b2sum md5sum sha1sum sha224sum sha256sum sha384sum sha512sum sort shuf uniq comm ptx tsort cut paste join tr expand unexpand ls dir vdir dircolors cp dd install mv rm shred link ln mkdir mkfifo mknod readlink rmdir unlink chown chgrp chmod touch df du stat sync truncate echo printf yes expr tee basename dirname pathchk mktemp realpath pwd stty printenv tty id logname whoami groups users who date arch nproc uname hostname hostid uptime chcon runcon chroot env nice nohup stdbuf timeout kill sleep factor numfmt seq tar grep sudo awk sed gzip gunzip ).join('|') state :basic do rule %r/#.*$/, Comment rule %r/\b(#{KEYWORDS})\s*\b/, Keyword rule %r/\bcase\b/, Keyword, :case rule %r/\b(#{BUILTINS})\s*\b(?!(\.|-))/, Name::Builtin rule %r/[.](?=\s)/, Name::Builtin rule %r/(\b\w+)(=)/ do groups Name::Variable, Operator end rule %r/[\[\]{}()!=>]/, Operator rule %r/&&|\|\|/, Operator # here-string rule %r/<<