Skip to content

Commit

Permalink
Documentation (#7)
Browse files Browse the repository at this point in the history
init: add license file
doc: add README file
  • Loading branch information
pouriya authored Mar 5, 2023
1 parent d865ae5 commit 7cba860
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 28 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[package]
name = "sssh"
description = "Simply connect to your SSH server."
version = "1.0.0"
edition = "2021"
authors = ["pouriya.jahanbakhsh@gmail.com"]
repository = "https://github.com/pouriya/sssh"
license-file = "LICENSE"

[workspace.metadata]
APPLICATION_VERSION = "23.03.02"


[dependencies]
clap = {version = "4.1.*", default-features = false, features = ["std", "help", "usage", "derive", "env", "wrap_help", "cargo"]}
tracing = "0.1.*"
Expand Down
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2023, Pouriya Jim Jahanbakhsh
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the BLOOM Digital Platforms nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL BLOOM DIGITAL PLATFORMS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ DEV_CMD=${BUILD_DIR}/sssh-${VERSION}-${TARGET}-dev${RELEASE_FILENAME_POSTFIX}
RELEASE_FILENAME_POSTFIX=



all: release


Expand Down Expand Up @@ -41,8 +40,15 @@ test:
cargo test --target ${TARGET}


clean:
cargo clean

dist-clean: clean
rm -rf ${BUILD_DIR}


${BUILD_DIR}:
@ mkdir -p ${BUILD_DIR}


.PHONY: all release deb dev start-dev lint test
.PHONY: all release deb dev start-dev lint test clean dist-clean
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
![SSSH DEMO GIF](https://github.com/pouriya/restcommander/releases/download/media/sssh-demo.gif)


# SSSH
Simply connect to your ssh server.

## Installation
Download the latest version:
* GNU/Linux:
* Musl (Statically linked): [download](https://github.com/pouriya/sssh/releases/download/latest/sssh-latest-x86_64-unknown-linux-musl-ubuntu-22.04)
* GNU (Dynamic linking to glibc): [download](https://github.com/pouriya/sssh/releases/download/latest/sssh-latest-x86_64-unknown-linux-gnu-ubuntu-22.04)
* Debian package (`.deb` file):
* Musl (Statically linked): [download](https://github.com/pouriya/sssh/releases/download/latest/sssh-latest-x86_64-unknown-linux-musl-ubuntu-22.04.deb)
* GNU (Dynamic linking to glibc): [download](https://github.com/pouriya/sssh/releases/download/latest/sssh-latest-x86_64-unknown-linux-gnu-ubuntu-22.04.deb)
* macOS:
* v11: [download](https://github.com/pouriya/sssh/releases/download/latest/sssh-latest-x86_64-apple-darwin-macos-11)
* v12: [download](https://github.com/pouriya/sssh/releases/download/latest/sssh-latest-x86_64-apple-darwin-macos-12)
* Windows:
* MSVC: [download](https://github.com/pouriya/sssh/releases/download/latest/sssh-latest-x86_64-pc-windows-msvc-windows-2022.exe)
* GNU: [download](https://github.com/pouriya/sssh/releases/download/latest/sssh-latest-x86_64-pc-windows-gnu-windows-2022.exe)

## Usage
```shell
$ sssh --help
```
```text
Simply connect to your SSH server.
Usage: sssh [OPTIONS] [COMMAND]
Commands:
select
Select a server to connect from the terminal UI. (default)
edit
Edit configuration file to add/remove servers
config
Print current configuration file contents
script
Print current script file contents
sample
Samples for configuration and script
help
Print this message or the help of the given subcommand(s)
Options:
-v, --verbose
Increase verbosity
[env: SSSH_VERBOSE=]
-q, --quiet
Disable logging
[env: SSSH_QUIET=]
-c, --config-file <config-file>
TOML Configuration file.
For more information run `sssh sample config`
[env: SSSH_CONFIG_FILE=]
[default: /home/p/.config/sssh.toml]
-s, --script-file <script-file>
An executable file that will accept SSH info to connect to chosen server.
For more information run `sssh sample script`
[env: SSSH_SCRIPT_FILE=]
[default: /home/p/.config/sssh.sh]
-S, --skip-select
Skip running final script
[env: SSSH_SKIP_SELECT=]
-e, --editor-command <editor-command>
Editor command for editing configuration file
[env: SSSH_EDITOR_COMMAND=]
[default: nano]
-E, --editor-argument <editor-argument>
List of arguments passed to --editor-command
[env: SSSH_EDITOR_ARGUMENTS=]
[default: "-l {FILENAME}"]
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
```


# To contributors
I ❤️ PR from everyone and I appreciate your help but before opening a PR, Open an issue and describe your feature, bug, etc.

15 changes: 8 additions & 7 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ const TO_BE_SEARCHED_EDITOR_LIST: &[(&str, &[&str])] = &[
];
#[cfg(not(target_family = "unix"))]
const TO_BE_SEARCHED_EDITOR_LIST: &[(&str, &[&str])] = &[
// -multiInst: Launch another Notepad++ instance.
// -nosession:
// -notabbar:
(
"notepad++",
&[
Expand All @@ -55,6 +52,8 @@ pub struct Settings {
#[arg(short, long, global = true, env = "SSSH_QUIET")]
pub quiet: bool,
/// TOML Configuration file.
///
/// For more information run `sssh sample config`
#[arg(
name = "config-file",
short,
Expand All @@ -65,6 +64,8 @@ pub struct Settings {
)]
pub configuration_file: PathBuf,
/// An executable file that will accept SSH info to connect to chosen server.
///
/// For more information run `sssh sample script`
#[arg(
name = "script-file",
short,
Expand Down Expand Up @@ -109,13 +110,13 @@ pub struct Settings {

#[derive(Debug, Clone, PartialEq, Parser)]
pub enum SubCommand {
/// Select a server to connect from the terminal UI.
/// Select a server to connect from the terminal UI. (default)
Select,
/// Edit configuration file to add/remove servers.
Edit,
/// Prints current configuration file contents.
/// Print current configuration file contents.
Config,
/// Prints current script file contents.
/// Print current script file contents.
Script,
/// Samples for configuration and script.
#[command(subcommand)]
Expand Down Expand Up @@ -366,7 +367,7 @@ impl Config {
}

pub fn is_default_servers(&self) -> bool {
self.raw == DEFAULT_CONFIGURATION
self.raw.trim() == DEFAULT_CONFIGURATION.trim()
}
}

Expand Down
63 changes: 45 additions & 18 deletions src/subcommands/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crossterm::{
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use std::collections::HashMap;
use std::error::Error;
use std::path::PathBuf;
use tracing::debug;
use tui::layout::Rect;
Expand Down Expand Up @@ -358,29 +359,39 @@ pub fn run(settings: &mut Settings) -> Result<(), AppError> {
fn edit_and_convert_errors(settings: &mut Settings) -> Result<Option<String>, AppError> {
match edit(settings) {
Ok(_) => Ok(None),
Err(ref error @ AppError::ConfigSyntax { ref source, .. }) => {
Ok(Some(format!("{}\n{}", error, source)))
Err(ref error @ AppError::ConfigSyntax { .. }) => {
Ok(Some(error_to_string(error, String::new())))
}
Err(ref error @ AppError::EditorFastStop) => Ok(Some(format!(
"{}\nAfter editing configuration file press `r` to reload it.\n\nfile: {:?}",
error, settings.configuration_file
error_to_string(error, String::new()),
settings.configuration_file
))),
Err(ref error @ AppError::ProcessStart { ref source, .. }) => Ok(Some(format!(
"{}\n{}\nEdit the file manually and press `r` to reload it.",
error, source
Err(ref error @ AppError::ProcessStart { .. }) => Ok(Some(format!(
"{}\nEdit the file manually and press `r` to reload it.",
error_to_string(error, String::new())
))),
Err(ref error @ AppError::ProcessWait { ref source, .. }) => Ok(Some(format!(
"{}\n{}\nEdit the file manually and press `r` to reload it.",
error, source
Err(ref error @ AppError::ProcessWait { .. }) => Ok(Some(format!(
"{}\nEdit the file manually and press `r` to reload it.",
error_to_string(error, String::new())
))),
Err(ref error @ AppError::ProcessFailed { ref source, .. }) => Ok(Some(format!(
"{}\n{}\nEdit the file manually and press `r` to reload it.",
error, source
Err(ref error @ AppError::ProcessFailed { .. }) => Ok(Some(format!(
"{}\nEdit the file manually and press `r` to reload it.",
error_to_string(error, String::new())
))),
Err(error) => Err(error),
}
}

fn error_to_string<E: Error>(error: E, prefix: String) -> String {
let text = format!("{}\n{}", prefix, error);
if let Some(source) = error.source() {
error_to_string(source, text)
} else {
text
}
}

fn run_tui<B: Backend>(
settings: &mut Settings,
state: &mut State,
Expand Down Expand Up @@ -627,9 +638,17 @@ fn error_ui<B: Backend>(
.direction(Direction::Vertical)
.constraints(
[
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
Constraint::Length(if rect.height > line_count {
(rect.height - line_count) / 2
} else {
0
}),
Constraint::Length(line_count),
Constraint::Length(if rect.height > line_count {
(rect.height - line_count) / 2
} else {
0
}),
]
.as_ref(),
)
Expand All @@ -638,9 +657,17 @@ fn error_ui<B: Backend>(
.direction(Direction::Horizontal)
.constraints(
[
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
Constraint::Length(if rect.width > max_line_length as u16 {
(rect.width - max_line_length as u16) / 2
} else {
0
}),
Constraint::Length(max_line_length as u16),
Constraint::Length(if rect.width > max_line_length as u16 {
(rect.width - max_line_length as u16) / 2
} else {
0
}),
]
.as_ref(),
)
Expand Down

0 comments on commit 7cba860

Please sign in to comment.