1- using Microsoft . VisualStudio . Shell ;
1+ using Microsoft . VisualStudio . Shell ;
22using System ;
33using System . Collections . Generic ;
44using System . ComponentModel ;
@@ -8,10 +8,52 @@ namespace MadsKristensen.OpenCommandLine
88{
99 internal class Options : DialogPage
1010 {
11- public static Dictionary < string , Command > DefaultPresets = new Dictionary < string , Command > ( ) ;
11+ private static Dictionary < string , Command > _defaultPresets ;
1212 private bool _isLoading , _isChanging ;
1313 private string _preset ;
1414
15+ public static Dictionary < string , Command > DefaultPresets
16+ {
17+ get
18+ {
19+ if ( _defaultPresets == null )
20+ {
21+ InitializePresets ( ) ;
22+ }
23+ return _defaultPresets ;
24+ }
25+ }
26+
27+ private static void InitializePresets ( )
28+ {
29+ _defaultPresets = new Dictionary < string , Command > ( ) ;
30+
31+ string installDir = VsHelpers . GetInstallDirectory ( ) ;
32+ string devPromptFile = installDir != null
33+ ? Path . Combine ( installDir , @"..\Tools\VsDevCmd.bat" )
34+ : "" ;
35+
36+ _defaultPresets [ "cmd" ] = new Command ( "cmd.exe" ) ;
37+ _defaultPresets [ "Dev Cmd Prompt" ] = new Command ( "cmd.exe" , "/k \" " + devPromptFile + "\" " ) ;
38+ _defaultPresets [ "PowerShellCore" ] = new Command ( "pwsh.exe" , "-ExecutionPolicy Bypass -NoExit" ) ;
39+ _defaultPresets [ "PowerShell" ] = new Command ( "powershell.exe" , "-ExecutionPolicy Bypass -NoExit" ) ;
40+ _defaultPresets [ "PowerShell ISE" ] = new Command ( "powershell_ise.exe" ) ;
41+ _defaultPresets [ "posh-git" ] = new Command ( "powershell.exe" , @"-ExecutionPolicy Bypass -NoExit -Command .(Resolve-Path ""$env:LOCALAPPDATA\GitHub\shell.ps1""); .(Resolve-Path ""$env:github_posh_git\profile.example.ps1"")" ) ;
42+ _defaultPresets [ "Git Bash" ] = new Command ( @"C:\Program Files\Git\git-bash.exe" ) ;
43+ _defaultPresets [ "Babun" ] = new Command ( @"%UserProfile%\.babun\cygwin\bin\mintty.exe" , "/bin/env CHERE_INVOKING=1 /bin/zsh.exe" ) ;
44+
45+ string GitHubForWindowsPath = Path . Combine ( Environment . GetEnvironmentVariable ( "LocalAppData" ) ?? "" , "GitHub" , "GitHub.appref-ms" ) ;
46+ if ( File . Exists ( GitHubForWindowsPath ) )
47+ {
48+ _defaultPresets [ "GitHub Console" ] = new Command ( @"%LOCALAPPDATA%\GitHub\GitHub.appref-ms" , "-open-shell" ) ;
49+ }
50+
51+ _defaultPresets [ "cmder" ] = new Command ( "cmder.exe" , "/START \" %folder%\" " ) ;
52+ _defaultPresets [ "ConEmu" ] = new Command ( "ConEmu64.exe" , "/cmd PowerShell.exe" ) ;
53+ _defaultPresets [ "Windows Terminal" ] = new Command ( "wt.exe" , "-d \" %folder%\" " ) ;
54+ _defaultPresets [ "Custom" ] = new Command ( string . Empty , string . Empty ) ;
55+ }
56+
1557 [ Category ( "Command Preset" ) ]
1658 [ DisplayName ( "Select preset" ) ]
1759 [ Description ( "Select one of the predefined command configurations" ) ]
@@ -114,32 +156,6 @@ public override void LoadSettingsFromStorage()
114156 Preset = "cmd" ;
115157 }
116158
117- if ( DefaultPresets . Count == 0 )
118- {
119- string installDir = VsHelpers . GetInstallDirectory ( ) ;
120- string devPromptFile = Path . Combine ( installDir , @"..\Tools\VsDevCmd.bat" ) ;
121-
122- DefaultPresets [ "cmd" ] = new Command ( "cmd.exe" ) ;
123- DefaultPresets [ "Dev Cmd Prompt" ] = new Command ( "cmd.exe" , "/k \" " + devPromptFile + "\" " ) ;
124- DefaultPresets [ "PowerShellCore" ] = new Command ( "pwsh.exe" , "-ExecutionPolicy Bypass -NoExit" ) ;
125- DefaultPresets [ "PowerShell" ] = new Command ( "powershell.exe" , "-ExecutionPolicy Bypass -NoExit" ) ;
126- DefaultPresets [ "PowerShell ISE" ] = new Command ( "powershell_ise.exe" ) ;
127- DefaultPresets [ "posh-git" ] = new Command ( "powershell.exe" , @"-ExecutionPolicy Bypass -NoExit -Command .(Resolve-Path ""$env:LOCALAPPDATA\GitHub\shell.ps1""); .(Resolve-Path ""$env:github_posh_git\profile.example.ps1"")" ) ;
128- DefaultPresets [ "Git Bash" ] = new Command ( @"C:\Program Files\Git\git-bash.exe" ) ;
129- DefaultPresets [ "Babun" ] = new Command ( @"%UserProfile%\.babun\cygwin\bin\mintty.exe" , "/bin/env CHERE_INVOKING=1 /bin/zsh.exe" ) ;
130-
131- string GitHubForWindowsPath = Path . Combine ( Environment . GetEnvironmentVariable ( "LocalAppData" ) , "GitHub" , "GitHub.appref-ms" ) ;
132- if ( File . Exists ( GitHubForWindowsPath ) )
133- {
134- DefaultPresets [ "GitHub Console" ] = new Command ( @"%LOCALAPPDATA%\GitHub\GitHub.appref-ms" , "-open-shell" ) ;
135- }
136-
137- DefaultPresets [ "cmder" ] = new Command ( "cmder.exe" , "/START \" %folder%\" " ) ;
138- DefaultPresets [ "ConEmu" ] = new Command ( "ConEmu64.exe" , "/cmd PowerShell.exe" ) ;
139- DefaultPresets [ "Windows Terminal" ] = new Command ( "wt" , "-d %folder%" ) ;
140- DefaultPresets [ "Custom" ] = new Command ( string . Empty , string . Empty ) ;
141- }
142-
143159 _isLoading = false ;
144160 }
145161
0 commit comments