Skip to content

Commit

Permalink
Merge pull request #11 from blacknon/develop
Browse files Browse the repository at this point in the history
Develop(ver 0.4.3)
  • Loading branch information
blacknon authored May 27, 2018
2 parents ad2f20b + 5134e6e commit 2257a19
Show file tree
Hide file tree
Showing 21 changed files with 577 additions and 92 deletions.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.DS_Store
lssh.sublime-project
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Go コマンド
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get

build:
$(GOBUILD) lssh.go
$(GOBUILD) lscp.go
clean:
$(GOCLEAN)
rm -f lssh
rm -f lscp
install:
cp lssh /usr/local/bin/
cp lscp /usr/local/bin/
cp -n example/config.tml ~/.lssh.conf || true
107 changes: 80 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
lssh
====

List select formula ssh wrapper for terminal UI
TUI list select ssh/scp client.

## Description

lssh - A command to read a prepared list in advance and connect to ssh to the selected host. list file is set in yaml format.When selecting a host, you can filter by keywords.Execute commands concurrently to multiple hosts.
command to read a prepared list in advance and connect ssh/scp the selected host. List file is set in yaml format.When selecting a host, you can filter by keywords. Can execute commands concurrently to multiple hosts.

## Demo

Expand All @@ -20,24 +20,27 @@ lssh - A command to read a prepared list in advance and connect to ssh to the se
need the following command.

- ssh
- scp (remote host)

## Install

go get github.com/blacknon/lssh
go install github.com/blacknon/lssh
cp $GOPATH/src/github.com/blacknon/lssh/example/config.tml ~/.lssh.conf
chmod 600 ~/.lssh.conf
go get github.com/blacknon/lssh
cd $GOPATH/src/github.com/blacknon/lssh
make && sudo make install && make clean

## Usage

Please edit "~/.lssh.conf".
Please edit "~/.lssh.conf". The connection information at servers,can be divided into external files.

example)
example:

[log]
enable = true
dirpath = "/path/to/logdir"

[include.Name]
path = "/path/to/include/file"

[server.PasswordAuth_ServerName]
addr = "192.168.100.101"
port = "22"
Expand All @@ -58,26 +61,40 @@ After exec command.
lssh


option
option(lssh)

lssh v0.4.1
usage: lssh [--host HOST] [--list] [--file FILE] [--terminal] [--parallel] [--command COMMAND]
lssh v0.4.3
Usage: lssh [--host HOST] [--list] [--file FILE] [--terminal] [--parallel] [--command COMMAND]

options:
Options:
--host HOST, -H HOST Connect servername
--list, -l print server list
--file FILE, -f FILE config file path [default: /home/blacknon/.lssh.conf]
--terminal, -T Run specified command at terminal
--parallel, -P Exec command parallel node(tail -F etc...)
--command COMMAND, -C COMMAND
Remote Server exec command.
--file FILE, -f FILE config file path [default: /Users/uesugi/.lssh.conf]
--terminal, -t Run specified command at terminal
--parallel, -p Exec command parallel node(tail -F etc...)
--command COMMAND, -c COMMAND
Remote Server exec command.
--help, -h display this help and exit
--version display version and exit

If you specify a command as an argument, you can select multiple hosts.Select host 'Ctrl + X',select all displayed hosts 'Ctrl + A'.
option(lscp)

lscp v0.4.3
Usage: lscp [--host HOST] [--file FILE] FROM TO

Positional arguments:
FROM Copy from path
TO Copy to path

Options:
--host HOST, -H HOST Connect servername
--file FILE, -f FILE config file path [default: /Users/uesugi/.lssh.conf]
--help, -h display this help and exit
--version display version and exit

If you specify a command as an argument, you can select multiple hosts. Select host 'Tab', select all displayed hosts 'Ctrl + A'.

### copy files using stdin/stdout to/from remote server
### [lssh] copy files using stdin/stdout to/from remote server

You can scp like copy files using stdin/stdout.It also supports multiple nodes(parallel is not yet supported now).

Expand All @@ -91,29 +108,65 @@ You can scp like copy files using stdin/stdout.It also supports multiple nodes(p
<img src="./example/lssh_stdcp.gif" />
</p>

### [lssh] multiple node select exec tail -f


# -p option parallel exec command
lssh -p -c 'cmd'

### multi node select exec tail -f

<p align="center">
<img src="./example/lssh_parallel.gif" />
</p>

### Use list select type ssh gateway server
### [lscp] scp remote to local (get)

exec lscp get file/dir (remote to local scp).

lscp remote:/path/to/remote local:/path/to/local

# short version
lscp r:/path/to/remote l:/path/to/local


<p align="center">
<img src="./example/scp_l2r1.gif" />
</p>

<p align="center">
<img src="./example/scp_l2r2.gif" />
</p>

#### '/etc/passwd' use (or .ssh/authorized_keys)

To use as a ssh gateway server as list select type, specify it at an execution command in "/etc/passwd"( or "authorized_keys").
### [lscp] scp local to remote (put)

ex) /etc/passwd
exec lscp put file/dir (local to remote scp). If multiple server selected, mkdir servername dir.

lssh:x:1000:1000::/home/lssh:/bin/lssh
lscp local:/path/to/remote remote:/path/to/local

# short version
lscp l:/path/to/local r:/path/to/remote

<p align="center">
<img src="./example/scp_r2l.gif" />
</p>


### [lscp] scp remote to remote

exec lscp get/put file/dir (remote to remote scp).

lscp remote:/path/to/remote(get) remote:/path/to/remote(put)

# short version
lscp r:/path/to/remote(get) r:/path/to/local(put)

Arrange "~/.lssh.conf" and connect with ssh.

<p align="center">
<img src="./example/lssh_withpasswd.gif" />
<img src="./example/scp_r2r.gif" />
</p>


## Licence

A short snippet describing the license [MIT](https://github.com/blacknon/lssh/blob/master/LICENSE.md).
Expand Down
8 changes: 8 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencies:
override:
- go get -t -d -v ./...
- make
test:
override:
- ./lssh --help
- ./lscp --help
52 changes: 51 additions & 1 deletion conf/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@ package conf
import (
"fmt"
"os"
"os/user"
"path/filepath"
"runtime"
"strings"
)

func GetFullPath(path string) (fullPath string) {
usr, _ := user.Current()
fullPath = strings.Replace(path, "~", usr.HomeDir, 1)
fullPath, _ = filepath.Abs(fullPath)
return fullPath
}

func PathWalkDir(dir string) (files []string, err error) {
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
path = path + "/"
}
files = append(files, path)
return nil
})
return
}

func isExist(filename string) bool {
_, err := os.Stat(filename)
return err == nil
Expand All @@ -26,7 +47,7 @@ func checkOS() {

func checkCommandExist(cmd string) {
if (isExist(cmd)) == false {
fmt.Printf("%s:Not Found.\n", cmd)
fmt.Fprintf(os.Stderr, "%s:Not Found.\n", cmd)
}
}

Expand Down Expand Up @@ -76,3 +97,32 @@ func CheckInputServerExit(inputServer []string, nameList []string) bool {
}
return false
}

func ParsePathArg(arg string) (hostType string, path string, result bool) {
argArray := strings.SplitN(arg, ":", 2)

// check split count
if len(argArray) != 2 {
hostType = ""
path = ""
result = false
return
}

array1 := strings.ToLower(argArray[0])
switch array1 {
case "local", "l":
hostType = "local"
path = argArray[1]
case "remote", "r":
hostType = "remote"
path = argArray[1]
default:
hostType = ""
path = ""
result = false
return
}
result = true
return
}
2 changes: 0 additions & 2 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func ReadConf(confPath string) (checkConf Config) {
}

if checkConf.Include != nil {

for _, v := range checkConf.Include {
//var serverconf ServerConfig
usr, _ := user.Current()
Expand All @@ -55,7 +54,6 @@ func ReadConf(confPath string) (checkConf Config) {
if err != nil {
panic(err)
}
//fmt.Println(&checkConf)
}
}

Expand Down
Binary file modified example/lssh.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example/lssh_parallel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example/lssh_stdcp.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/scp_l2r1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/scp_l2r2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/scp_r2l.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/scp_r2r.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 14 additions & 10 deletions list/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,32 @@ func (l *ListInfo) keyEvent() (lineData []string) {
}
l.draw()

// Ctrl + x Key(select)
case termbox.KeyCtrlX:
// Tab Key(select)
case termbox.KeyTab:
if l.MultiFlag == true {
l.toggle(strings.Fields(l.ViewText[l.CursorLine+1])[0])
}
if l.CursorLine < len(l.ViewText)-headLine {
l.CursorLine += 1
}
l.draw()

// Ctrl + a Key(all select)
case termbox.KeyCtrlA:
// allFlag Toggle
if allFlag == false {
allFlag = true
} else {
allFlag = false
}

if l.MultiFlag == true {
l.allToggle(allFlag)
// allFlag Toggle
if allFlag == false {
allFlag = true
} else {
allFlag = false
}
}

l.draw()

// Ctrl + h Key(Help Window)
//case termbox.KeyCtrlH:

// Enter Key
case termbox.KeyEnter:
if len(l.SelectName) == 0 {
Expand Down
19 changes: 15 additions & 4 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import (
termbox "github.com/nsf/termbox-go"
)

func arrayContains(arr []string, str string) bool {
for _, v := range arr {
if v == str {
return true
}
}
return false
}

// toggle select line (multi select)
func (l *ListInfo) toggle(newLine string) {
tmpList := []string{}
Expand All @@ -30,18 +39,21 @@ func (l *ListInfo) toggle(newLine string) {
}

func (l *ListInfo) allToggle(allFlag bool) {
SelectedList := []string{}
allSelectedList := []string{}
// selectedList in allSelectedList
for _, selectedLine := range l.SelectName {
allSelectedList = append(allSelectedList, selectedLine)
SelectedList = append(SelectedList, selectedLine)
}

// allFlag is False
if allFlag == false {
for _, addLine := range l.ViewText[1:] {
addName := strings.Fields(addLine)[0]
allSelectedList = append(allSelectedList, addName)
l.toggle(addName)
if !arrayContains(SelectedList, addName) {
allSelectedList = append(allSelectedList, addName)
l.toggle(addName)
}
}
return
} else {
Expand Down Expand Up @@ -78,7 +90,6 @@ func (l *ListInfo) getText() {
}
}

//func (l *ListInfo) getFilterText(searchText string, listData []string) (returnListData []string) {
func (l *ListInfo) getFilterText() {
// Initialization ViewText
l.ViewText = []string{}
Expand Down
Loading

0 comments on commit 2257a19

Please sign in to comment.