diff options
Diffstat (limited to '')
-rw-r--r-- | contrib/README.vimsyntax | 35 | ||||
-rw-r--r-- | contrib/bash_completion.sh | 256 | ||||
-rwxr-xr-x | contrib/git-hook-pre-commit | 14 | ||||
-rw-r--r-- | contrib/pcmk-ftdetect.vim | 2 | ||||
-rw-r--r-- | contrib/pcmk.vim | 114 | ||||
-rw-r--r-- | contrib/pygments_crmsh_lexers/__init__.py | 3 | ||||
-rw-r--r-- | contrib/pygments_crmsh_lexers/ansiclr.py | 50 | ||||
-rw-r--r-- | contrib/pygments_crmsh_lexers/crmsh.py | 88 | ||||
-rw-r--r-- | contrib/setup.py | 33 |
9 files changed, 595 insertions, 0 deletions
diff --git a/contrib/README.vimsyntax b/contrib/README.vimsyntax new file mode 100644 index 0000000..3bf5a7a --- /dev/null +++ b/contrib/README.vimsyntax @@ -0,0 +1,35 @@ +There were two VIM syntax files contributed: + +pacemaker-crm.vim +pcmk.vim + +The first one got removed because it didn't work with newer CRM +shell syntax anymore; most of the text was highlighted as "Error". + +Neither matches colours used in crm configure show and both need +to be improved. Still, you may want to edit a more colorful +configuration. To have that in "crm configure edit" do the +following: + + 1. Copy pcmk.vim to ~/.vim/syntax/pcmk.vim. + + 2. Make sure the following is added to your VIM rc file + (~/.vimrc or ~/.exrc): + + syntax on + set modeline + set modelines=5 + + 3. Copy the pcmk-ftdetect.vim to ~/.vim/ftdetect/ to + make files being identified automatically. + + +If you're editing a file directly, just type: + + :setf pcmk + +Many thanks to the contributors: + +Trevor Hemsley <themsley@voiceflex.com> +Dan Frincu <df.cluster@gmail.com> +Lars Ellenberg <lars@linbit.com> diff --git a/contrib/bash_completion.sh b/contrib/bash_completion.sh new file mode 100644 index 0000000..f497942 --- /dev/null +++ b/contrib/bash_completion.sh @@ -0,0 +1,256 @@ +#-*- mode: shell-script;-*- +# +# bash completion support for crmsh. +# +# Copyright (C) 2013 Kristoffer Gronlund <kgronlund@suse.com> +# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). +# Distributed under the GNU General Public License, version 2.0. +# +# To use these routines: +# +# 1) Copy this file to somewhere (e.g. ~/.crm-completion.sh). +# 2) Add the following line to your .bashrc/.zshrc: +# source ~/.crm-completion.sh + +shopt -s extglob + +# The following function is based on code from: +# +# bash_completion - programmable completion functions for bash 3.2+ +# +# Copyright © 2006-2008, Ian Macdonald <ian@caliban.org> +# © 2009-2010, Bash Completion Maintainers +# <bash-completion-devel@lists.alioth.debian.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The latest version of this software can be obtained here: +# +# http://bash-completion.alioth.debian.org/ +# +# RELEASE: 2.x + +# This function can be used to access a tokenized list of words +# on the command line: +# +# __git_reassemble_comp_words_by_ref '=:' +# if test "${words_[cword_-1]}" = -w +# then +# ... +# fi +# +# The argument should be a collection of characters from the list of +# word completion separators (COMP_WORDBREAKS) to treat as ordinary +# characters. +# +# This is roughly equivalent to going back in time and setting +# COMP_WORDBREAKS to exclude those characters. The intent is to +# make option types like --date=<type> and <rev>:<path> easy to +# recognize by treating each shell word as a single token. +# +# It is best not to set COMP_WORDBREAKS directly because the value is +# shared with other completion scripts. By the time the completion +# function gets called, COMP_WORDS has already been populated so local +# changes to COMP_WORDBREAKS have no effect. +# +# Output: words_, cword_, cur_. + +__crm_reassemble_comp_words_by_ref() +{ + local exclude i j first + # Which word separators to exclude? + exclude="${1//[^$COMP_WORDBREAKS]}" + cword_=$COMP_CWORD + if [ -z "$exclude" ]; then + words_=("${COMP_WORDS[@]}") + return + fi + # List of word completion separators has shrunk; + # re-assemble words to complete. + for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do + # Append each nonempty word consisting of just + # word separator characters to the current word. + first=t + while + [ $i -gt 0 ] && + [ -n "${COMP_WORDS[$i]}" ] && + # word consists of excluded word separators + [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] + do + # Attach to the previous token, + # unless the previous token is the command name. + if [ $j -ge 2 ] && [ -n "$first" ]; then + ((j--)) + fi + first= + words_[$j]=${words_[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword_=$j + fi + if (($i < ${#COMP_WORDS[@]} - 1)); then + ((i++)) + else + # Done. + return + fi + done + words_[$j]=${words_[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword_=$j + fi + done +} + +if ! type _get_comp_words_by_ref >/dev/null 2>&1; then +_get_comp_words_by_ref () +{ + local exclude cur_ words_ cword_ + if [ "$1" = "-n" ]; then + exclude=$2 + shift 2 + fi + __crm_reassemble_comp_words_by_ref "$exclude" + cur_=${words_[cword_]} + while [ $# -gt 0 ]; do + case "$1" in + cur) + cur=$cur_ + ;; + prev) + prev=${words_[$cword_-1]} + ;; + words) + words=("${words_[@]}") + ;; + cword) + cword=$cword_ + ;; + esac + shift + done +} +fi + +__crmcompadd () +{ + local i=0 + for x in $1; do + if [[ "$x" == "$3"* ]]; then + if [[ "$x" =~ .*(=|:)$ ]];then + if [[ "$x" =~ ^id=$ ]];then + : + else + COMPREPLY[i++]="$2$x" + fi + else + COMPREPLY[i++]="$2$x$4" + fi + fi + done +} + +# Generates completion reply, appending a space to possible completion words, +# if necessary. +# It accepts 1 to 4 arguments: +# 1: List of possible completion words. +# 2: A prefix to be added to each possible completion word (optional). +# 3: Generate possible completion matches for this word (optional). +# 4: A suffix to be appended to each possible completion word (optional). +__crmcomp () +{ + local cur_="${3-$cur}" + + case "$cur_" in + --*=) + ;; + *) + local c i=0 IFS=$' \t\n' + for c in $1; do + c="$c${4-}" + if [[ $c == "$cur_"* ]]; then + case $c in + --*=*|*.) ;; + *) c="$c " ;; + esac + COMPREPLY[i++]="${2-}$c" + fi + done + ;; + esac +} + +# Generates completion reply from newline-separated possible completion words +# by appending a space to all of them. +# It accepts 1 to 4 arguments: +# 1: List of possible completion words, separated by a single newline. +# 2: A prefix to be added to each possible completion word (optional). +# 3: Generate possible completion matches for this word (optional). +# 4: A suffix to be appended to each possible completion word instead of +# the default space (optional). If specified but empty, nothing is +# appended. +__crmcomp_nl () +{ + local IFS=$'\n' + __crmcompadd "$1" "${2-}" "${3-$cur}" "${4- }" +} + +__crm_compgen () +{ + local cur_="$cur" cmd="${words[1]}" + local pfx="" + + case "$cur_" in + *:*) + case "$COMP_WORDBREAKS" in + *:*) : great ;; + *) pfx="${cur_%%:*}:" ;; + esac + cur_="${cur_##*:}" + ;; + esac + + __crmcomp_nl "$(2>/dev/null crm --compgen "${COMP_POINT}" "${COMP_LINE}")" "$pfx" "$cur_" +} + +_crm() { + local cur words cword prev + + _get_comp_words_by_ref -n =: cur words cword prev + + for ((i=1; $i<=$cword; i++)); do + if [[ ${words[i]} != -* ]]; then + if [[ ${words[i-1]} != @(-f|--file|-H|--history|-D|--display|-X|-c|--cib) ]]; then + arg="${words[i]}" + argi=$i + break + fi + fi + done + + case $prev in + -f|--file|-H|--history|-D|--display|-X|-c|--cib) + # use default completion + return + ;; + esac + + if [[ "$cur" == -* ]]; then + __crmcomp '-w -h -d -F -R -f --file -H --history -D --display -X -c --cib' + return 0 + fi + + __crm_compgen +} && +complete -o bashdefault -o default -o nospace -F _crm crm || complete -o default -o nospace -F _crm crm diff --git a/contrib/git-hook-pre-commit b/contrib/git-hook-pre-commit new file mode 100755 index 0000000..f4bd35a --- /dev/null +++ b/contrib/git-hook-pre-commit @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +root="$(git rev-parse --show-toplevel)" +[ -d "$root" ] || exit 1 + +./update-data-manifest.sh +git add ./data-manifest diff --git a/contrib/pcmk-ftdetect.vim b/contrib/pcmk-ftdetect.vim new file mode 100644 index 0000000..e8e5387 --- /dev/null +++ b/contrib/pcmk-ftdetect.vim @@ -0,0 +1,2 @@ +" test for match at first character +au BufNewFile,BufRead * if match(getline(1), 'node ')==0 | set ft=pcmk | endif diff --git a/contrib/pcmk.vim b/contrib/pcmk.vim new file mode 100644 index 0000000..19a93b6 --- /dev/null +++ b/contrib/pcmk.vim @@ -0,0 +1,114 @@ +" Vim syntax file +" Author: Trevor Hemsley <themsley@voiceflex.com> +" Author: Dan Frincu <df.cluster@gmail.com> +" Language: pcmk +" Filenames: *.pcmk + +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +set modeline + +" setlocal iskeyword+=- + +" Errors +syn match pcmkParErr ")" +syn match pcmkBrackErr "]" +syn match pcmkBraceErr "}" + +" Enclosing delimiters +syn region pcmkEncl transparent matchgroup=pcmkParEncl start="(" matchgroup=pcmkParEncl end=")" contains=ALLBUT,pcmkParErr +syn region pcmkEncl transparent matchgroup=pcmkBrackEncl start="\[" matchgroup=pcmkBrackEncl end="\]" contains=ALLBUT,pcmkBrackErr +syn region pcmkEncl transparent matchgroup=pcmkBraceEncl start="{" matchgroup=pcmkBraceEncl end="}" contains=ALLBUT,pcmkBraceErr + +" Comments +syn region pcmkComment start="//" end="$" contains=pcmkComment,pcmkTodo +syn region pcmkComment start="/\*" end="\*/" contains=pcmkComment,pcmkTodo +syn keyword pcmkTodo contained TODO FIXME XXX + +" Strings +syn region pcmkString start=+"+ skip=+\\\\\|\\"+ end=+"+ + +" General keywords +syn keyword pcmkKeyword node primitive property rsc_defaults op_defaults group clone nextgroup=pcmkName skipwhite +syn keyword pcmkKey2 location nextgroup=pcmkResource skipwhite +syn keyword pcmkKey3 colocation order nextgroup=pcmkName3 skipwhite +syn match pcmkResource /\<\f\+\>/ nextgroup=pcmkName2 skipwhite +syn match pcmkName /\<\f\+\>/ +syn match pcmkName2 /\<\f\+\>/ nextgroup=pcmkPrio skipwhite +syn match pcmkName3 /\<\f\+\>/ nextgroup=pcmkPrio skipwhite +syn match pcmkPrio /\<\w\+\>/ +syn match pcmkNumbers /[[:digit:]]\+\:/ +syn match pcmkInf /inf\:/ + +" Graph attributes +syn keyword pcmkType attributes params op meta +syn keyword pcmkTag monitor start stop migrate_from migrate_to notify demote promote Master Slave + +" Special chars +"syn match pcmkKeyChar "=" +syn match pcmkKeyChar ";" +syn match pcmkKeyChar "->" +syn match pcmkKeyChar "\$" +"syn match pcmkKeyChar "\\" +syn match pcmkKeyChar ":" +syn match pcmkKeyChar "-" +syn match pcmkKeyChar "+" + +" Identifier +syn match pcmkIdentifier /\<\w\+\>/ +syn match pcmkKeyword "^ms\s*" nextgroup=pcmkName skipwhite + +" Synchronization +syn sync minlines=50 +syn sync maxlines=500 + +" Define the default highlighting. +" For version 5.7 and earlier: only when not done already +" For version 5.8 and later: only when an item doesn't have highlighting yet +if version >= 508 || !exists("did_pcmk_syntax_inits") + if version < 508 + let did_pcmk_syntax_inits = 1 + command -nargs=+ HiLink hi link <args> + else + command -nargs=+ HiLink hi def link <args> + endif + + HiLink pcmkParErr Error + HiLink pcmkBraceErr Error + HiLink pcmkBrackErr Error + + HiLink pcmkComment Comment + HiLink pcmkTodo Todo + + HiLink pcmkParEncl Keyword + HiLink pcmkBrackEncl Keyword + HiLink pcmkBraceEncl Keyword + + HiLink pcmkKeyword Keyword + HiLink pcmkKey2 Keyword + HiLink pcmkKey3 Keyword + HiLink pcmkType Keyword + HiLink pcmkKeyChar Keyword + +" hi Normal ctermfg=yellow ctermbg=NONE cterm=NONE + HiLink pcmkString String + HiLink pcmkIdentifier Identifier + HiLink pcmkTag Tag + HiLink pcmkName Type + HiLink pcmkName2 Tag + HiLink pcmkName3 Type + HiLink pcmkResource Type + HiLink pcmkPrio Number + HiLink pcmkNumbers String + HiLink pcmkInf String + + delcommand HiLink +endif + +let b:current_syntax = "pcmk" diff --git a/contrib/pygments_crmsh_lexers/__init__.py b/contrib/pygments_crmsh_lexers/__init__.py new file mode 100644 index 0000000..938d6e8 --- /dev/null +++ b/contrib/pygments_crmsh_lexers/__init__.py @@ -0,0 +1,3 @@ +from __future__ import unicode_literals +from .ansiclr import ANSIColorsLexer +from .crmsh import CrmshLexer diff --git a/contrib/pygments_crmsh_lexers/ansiclr.py b/contrib/pygments_crmsh_lexers/ansiclr.py new file mode 100644 index 0000000..b30ee85 --- /dev/null +++ b/contrib/pygments_crmsh_lexers/ansiclr.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.console + ~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for misc console output. + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +from __future__ import unicode_literals + +from pygments.lexer import RegexLexer, bygroups +from pygments.token import Generic, Text + +__all__ = ['ANSIColorsLexer'] + +_ESC = "\x1b\[" +# this is normally to reset (reset attributes, set primary font) +# there could be however other reset sequences and in that case +# sgr0 needs to be updated +_SGR0 = "%s(?:0;10|10;0)m" % _ESC +# BLACK RED GREEN YELLOW +# BLUE MAGENTA CYAN WHITE +_ANSI_COLORS = (Generic.Emph, Generic.Error, Generic.Inserted, Generic.Keyword, + Generic.Keyword, Generic.Prompt, Generic.Traceback, Generic.Output) + + +def _ansi2rgb(lexer, match): + code = match.group(1) + text = match.group(2) + yield match.start(), _ANSI_COLORS[int(code)-30], text + + +class ANSIColorsLexer(RegexLexer): + """ + Interpret ANSI colors. + """ + name = 'ANSI Colors' + aliases = ['ansiclr'] + filenames = ["*.typescript"] + + tokens = { + 'root': [ + (r'%s(3[0-7]+)m(.*?)%s' % (_ESC, _SGR0), _ansi2rgb), + (r'[^\x1b]+', Text), + # drop the rest of the graphic codes + (r'(%s[0-9;]+m)()' % _ESC, bygroups(None, Text)), + ] + } diff --git a/contrib/pygments_crmsh_lexers/crmsh.py b/contrib/pygments_crmsh_lexers/crmsh.py new file mode 100644 index 0000000..d4f1b14 --- /dev/null +++ b/contrib/pygments_crmsh_lexers/crmsh.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.dsls + ~~~~~~~~~~~~~~~~~~~~ + + Lexers for various domain-specific languages. + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +from __future__ import unicode_literals + + +from pygments.lexer import RegexLexer, bygroups, words +from pygments.token import Comment, Operator, Keyword, Name, String, Number, Punctuation, Whitespace + +__all__ = ['CrmshLexer'] + + +class CrmshLexer(RegexLexer): + """ + Lexer for `crmsh <http://crmsh.github.io/>`_ configuration files + for Pacemaker clusters. + + .. versionadded:: 2.1 + """ + name = 'Crmsh' + aliases = ['crmsh', 'pcmk'] + filenames = ['*.crmsh', '*.pcmk'] + mimetypes = [] + + elem = words(( + 'node', 'primitive', 'group', 'clone', 'ms', 'location', + 'colocation', 'order', 'fencing_topology', 'rsc_ticket', + 'rsc_template', 'property', 'rsc_defaults', + 'op_defaults', 'acl_target', 'acl_group', 'user', 'role', + 'tag'), suffix=r'(?![\w#$-])') + sub = words(( + 'params', 'meta', 'operations', 'op', 'rule', + 'attributes', 'utilization'), suffix=r'(?![\w#$-])') + acl = words(('read', 'write', 'deny'), suffix=r'(?![\w#$-])') + bin_rel = words(('and', 'or'), suffix=r'(?![\w#$-])') + un_ops = words(('defined', 'not_defined'), suffix=r'(?![\w#$-])') + date_exp = words(('in_range', 'date', 'spec', 'in'), suffix=r'(?![\w#$-])') + acl_mod = (r'(?:tag|ref|reference|attribute|type|xpath)') + bin_ops = (r'(?:lt|gt|lte|gte|eq|ne)') + val_qual = (r'(?:string|version|number)') + rsc_role_action = (r'(?:Master|Started|Slave|Stopped|' + r'start|promote|demote|stop)') + + tokens = { + 'root': [ + (r'^#.*\n?', Comment), + # attr=value (nvpair) + (r'([\w#$-]+)(=)("(?:""|[^"])*"|\S+)', + bygroups(Name.Attribute, Punctuation, String)), + # need this construct, otherwise numeric node ids + # are matched as scores + # elem id: + (r'(node)(\s+)([\w#$-]+)(:)', + bygroups(Keyword, Whitespace, Name, Punctuation)), + # scores + (r'([+-]?([0-9]+|inf)):', Number), + # keywords (elements and other) + (elem, Keyword), + (sub, Keyword), + (acl, Keyword), + # binary operators + (r'(?:%s:)?(%s)(?![\w#$-])' % (val_qual, bin_ops), + Operator.Word), + # other operators + (bin_rel, Operator.Word), + (un_ops, Operator.Word), + (date_exp, Operator.Word), + # builtin attributes (e.g. #uname) + (r'#[a-z]+(?![\w#$-])', Name.Builtin), + # acl_mod:blah + (r'(%s)(:)("(?:""|[^"])*"|\S+)' % acl_mod, + bygroups(Keyword, Punctuation, Name)), + # rsc_id[:(role|action)] + # NB: this matches all other identifiers + (r'([\w#$-]+)(?:(:)(%s))?(?![\w#$-])' % rsc_role_action, + bygroups(Name, Punctuation, Operator.Word)), + # punctuation + (r'(\\(?=\n)|[[\](){}/:@])', Punctuation), + (r'\s+|\n', Whitespace), + ], + } diff --git a/contrib/setup.py b/contrib/setup.py new file mode 100644 index 0000000..30330b8 --- /dev/null +++ b/contrib/setup.py @@ -0,0 +1,33 @@ +#!/usr/bin/python + +from __future__ import unicode_literals +from setuptools import setup + +setup(name='pygments-crmsh-lexers', + version='0.0.5', + description='Pygments crmsh custom lexers.', + keywords='pygments crmsh lexer', + license='BSD', + + author='Kristoffer Gronlund', + author_email='kgronlund@suse.com', + + url='https://github.com/ClusterLabs/crmsh', + + packages=['pygments_crmsh_lexers'], + install_requires=['pygments>=2.0.2'], + + entry_points='''[pygments.lexers] + ANSIColorsLexer=pygments_crmsh_lexers:ANSIColorsLexer + CrmshLexer=pygments_crmsh_lexers:CrmshLexer''', + + classifiers=[ + 'Environment :: Plugins', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + 'Topic :: Software Development :: Libraries :: Python Modules', + ],) |