Thursday 13 February 2014

Cisco config text highlighting with Gedit

The following files can be copied into the language folder to enable text highlighting for Cisco configurations

$ sudo cp ios.lang /usr/share/gtksourceview-3.0/language-specs/



ios.lang

<?xml version="1.0" encoding="UTF-8"?>
<language id="cisco-ios" _name="Cisco IOS" version="2.0" _section="Cisco">
  <metadata>
    <property name="mimetypes">text/plain</property>
    <property name="globs">*.cfg</property>
    <property name="comment-start">!</property>
  </metadata>
  <styles>
    <style id="comment" _name="Comment" map-to="def:comment"/>
    <style id="identifier" _name="Interface" map-to="def:identifier"/>
    <style id="list" _name="Access List" map-to="def:preprocessor"/>
    <style id="number" _name="Number" map-to="def:preprocessor"/>
  </styles>
  <definitions>
    <context id="comment" style-ref="comment" end-at-line-end="true">
      <start>!</start>
    </context>
    <context id="description" style-ref="comment" end-at-line-end="true">
      <start>description</start>
    </context>

    <context id="hostname" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>hostname</start>
    </context>
    <context id="interface" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>interface</start>
    </context>
    <context id="policy-map" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>policy-map</start>
    </context>
    <context id="class-map" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>class-map</start>
    </context>
    <context id="controller" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>controller</start>
    </context>
    <context id="linevty" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>line vty</start>
    </context>
    <context id="linecon" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>line con</start>
    </context>
    <context id="lineaux" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>line aux</start>
    </context>

    <context id="lists" style-ref="list">
      <keyword>access-list</keyword>
      <keyword>ip route</keyword>
      <keyword>ip nat</keyword>
    </context>

    <context id="routers" style-ref="identifier">
      <keyword>router rip</keyword>
      <keyword>router eigrp</keyword>
      <keyword>router igrp</keyword>
      <keyword>router ospf</keyword>
      <keyword>router bgp</keyword>
    </context>

    <context id="number" style-ref="number">
      <match>(\b[0-9]+(\.[0-9]+)?|\.[0-9]+)([Ee][\+-]?[0-9]+)?\b</match>
    </context>
    <context id="cisco-ios">
      <include>
        <context ref="comment"/>
        <context ref="description"/>
        <context ref="hostname"/>
        <context ref="interface"/>
        <context ref="controller"/>
        <context ref="linevty"/>
        <context ref="linecon"/>
        <context ref="lineaux"/>
        <context ref="policy-map"/>
        <context ref="class-map"/>
        <context ref="lists"/>
        <context ref="routers"/>
        <context ref="number"/>
       </include>
    </context>
  </definitions>
</language>


asa.lang

<?xml version="1.0" encoding="UTF-8"?>
<language id="cisco-firewall" _name="Cisco PIX/ASA" version="2.0"
_section="Cisco">
  <metadata>
    <property name="mimetypes">text/plain</property>
    <property name="globs">*.txt;</property>
    <property name="comment-start">!</property>
  </metadata>
  <styles>
    <style id="comment" _name="Comment" map-to="def:comment"/>
    <style id="identifier" _name="Interface" map-to="def:keyword"/>
    <style id="access-list" _name="Access List" map-to="def:preprocessor"/>
    <style id="static" _name="Static" map-to="def:string"/>
    <style id="nat" _name="NAT" map-to="def:type"/>
    <style id="route" _name="Route" map-to="def:preprocessor"/>
    <style id="number" _name="Number" map-to="def:comment"/>
  </styles>
  <definitions>
    <context id="comment" style-ref="comment" end-at-line-end="true">
      <start>!</start>
    </context>
    <context id="description" style-ref="comment" end-at-line-end="true">
      <start>description</start>
    </context>

    <context id="hostname" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>hostname</start>
    </context>
    <context id="ip-address" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>ip address</start>
    </context>
    <context id="interface" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>interface</start>
    </context>
    <context id="policy-map" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>policy-map</start>
    </context>
    <context id="class-map" end-at-line-end="true" extend-parent="false"
style-ref="identifier">
      <start>class-map</start>
    </context>

    <context id="access-list" end-at-line-end="true" extend-parent="false"
style-ref="access-list">
      <start>access-list</start>
    </context>

    <context id="access-group" end-at-line-end="true" extend-parent="false"
style-ref="access-list">
      <start>access-group</start>
    </context>

    <context id="static" end-at-line-end="true" extend-parent="false"
style-ref="static">
      <start>static</start>
    </context>

    <context id="nat" end-at-line-end="true" extend-parent="false"
style-ref="nat">
      <start>nat</start>
    </context>

    <context id="route" end-at-line-end="true" extend-parent="false"
style-ref="route">
      <start>route</start>
    </context>

    <context id="number" style-ref="number">
      <match>(\b[0-9]+(\.[0-9]+)?|\.[0-9]+)([Ee][\+-]?[0-9]+)?\b</match>
    </context>
    <context id="cisco-firewall">
      <include>
        <context ref="comment"/>
        <context ref="description"/>
        <context ref="ip-address"/>
        <context ref="hostname"/>
        <context ref="interface"/>
        <context ref="policy-map"/>
        <context ref="class-map"/>
        <context ref="access-list"/>
        <context ref="access-group"/>
        <context ref="static"/>
        <context ref="nat"/>
        <context ref="route"/>
        <context ref="number"/>
       </include>
    </context>
  </definitions>
</language>

1 comment:

  1. This blog resolved all my queries I had in my mind. Really helpful and supportive subject matter written in all the points. Hard to find such kind of blogs as descriptive and accountable to your doubts.Cisco RV130

    ReplyDelete