Skip to content

Commit

Permalink
feat(ssh): add ssh layer
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdjeg committed Oct 16, 2021
1 parent 63c2bbf commit 3f87245
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 8 deletions.
62 changes: 62 additions & 0 deletions autoload/SpaceVim/layers/ssh.vim
@@ -0,0 +1,62 @@
"=============================================================================
" ssh.vim --- ssh layer for spacevim
" Copyright (c) 2016-2019 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================


""
" @section ssh, layers-ssh
" @parentsection layers
" The `ssh` layer provides basic function to connected to ssh server.
"
" @subsection layer options
"
" 1. `ssh_port`: set the port of ssh server
" 2. `ssh_address`: set the ip of ssh server
" 3. `ssh_user`: set the user name of ssh server
"
" @subsection key bindings
" >
" Key Bingding Description
" SPC S o connect to ssh server
" <

if exists('s:ssh')
finish
endif

let s:ssh = 'ssh'
let s:user = 'root'
let s:ip = '127.0.0.1'
let s:port = '20'

function! SpaceVim#layers#ssh#config() abort
let g:_spacevim_mappings_space.S = {'name' : '+SSH'}
call SpaceVim#mapping#space#langSPC('nmap', ['S','o'],
\ 'call SpaceVim#layers#ssh#connect()',
\ 'connect-to-ssh-server', 1)
endfunction

function! SpaceVim#layers#ssh#set_variable(opt) abort
let s:ssh = get(a:opt, 'ssh_command', s:ssh)
let s:user = get(a:opt, 'ssh_user', s:user)
let s:ip = get(a:opt, 'ssh_address', s:ip)
let s:port = get(a:opt, 'ssh_port', s:port)
endfunction

function! SpaceVim#layers#ssh#connect() abort
if has('nvim')
call termopen([s:ssh, '-p', s:port, s:user . '@' . s:ip])
else
call term_start([s:ssh, '-p', s:port, s:user . '@' . s:ip], {'curwin' : 1, 'term_finish' : 'close'})
endif
endfunction

function! SpaceVim#layers#ssh#get_options() abort

return ['ssh_port', 'ssh_user', 'ssh_address', 'ssh_command']

endfunction
35 changes: 27 additions & 8 deletions doc/SpaceVim.txt
Expand Up @@ -192,14 +192,15 @@ CONTENTS *SpaceVim-contents*
106. leaderf...................................|SpaceVim-layers-leaderf|
107. operator.................................|SpaceVim-layers-operator|
108. shell.......................................|SpaceVim-layers-shell|
109. test.........................................|SpaceVim-layers-test|
110. tmux.........................................|SpaceVim-layers-tmux|
111. tools#dash.............................|SpaceVim-layers-tools-dash|
112. tools#mpv...............................|SpaceVim-layers-tools-mpv|
113. tools#zeal.............................|SpaceVim-layers-tools-zeal|
114. treesitter.............................|SpaceVim-layers-treesitter|
115. ui.............................................|SpaceVim-layers-ui|
116. unite.......................................|SpaceVim-layers-unite|
109. ssh...........................................|SpaceVim-layers-ssh|
110. test.........................................|SpaceVim-layers-test|
111. tmux.........................................|SpaceVim-layers-tmux|
112. tools#dash.............................|SpaceVim-layers-tools-dash|
113. tools#mpv...............................|SpaceVim-layers-tools-mpv|
114. tools#zeal.............................|SpaceVim-layers-tools-zeal|
115. treesitter.............................|SpaceVim-layers-treesitter|
116. ui.............................................|SpaceVim-layers-ui|
117. unite.......................................|SpaceVim-layers-unite|
7. Usage....................................................|SpaceVim-usage|
1. buffers-and-files..................|SpaceVim-usage-buffers-and-files|
2. custom_plugins........................|SpaceVim-usage-custom_plugins|
Expand Down Expand Up @@ -4575,6 +4576,24 @@ KEY BINDINGS
q Hide terminal windows in normal mode
<

==============================================================================
SSH *SpaceVim-layers-ssh*

The `ssh` layer provides basic function to connected to ssh server.

LAYER OPTIONS

1. `ssh_port`: set the port of ssh server
2. `ssh_address`: set the ip of ssh server
3. `ssh_user`: set the user name of ssh server

KEY BINDINGS

>
Key Bingding Description
SPC S o connect to ssh server
<

==============================================================================
TEST *SpaceVim-layers-test*

Expand Down
2 changes: 2 additions & 0 deletions docs/layers.md
Expand Up @@ -189,13 +189,15 @@ Some layers are enabled by default. The following example shows how to disable `
| [language-server-protocol](language-server-protocol/) | This layers provides language server protocol for vim and neovim |
| [leaderf](leaderf/) | This layer provides a heavily customized LeaderF centric workflow |
| [shell](shell/) | This layer provides shell support in SpaceVim |
| [ssh](ssh/) | This layer provides ssh support in SpaceVim |
| [sudo](sudo/) | sudo layer provides the ability to read and write files with elevated privileges in SpaceVim |
| [test](test/) | This layer allows to run tests directly in SpaceVim |
| [tmux](tmux/) | This layers adds extensive support for tmux |
| [tools#dash](tools/dash/) | This layer provides Dash integration for SpaceVim |
| [tools#mpv](tools/mpv/) | This layer provides mpv integration for SpaceVim |
| [tools#zeal](tools/zeal/) | This layer provides Zeal integration for SpaceVim |
| [tools](tools/) | This layer provides some tools for vim |
| [treesitter](treesitter/) | This layers adds extensive support for treesitter |
| [ui](ui/) | Awesome UI layer for SpaceVim, provide IDE-like UI for neovim and vim in both TUI and GUI |
| [unite](unite/) | This layer provides a heavily customized Unite centric workflow |
| [VersionControl](VersionControl/) | This layer provides general version control features for SpaceVim. It should work with all VC backends such as Git, Mercurial, Bazaar, SVN, etc |
Expand Down
51 changes: 51 additions & 0 deletions docs/layers/ssh.md
@@ -0,0 +1,51 @@
---
title: "SpaceVim ssh layer"
description: "This layer provides ssh support in SpaceVim"
---

# [Available Layers](../) >> shell

<!-- vim-markdown-toc GFM -->

- [Description](#description)
- [Install](#install)
- [Configuration](#configuration)
- [Key bindings](#key-bindings)

<!-- vim-markdown-toc -->

## Description

This layer provides ssh connection support for SpaceVim.

## Install

To use this configuration layer, add following snippet to your custom configuration file.

```toml
[[layers]]
name = "ssh"
```

## Configuration

- `ssh_port`: set the port of ssh server
- `ssh_address`: set the ip of ssh server
- `ssh_user`: set the user name of ssh server

Example:

```
[[layers]]
name = 'ssh'
ssh_command = 'D:\Programs\Git\usr\bin\ssh.exe'
ssh_user = 'root'
ssh_address = '192.168.1.10'
ssh_port = '8097'
```

## Key bindings

| Key Binding | Description |
| ----------- | --------------------------- |
| `SPC S o` | open ssh connection windows |

0 comments on commit 3f87245

Please sign in to comment.