Skip to content

Commit

Permalink
Installer will now install module
Browse files Browse the repository at this point in the history
  • Loading branch information
SirJson committed May 10, 2020
1 parent a1643c0 commit 7607e4e
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 18 deletions.
30 changes: 23 additions & 7 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class Kernel32
/// </summary>
public partial class App : Application
{
public static string DataPath, LogPath, ScriptPath, ModulePath;
public static string DataPath, LogPath, ScriptPath;
static readonly Mutex singleAppMutex = new Mutex(true, "{14E68EB5-8922-4752-B03C-D3D672135FA6}");

public static void Panic(string message)
Expand All @@ -42,22 +42,34 @@ private void EnsureDirectory(string path)
}
}

private void InstallIfNotExists(string file, byte[] data)
{
if(File.Exists(file)) return;
Log.Information("Installing {file}", file);
File.WriteAllBytes(file, data);
}

private void InstallAssets() {
Log.Debug("Installing {file}", ScriptPath);
File.WriteAllBytes(ScriptPath, Scripts.sshchild);
//var modPath = Environment.GetEnvironmentVariable("PSModulePath").Split(";").First();
var modDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),"PowerShell","Modules","ReadNamedPipe");
var modDefinition = Path.Combine(modDir, "ReadNamedPipe.psd1");
var modAssembly = Path.Combine(modDir, "ReadNamedPipeCmdlet.dll");
EnsureDirectory(modDir);
InstallIfNotExists(ScriptPath,Scripts.sshchild);
InstallIfNotExists(modDefinition,Scripts.ModuleDefinition);
InstallIfNotExists(modAssembly,Scripts.ReadNamedPipeCmdlet);
}

private void Application_Startup(object sender, StartupEventArgs e)
{
if (singleAppMutex.WaitOne(TimeSpan.Zero, true))
{

DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SSHMan");
ScriptPath = Path.Combine(DataPath, "sshchild.ps1");
ModulePath = Path.Combine(DataPath, "ReadNamedPipeCmdlet.dll");
EnsureDirectory(DataPath);
InstallAssets();
LogPath = Path.Combine(DataPath, "sshman.log");

EnsureDirectory(DataPath);

if (e.Args.Length > 0 && e.Args[0] == "-d")
{
DebugLogger();
Expand All @@ -66,6 +78,10 @@ private void Application_Startup(object sender, StartupEventArgs e)
{
StandardLogger();
}

InstallAssets();


}
else
{
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SSHMan

A Windows Terminal launcher for SSH connections defined in your ssh config.

![screenshot](screenshot.PNG)

It basically parses your user SSH config and creates a list of all entries. On connect it will open the new Windows Terminal and connect to the selected Server.

This is an easy alternative to creating a profile inside your Terminal config for every remote connection you already have in your SSH config.

## Installation

This project depends on

- The new Windows Terminal
- PowerShell 6+

If you have PowerShell 6 or 7 installed and the Windows Terminal it will automatically make sure that you also have the included ReadNamedPipe Module and the launcher script installed.

All you need to do is define a Profile inside your Terminal config with the name `Remote`. Here you can choose what ever settings you like for your remote connections like font or color scheme.

This is the profile I use, you can use this as an example or just use it as is

```json
{
"guid": "{8954ce30-29ac-4335-997a-4a96c00ded5a}",
"hidden": false,
"name": "Remote",
"fontFace": "Hack NF",
"colorScheme":"Lab Fox",
"useAcrylic": false,
"fontSize": 9
}
```



## How this works

After parsing you press „Connect“ it will run st.exe with the new-tab action and the Remote Profile. From there it will run [sshchild.ps1](https://github.com/SirJson/SSHMan/blob/master/sshchild.ps1)

At the sametime the launcher will provide a named pipe with a guid that it passed to sshchild.ps1 and waits for a connection. If both are connected the script will receive the parameter it need to launch your ssh session.
10 changes: 5 additions & 5 deletions SSHChild/ReadNamedPipe.psd1 → ReadNamedPipe.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ ModuleVersion = '1.0.0'
GUID = '286de10b-5431-4941-8753-de95f8ef6cc9'

# Author of this module
Author = 'SirJson'
Author = 'Raffael Zica'

# Company or vendor of this module
CompanyName = 'SirJson'
CompanyName = 'Pixeltastic'

# Copyright statement for this module
Copyright = '(c) SirJson. All rights reserved.'
Copyright = '(c) Raffael Zica. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Helper for reading string data from named pipes'
Expand Down Expand Up @@ -98,10 +98,10 @@ PrivateData = @{
Tags = @("IPC","NamedPipe","Windows","Win32","dotnet")

# A URL to the license for this module.
LicenseUri = ''
LicenseUri = 'https://raw.githubusercontent.com/SirJson/SSHMan/master/LICENSE'

# A URL to the main website for this project.
# ProjectUri = ''
ProjectUri = 'https://github.com/SirJson/SSHMan'

# A URL to an icon representing this module.
# IconUri = ''
Expand Down
3 changes: 0 additions & 3 deletions ReadNamedPipe.zip

This file was deleted.

Binary file added ReadNamedPipeCmdlet.dll
Binary file not shown.
3 changes: 0 additions & 3 deletions SSHMan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
</ItemGroup>

<ItemGroup>
<None Update="ReadNamedPipeCmdlet.dll">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="sshchild.ps1">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
Expand Down
20 changes: 20 additions & 0 deletions Scripts.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Scripts.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ModuleDefinition" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>ReadNamedPipe.psd1;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="ReadNamedPipeCmdlet" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>ReadNamedPipeCmdlet.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="sshchild" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>sshchild.ps1;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions screenshot.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7607e4e

Please sign in to comment.