kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

sshconfig.kak (5450B)


      1 hook global BufCreate .*/\.ssh/config %{
      2     set-option buffer filetype ssh
      3 }
      4 
      5 # Initialization
      6 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      7 
      8 hook global WinSetOption filetype=ssh %{
      9     require-module ssh
     10 
     11     set-option window static_words %opt{ssh_static_words}
     12 
     13     hook window InsertChar \n -group ssh-insert ssh-insert-on-new-line
     14     hook window InsertChar \n -group ssh-indent ssh-indent-on-new-line
     15 
     16     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ssh-.+ }
     17 }
     18 
     19 hook -group ssh-highlight global WinSetOption filetype=ssh %{
     20     add-highlighter window/ssh ref ssh
     21     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ssh }
     22 }
     23 
     24 provide-module ssh %@
     25 
     26 # Highlighters
     27 # ‾‾‾‾‾‾‾‾‾‾‾‾
     28 
     29 add-highlighter shared/ssh regions
     30 add-highlighter shared/ssh/code default-region group
     31 
     32 add-highlighter shared/ssh/double_string region %{(?<!\\)(?:\\\\)*\K"} %{(?<!\\)(?:\\\\)*"} group
     33 add-highlighter shared/ssh/single_string region %{(?<!\\)(?:\\\\)*\K'} %{'} fill string
     34 
     35 add-highlighter shared/ssh/comment region (?<!\\)(?:\\\\)*(?:^|\h)\K# '$' fill comment
     36 
     37 add-highlighter shared/ssh/double_string/fill fill string
     38 
     39 evaluate-commands %sh{
     40     keywords="AddKeysToAgent AddressFamily AskPassGUI BatchMode BindAddress CanonicalDomains CanonicalizeFallbackLocal CanonicalizeHostname
     41               CanonicalizeMaxDots CanonicalizePermittedCNAMEs ChallengeResponseAuthentication CheckHostIP Cipher Ciphers ClearAllForwardings
     42               Compression CompressionLevel ConnectionAttempts ConnectTimeout ControlMaster ControlPath ControlPersist DynamicForward
     43               EnableSSHKeysign EscapeChar ExitOnForwardFailure FingerprintHash ForwardAgent ForwardX11 ForwardX11Timeout ForwardX11Trusted
     44               GatewayPorts GlobalKnownHostsFile GSSAPIAuthentication GSSAPIClientIdentity GSSAPIDelegateCredentials GSSAPIKeyExchange
     45               GSSAPIRenewalForcesRekey GSSAPIServerIdentity GSSAPITrustDns HashKnownHosts Host HostbasedAuthentication HostbasedKeyTypes
     46               HostKeyAlgorithms HostKeyAlias HostName IdentitiesOnly IdentityFile IgnoreUnknown IPQoS KbdInteractiveAuthentication
     47               KbdInteractiveDevices KexAlgorithms KeychainIntegration LocalCommand LocalForward LogLevel MACs Match NoHostAuthenticationForLocalhost
     48               NumberOfPasswordPrompts PasswordAuthentication PermitLocalCommand PKCS11Provider Port PreferredAuthentications Protocol ProxyCommand
     49               ProxyJump ProxyUseFdpass PubkeyAuthentication RekeyLimit RemoteForward RequestTTY RevokedHostKeys RhostsRSAAuthentication
     50               RSAAuthentication SendEnv ServerAliveCountMax ServerAliveInterval SmartcardDevice StreamLocalBindMask StreamLocalBindUnlink
     51               StrictHostKeyChecking TCPKeepAlive Tunnel TunnelDevice UpdateHostKeys UseKeychain UsePrivilegedPort User UserKnownHostsFile
     52               VerifyHostKeyDNS VisualHostKey XAuthLocation"
     53 
     54     join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
     55 
     56     printf %s\\n "declare-option str-list ssh_static_words $(join "${keywords}" ' ') $(join "${builtins}" ' ')"
     57 
     58     printf %s\\n "add-highlighter shared/ssh/code/ regex (?<!-)\b($(join "${keywords}" '|'))\b(?!-) 0:keyword"
     59 }
     60 
     61 add-highlighter shared/ssh/code/ regex ^host\s+ 0:keyword
     62 
     63 # Commands
     64 # ‾‾‾‾‾‾‾‾
     65 
     66 define-command -hidden ssh-insert-on-new-line %{ evaluate-commands -itersel -draft %{
     67     execute-keys <semicolon>
     68     try %{
     69         evaluate-commands -draft -save-regs '/"' %{
     70             # Ensure previous line is a comment
     71             execute-keys -draft kxs^\h*#+\h*<ret>
     72 
     73             # now handle the coment continuation logic
     74             try %{
     75                 # try and match a regular block comment, copying the prefix
     76                 execute-keys -draft -save-regs '' k x 1s^(\h*#+\h*)\S.*$ <ret> y
     77                 execute-keys -draft P
     78             } catch %{
     79                 try %{
     80                     # try and match a regular block comment followed by a single
     81                     # empty comment line
     82                     execute-keys -draft -save-regs '' kKx 1s^(\h*#+\h*)\S+\n\h*#+\h*$ <ret> y
     83                     execute-keys -draft P
     84                 } catch %{
     85                     try %{
     86                         # try and match a pair of empty comment lines, and delete
     87                         # them if we match
     88                         execute-keys -draft kKx <a-k> ^\h*#+\h*\n\h*#+\h*$ <ret> <a-d>
     89                     } catch %{
     90                         # finally, we need a special case for a new line inserted
     91                         # into a file that consists of a single empty comment - in
     92                         # that case we can't expect to copy the trailing whitespace,
     93                         # so we add our own
     94                         execute-keys -draft -save-regs '' k x1s^(\h*#+)\h*$<ret> y
     95                         execute-keys -draft P
     96                         execute-keys -draft i<space>
     97                     }
     98                 }
     99             }
    100         }
    101 
    102         # trim trailing whitespace on the previous line
    103         try %{ execute-keys -draft k x s\h+$<ret> d }
    104     }
    105 } }
    106 
    107 define-command -hidden ssh-indent-on-new-line %<
    108     evaluate-commands -draft -itersel %<
    109         # preserve previous line indent
    110         try %{ execute-keys -draft <semicolon> K <a-&> }
    111         # cleanup trailing whitespaces from previous line
    112         try %{ execute-keys -draft k x s \h+$ <ret> d }
    113     >
    114 >
    115 
    116 @