Sublime Text 2でCisco機器のコンフィグをハイライト

ちまたで話題の"恋に落ちるエディタ"Sublime Textで、
Ciscoルータやスイッチなど、ネットワーク機器のコンフィグをハイライトできるよう設定した。

結果の画面キャプチャがこちら。

以下手順。
1)Sublime Text 2をインストール
公式サイトSublime Text - A sophisticated text editor for code, markup and proseからDL、インストール

2)Sublime Text 2に「Package Control」をインストール

View -> Show Consoleを選択し、以下のテキストを入力してSublime Text2を再起動

import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())

参考:http://mnemoniqs.com/web/sublimetext2/

3)Cisco機器configのハイライト設定をDL

自作しても良いのだが、Sublime TextはTextMateのbundleを利用できるとのことなので、
TextMate用に作成されたハイライトのzipファイルを以下からDL。
the monkey puzzle: cisco config syntax highlighting for textmate

4)Cisco機器用のハイライト設定をPackagesフォルダ下に格納

Preferences -> Browse packages で表示されたPackagesフォルダの配下に
"Cisco IOS"の名前で新規フォルダを作成し、3)でDLしたzipファイルの中身
Cisco IOS.tmLanguage」をコピー。
スニペットを使いたい場合は拡張子を「.sublime-snippet」に変更。

ちなみにPackagesフォルダは以下。「Package Control」をインストールしないと出現しない。
~/Library/Application Support/Sublime Text 2/Packages

参考:http://succi.jp/blog/?p=257

5)確認
ciscoコンフィグの設定ファイルを開き、
View -> Syntax -> Cisco IOSしてみると、インターフェースの名前やip address等がハイライトされる。

6)特定の拡張子のデフォルトsyntaxを設定
ちなみにcfgファイルやlogファイルはデフォルトでCisco機器用のハイライトを利用したい場合は、
その拡張子のファイルを開いて
View -> Syntax -> Open all with current extension as … ->Cisco IOS
を選択。

      • -

3)でDLした「Cisco IOS.tmLanguage」の中身を一応貼っておく。



fileTypes

-confg

foldingStartMarker
^interface|^router|^ip access-list extended
foldingStopMarker
^!
name
Cisco IOS
patterns


match
(\bshutdown\b|^boot-(start|end)-marker)
name
constant.language.cisco


match
*1*2\b
name
keyword.other.line.cisco


match
\b(domain-name|default-router|dns-server|host|client-(name|identifier)|option)\b
name
keyword.other.dhcp.cisco


match
\b(device-security-mode|mac-address|type|button|video|username)\b
name
keyword.other.ephone.cisco


match
\b(number|name|call-forward|hold-alert)\b
name
keyword.other.ephonedn.cisco


match
\b(load|max-ephones|max-dn|ip|auto|calling-number|timeouts|time-zone|time-format|date-format|dialplan-pattern|max-conferences|moh|web|(dn|time)-webedit|transfer-(system|pattern)|create)\b
name
keyword.other.telephony.cisco


match
\b(translation-profile|answer-address|destination-pattern|progress_ind|incoming|direct-inward-dial|port|max-conn|information-type|session (target|protocol)|dtmf-relay|codec|vad)\b
name
keyword.other.dial-peer.cisco


match
\b(compand-type|comfort-noise|cptone)\b
name
keyword.other.voice-port.cisco


match
\b(permit|deny|log|established|evaluate)\b
name
keyword.other.acl.cisco


match
\b(auth(entic|oriz)ation|accounting)\b
name
keyword.other.aaa.cisco


match
\bmatch (ip precedence|protocol|access-group)\b
name
keyword.other.class-map.cisco


match
\b(class(-default)?|set ip dscp|priority)\b
name
keyword.other.policy-map.cisco


match
\b(frame-relay|service-policy)\b
name
keyword.other.map-class.cisco


scopeName
source.cisco-ios-config
uuid
DDC9CB9E-AF2D-48A7-A600-12498CA0A59A

*1:^|no )(interface|line|ip (access-list (extended|standard)|dhcp (pool|excluded-address)|route|classless|subnet-zero|nat|http|local pool|flow-export|flow-top-talkers|inspect|domain|ips|host)|router|voice-(card|port)|dial-peer|voice (translation-(rule|profile)|register (global|pool|dn)|service)|application$|crypto (pki|keyring|isakmp (profile|policy|client configuration)|ipsec (profile|transform-set)|(dynamic-)?map)|telephony-service|ephone(-dn)?|banner|(class|policy|route)-map|map-class)|\b(ssid|pvc|certificate)|service|clock|boot|logging|control-plane|aaa|(tftp|snmp|radius)-server|ntp|bridge|(access|dialer)-list|archive)\b name support.control.cisco match \b([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|\h{1,4}\.\h{1,4}\.\h{1,4}(\.\h{1,2})?)\b name constant.numeric.cisco match \b((Fast|Gigabit)?Ethernet|Dialer|Dot11Radio|ATM|BRI|Tunnel(Group-)?Async|BVI|Loopback|Null|Port-channel|Virtual-(Access|Dot11Radio|PPP|Template

*2:\d+[\.:/])*)?\d+\b name constant.character.interface.cisco match ^!.*$ name comment.bang.cisco match \b(description|remark|system message)\s.*$ name comment.documentation.cisco match \bno\b name constant.language.cisco match ^version.*$ name constant.language.cisco match ^(username|hostname|enable)\b name keyword.other.cisco match \b(network|passive-interface|redistribute|auto-summary|synchronization|bgp|neighbor|default-information)\b name keyword.other.routing.cisco match \b(ip (address|unnumbered|proxy-arp|nat|nbar|virtual-reassembly|access-group|verify)|speed|(full-|half-)?duplex|cdp enable|encapsulation|dialer(-group)?|compress|ppp|crypto|channel|station-role|encryption|broadcast-key|snmp|isdn|dsl|tunnel|bandwidth|fair-queue|physical-layer|async mode|peer default|switchport|media-type|clockrate)\b name keyword.other.interface.cisco match \b((session|exec)-timeout|login|password|stopbits|access-class|transport (input|output