Compare commits

3 Commits
v0.0.0 ... main

Author SHA1 Message Date
Denys Seredenko
121c2505e6 * showing help by basic call
All checks were successful
Build and Test / build-test (1.23.4) (push) Successful in 1m37s
* autocompletion for exec
2025-02-18 19:34:15 +01:00
Denys Seredenko
a21b9cfa84 naming improvements
All checks were successful
Build and Test / build-test (1.23.4) (push) Successful in 41s
2025-01-15 12:58:30 +01:00
Denys Seredenko
bde8c0184a naming improvements
All checks were successful
Build and Test / build-test-publish (1.23.4) (push) Successful in 45s
2025-01-15 12:58:03 +01:00
7 changed files with 39 additions and 16 deletions

View File

@@ -1,12 +1,9 @@
name: Go name: Build and Test
on: [push] on: [push]
env:
VERSION: v0.0.0
jobs: jobs:
build-test-publish: build-test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:

View File

@@ -1,4 +1,4 @@
name: Release name: Add executable to release
on: [release] on: [release]

15
Readme.md Normal file
View File

@@ -0,0 +1,15 @@
# SSH-HUB - portable command hub
## Autocompletion
In order to create autocompletion you have to:
- Download executable or clone project and write go install
- Then consult with ssh-hub completion. There you can select needed script for your terminal
- After that source it to have autocompletion and you are ready to go
Example in Mac OS with ZSH:
- go build
- go install
- ssh-hub completion zsh > ssh-hub-completion.zsh
- source ssh-hub-completion.zsh
- Now you should have it! Try using a ssh-hub exec [TAB] [TAB] it will help to find needed command

View File

@@ -3,6 +3,7 @@ package exec
import ( import (
"errors" "errors"
"fmt" "fmt"
"git.denysoft.de/CubeBit/ssh-hub/util"
"github.com/creack/pty" "github.com/creack/pty"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
@@ -16,6 +17,10 @@ import (
var execCmd = &cobra.Command{ var execCmd = &cobra.Command{
Use: "exec", Use: "exec",
Short: "Execute command of specific alias", Short: "Execute command of specific alias",
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
data := viper.GetStringMapString("data")
return util.AutocompleteConfig(&data, toComplete), cobra.ShellCompDirectiveNoFileComp
},
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.ExactArgs(1)(cmd, args); err != nil { if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return err return err

View File

@@ -11,7 +11,7 @@ import (
var replaceCmd = &cobra.Command{ var replaceCmd = &cobra.Command{
Use: "replace", Use: "replace",
Short: "Replace in string to new string in all commands", Short: "Replace string with new string in all commands",
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.ExactArgs(2)(cmd, args); err != nil { if err := cobra.ExactArgs(2)(cmd, args); err != nil {
return err return err

View File

@@ -14,15 +14,15 @@ import (
"os" "os"
) )
var validArgs = []string{"list", "replace", "add", "delete", "exec"}
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "ssh-hub", Use: "ssh-hub",
Short: "ssh-hub is a simple SSH manager. Storing all your ssh commands and managing them", Short: "ssh-hub is a simple SSH manager. Storing all your ssh commands and managing them",
Long: "ssh-hub was created in order to automatically manage ssh commands and different Groups.\n " + Long: "ssh-hub was created in order to automatically manage ssh commands and different Groups.\n " +
"\tCreate groups based on projects, environments etc and add there your ssh commands.\n " + "\tCreate groups based on projects, environments etc and add there your ssh commands.\n " +
"\tWe will carefully manage all known sessions and groups.", "\tWe will carefully manage all known sessions and groups.",
Run: func(cmd *cobra.Command, args []string) { ValidArgs: validArgs,
fmt.Println("Welcome to ssh-hub!")
},
} }
func Execute() { func Execute() {
@@ -72,13 +72,8 @@ ssh-hub
├── ssh - Execute an SSH command (with autocomplete) ├── ssh - Execute an SSH command (with autocomplete)
├── add - Add a new command or group ├── add - Add a new command or group
│ ├── command - Save an SSH command │ ├── command - Save an SSH command
│ └── group - Create a group of commands
├── exec - Execute a saved command or group ├── exec - Execute a saved command or group
├── remove - Remove a command or group ├── delete - Remove a command or group
├── groups - Manage groups
│ ├── add - Add a command to a group
│ ├── remove - Remove a command from a group
│ └── list - List commands in a group
├── autocomplete - Enable or generate shell autocompletion ├── autocomplete - Enable or generate shell autocompletion
└── help - Display help information for commands └── help - Display help information for commands
*/ */

View File

@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os" "os"
"strings"
) )
func SaveConfig(data *map[string]string) error { func SaveConfig(data *map[string]string) error {
@@ -19,3 +20,13 @@ func SaveConfig(data *map[string]string) error {
return nil return nil
} }
func AutocompleteConfig(conf *map[string]string, partialInput string) []string {
var result []string
for key := range *conf {
if strings.Contains(key, partialInput) {
result = append(result, key)
}
}
return result
}