Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH config highlighting #1543

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rouge/demos/ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Host example
Hostname example.com
User user
Port 1234
33 changes: 33 additions & 0 deletions lib/rouge/lexers/ssh.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
module Lexers
class SSH < RegexLexer
tag 'ssh'

title "SSH Config File"
desc 'A lexer for SSH configuration files'
filenames 'config', 'ssh_config'
pyrmont marked this conversation as resolved.
Show resolved Hide resolved

state :root do
rule %r/[a-z0-9]+/i, Keyword, :statement
mixin :base
end

state :statement do
rule %r/\n/, Text, :pop!
rule %r/(?:yes|no|confirm|ask|always|auto|none|force)\b/, Name::Constant

rule %r/\d+/, Num
rule %r/[^#\s;{}$\\]+/, Text
mixin :base
end

state :base do
rule %r/\s+/, Text
rule %r/#.*/, Comment::Single
end
end
end
end
26 changes: 26 additions & 0 deletions spec/lexers/ssh_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Lexers::SSH do
pyrmont marked this conversation as resolved.
Show resolved Hide resolved
let(:subject) { Rouge::Lexers::SSH.new }
include Support::Lexing

it 'lexes a specification' do
example = 'Host example
Hostname www.example.com
Port 1234
Tunnel no'

assert_tokens_equal example, ["Keyword", "Host"],
["Text", " example\n "],
["Keyword", "Hostname"],
["Text", " www.example.com\n "],
["Keyword", "Port"],
["Text", " "],
["Literal.Number", "1234"],
["Text", "\n "],
["Keyword", "Tunnel"],
["Text", " "],
["Name.Constant", "no"]
end
end
15 changes: 15 additions & 0 deletions spec/visual/samples/ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This is the ssh client system-wide configuration file. See
# ssh_config(5) for more information. This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

Host *
Port 22 # default port
Tunnel no
GSSAPIAuthentication yes
GSSAPIDelegateCredentials no

Host example
Hostname www.example.com
User user
Port 1234