Skip to content

Commit

Permalink
Add CommandNotFoundAcion hook to give info on posh-sshell
Browse files Browse the repository at this point in the history
You can override this check by defining an env var: POSHGIT_NO_SSH_CHECK

Remove NoVersionWarn module param - no longer used.
Convert last module param to [bool] since [switch] doesn't really work.
  • Loading branch information
rkeithhill committed Oct 4, 2018
1 parent b819ed9 commit f109b22
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/posh-git.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
param([switch]$NoVersionWarn, [switch]$ForcePoshGitPrompt)
param([bool]$ForcePoshGitPrompt = $false)

& $PSScriptRoot\CheckRequirements.ps1 > $null

Expand All @@ -16,6 +16,26 @@ param([switch]$NoVersionWarn, [switch]$ForcePoshGitPrompt)
if (!$Env:HOME) { $Env:HOME = "$Env:HOMEDRIVE$Env:HOMEPATH" }
if (!$Env:HOME) { $Env:HOME = "$Env:USERPROFILE" }

# Check if posh-sshell not installed. If not, install CommandNotFoundAction handler to give info on installing posh-sshell
$prevCommandNotFoundActionHandler = $null
$commandNotFoundActionHandlerInstalled = $false
if (!$Env:POSHGIT_NO_SSH_CHECK -and !(Get-Module posh-sshell -ListAvailable)) {
$prevCommandNotFoundActionHandler = $ExecutionContext.InvokeCommand.CommandNotFoundAction
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param($commandName, $eventArgs)
if ($commandName -in "Get-SshAgent", "Start-SshAgent", "Stop-SshAgent", "Add-SshKey", "Get-SshPath") {
Write-Warning ("The posh-git SSH commands have been moved to the posh-sshell module. " +
"You can install posh-sshell by executing: Install-Module posh-sshell -Scope CurrentUser")
}

if ($prevCommandNotFoundActionHandler) {
return $prevCommandNotFoundActionHandler.Invoke($commandName, $eventArgs)
}
}

$commandNotFoundActionHandlerInstalled = $true
}

$IsAdmin = Test-Administrator

# Get the default prompt definition.
Expand Down Expand Up @@ -132,6 +152,10 @@ if ($ForcePoshGitPrompt -or !$currentPromptDef -or ($currentPromptDef -eq $defau
$ExecutionContext.SessionState.Module.OnRemove = {
$global:VcsPromptStatuses = $global:VcsPromptStatuses | Where-Object { $_ -ne $PoshGitVcsPrompt }

if ($commandNotFoundActionHandlerInstalled) {
$ExecutionContext.InvokeCommand.CommandNotFoundAction = $prevCommandNotFoundActionHandler
}

Reset-WindowTitle

# Check if the posh-git prompt function itself has been replaced. If so, do not restore the prompt function
Expand Down

0 comments on commit f109b22

Please sign in to comment.