From 4669a033ee4fbde5e3c2447778657a20a73d5df8 Mon Sep 17 00:00:00 2001 From: Matt Kotsenas Date: Wed, 1 Mar 2017 09:32:55 -0800 Subject: [PATCH] Update PowerShell alias to handle no history If history is cleared (or the shell is new and there is no history), invoking thefuck results in an error because the alias attempts to execute the usage string. The fix is to check if Get-History returns anything before invoking thefuck. --- thefuck/shells/powershell.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/thefuck/shells/powershell.py b/thefuck/shells/powershell.py index 8e5d994d..bf954bf3 100644 --- a/thefuck/shells/powershell.py +++ b/thefuck/shells/powershell.py @@ -3,11 +3,14 @@ from .generic import Generic class Powershell(Generic): def app_alias(self, fuck): - return 'function ' + fuck + ' { \n' \ - ' $fuck = $(thefuck (Get-History -Count 1).CommandLine);\n' \ - ' if (-not [string]::IsNullOrWhiteSpace($fuck)) {\n' \ - ' if ($fuck.StartsWith("echo")) { $fuck = $fuck.Substring(5); }\n' \ - ' else { iex "$fuck"; }\n' \ + return 'function ' + fuck + ' {\n' \ + ' $history = (Get-History -Count 1).CommandLine;\n' \ + ' if (-not [string]::IsNullOrWhiteSpace($history)) {\n' \ + ' $fuck = $(thefuck $history);\n' \ + ' if (-not [string]::IsNullOrWhiteSpace($fuck)) {\n' \ + ' if ($fuck.StartsWith("echo")) { $fuck = $fuck.Substring(5); }\n' \ + ' else { iex "$fuck"; }\n' \ + ' }\n' \ ' }\n' \ '}\n'