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
*2:\d+[\.:/])*)?\d+\b