Skip to content

Commit 8447163

Browse files
committed
Add "sysinfo" command that also displays the status of the 1Password integration
1 parent 7d7d54a commit 8447163

File tree

5 files changed

+71
-1
lines changed

5 files changed

+71
-1
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"MD036": false,
1212
},
1313
"cSpell.words": [
14-
"datadir"
14+
"datadir",
15+
"sysinfo"
1516
]
1617
}

app/1Password.psm1

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#
2+
# Module for 1Password integration
3+
#
4+
# See: https://developer.1password.com/docs/ssh/get-started
5+
#
6+
17
# Stop on every error
28
$script:ErrorActionPreference = 'Stop'
39

@@ -6,6 +12,7 @@ Import-Module "$PSScriptRoot/Utils.psm1"
612
function Test-Is1PasswordIntegrationSupported() {
713
return Test-IsWindows -or $IsMacOs
814
}
15+
Export-ModuleMember -Function Test-Is1PasswordIntegrationSupported
916

1017
function Test-Is1PasswordInstalled() {
1118
if (-Not (Test-Is1PasswordIntegrationSupported)) {

app/SshEnvApp.ps1

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Import-Module "$PSScriptRoot/SshEnvAppAux.psm1"
1212
Import-Module "$PSScriptRoot/Installation.psm1"
1313
Import-Module "$PSScriptRoot/SshDataDir.psm1"
1414
Import-Module "$PSScriptRoot/SshConfig.psm1"
15+
Import-Module "$PSScriptRoot/SysInfo.psm1"
1516

1617
if ($args.Length -eq 0) {
1718
Write-Help 'No command specified'
@@ -211,6 +212,11 @@ function Invoke-SshEnvApp {
211212
break
212213
}
213214

215+
'sysinfo' {
216+
Write-SysInfo
217+
break
218+
}
219+
214220
'version|--version|-v' {
215221
$version = Get-EnvVersion
216222
Write-Host "ssh-env version $version"

app/SysInfo.psm1

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Stop on every error
2+
$script:ErrorActionPreference = 'Stop'
3+
4+
Import-Module "$PSScriptRoot/Utils.psm1"
5+
Import-Module "$PSScriptRoot/Installation.psm1"
6+
Import-Module "$PSScriptRoot/1Password.psm1"
7+
8+
function Get-OperatingSystemName() {
9+
if (Test-IsWindows) {
10+
return 'Windows'
11+
}
12+
elseif ($IsMacOs) {
13+
return 'macOS'
14+
}
15+
elseif ($IsLinux) {
16+
return 'Linux'
17+
}
18+
else {
19+
return 'unsupported'
20+
}
21+
}
22+
23+
function Get-1PasswordIntegrationStatus() {
24+
if (-Not (Test-Is1PasswordIntegrationSupported)) {
25+
return "unsupported operating system"
26+
}
27+
28+
if (-Not (Test-Is1PasswordInstalled)) {
29+
return "1Password not installed"
30+
}
31+
32+
if (-Not (Test-Is1PasswordSshAgentEnabled)) {
33+
return "1Password SSH agent not enabled"
34+
}
35+
36+
return "1Password SSH agent enabled"
37+
}
38+
39+
function Write-SysInfo() {
40+
$osName = Get-OperatingSystemName
41+
Write-Host "Operating System: $osName"
42+
43+
if (Test-IsWindows) {
44+
if (Test-IsMicrosoftSsh) {
45+
Write-Host 'Use Microsoft SSH: yes'
46+
}
47+
else {
48+
Write-Host 'Use Microsoft SSH: no'
49+
}
50+
}
51+
52+
$1passwordStatus = Get-1PasswordIntegrationStatus
53+
Write-Host "1Password Intergration: $1passwordStatus"
54+
}
55+
Export-ModuleMember -Function Write-SysInfo

app/_HELP.txt

+1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ Commands:
2929
key load Loads your private key into the ssh-agent (so that it can be used
3030
by applications other than ssh-env)
3131

32+
sysinfo Displays various information about the system
3233
help, --help, -h Displays this help page
3334
version, --version, -v Prints the ssh-env and OpenSSH client version

0 commit comments

Comments
 (0)