mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-14 07:29:12 +08:00
Enhance cmder start directory.
The start directory of cmder is defined in that order: 1. The directory passed as parameter to the cmder executable 2. The `CMDER_START` environment variable 3. The `HOME` environment variable 4. The current user directory (`USERPROFILE` environment variable) This commit also fix two issues: * stating cmder with a path in parameter would set CMDER_START (whereas it may just be temporary) * fix new line in cmd when starting cmder (this one was buggin me)
This commit is contained in:
parent
17b4525e60
commit
e9300ca43f
@ -33,6 +33,15 @@ In a file explorer window right click in or on a directory to see "Cmder Here" i
|
||||
|
||||
*If you get a message "Access Denied" ensure you are executing the command in an Administrator prompt.
|
||||
|
||||
### Start directory
|
||||
|
||||
The start directory of cmder is defined in that order (if one is empty, then the next one is used):
|
||||
|
||||
1. The directory passed as parameter to the cmder executable
|
||||
2. The `CMDER_START` environment variable
|
||||
3. The `HOME` environment variable
|
||||
4. The current user directory (`USERPROFILE` environment variable)
|
||||
|
||||
## Keyboard shortcuts
|
||||
|
||||
### Tab manipulation
|
||||
|
@ -487,28 +487,20 @@
|
||||
<value name="Count" type="dword" data="00000002"/>
|
||||
<key name="Task1" modified="2014-01-21 18:36:36" build="131215">
|
||||
<value name="Name" type="string" data="{cmd}"/>
|
||||
<value name="GuiArgs" type="string" data="/icon "%CMDER_ROOT%\cmder.exe""/>
|
||||
<value name="Cmd1" type="string" data="cmd /k "%ConEmuDir%\..\init.bat" -new_console:d:%USERPROFILE%"/>
|
||||
<value name="GuiArgs" type="string" data="/dir %CMDER_SESSION_START% /icon "%CMDER_ROOT%\cmder.exe""/>
|
||||
<value name="Cmd1" type="string" data="cmd /k "%ConEmuDir%\..\init.bat""/>
|
||||
<value name="Active" type="dword" data="00000000"/>
|
||||
<value name="Count" type="dword" data="00000001"/>
|
||||
<value name="Hotkey" type="dword" data="00000000"/>
|
||||
</key>
|
||||
<key name="Task2" modified="2014-01-21 18:36:36" build="131215">
|
||||
<value name="Name" type="string" data="{PowerShell}"/>
|
||||
<value name="GuiArgs" type="string" data="/icon "%CMDER_ROOT%\cmder.exe""/>
|
||||
<value name="Cmd1" type="string" data="PowerShell -NoLogo -NoProfile -NoExit -Command "Invoke-Expression '. ''%ConEmuDir%\..\profile.ps1'''" -new_console:d:"%USERPROFILE%""/>
|
||||
<value name="GuiArgs" type="string" data="/dir %CMDER_SESSION_START% /icon "%CMDER_ROOT%\cmder.exe""/>
|
||||
<value name="Cmd1" type="string" data="PowerShell -NoLogo -NoProfile -NoExit -Command "Invoke-Expression '. ''%ConEmuDir%\..\profile.ps1'''""/>
|
||||
<value name="Active" type="dword" data="00000000"/>
|
||||
<value name="Count" type="dword" data="00000001"/>
|
||||
<value name="Hotkey" type="dword" data="00000000"/>
|
||||
</key>
|
||||
<key name="Task3" modified="2014-09-17 09:17:41" build="140903">
|
||||
<value name="Name" type="string" data="{PowerShell as Admin}"/>
|
||||
<value name="Hotkey" type="dword" data="00000000"/>
|
||||
<value name="GuiArgs" type="string" data="/icon "%CMDER_ROOT%\cmder.exe""/>
|
||||
<value name="Cmd1" type="string" data="* PowerShell -NoLogo -NoProfile -NoExit -Command "Invoke-Expression '. ''%ConEmuDir%\..\custom.ps1''' " -new_console:d:"%USERPROFILE%""/>
|
||||
<value name="Active" type="dword" data="00000000"/>
|
||||
<value name="Count" type="dword" data="00000001"/>
|
||||
</key>
|
||||
</key>
|
||||
<key name="Apps" modified="2014-01-21 18:36:36" build="131215">
|
||||
<value name="Count" type="dword" data="00000000"/>
|
||||
|
@ -79,6 +79,33 @@ optpair GetOption()
|
||||
return pair;
|
||||
}
|
||||
|
||||
void ComputeStartDirectory(std::wstring path)
|
||||
{
|
||||
if (path.empty()) {
|
||||
wchar_t buffer[MAX_PATH];
|
||||
if (GetEnvironmentVariable(L"CMDER_START", buffer, MAX_PATH))
|
||||
{
|
||||
SetEnvironmentVariable(L"CMDER_SESSION_START", buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetEnvironmentVariable(L"HOME", buffer, MAX_PATH))
|
||||
{
|
||||
SetEnvironmentVariable(L"CMDER_SESSION_START", buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetEnvironmentVariable(L"USERPROFILE", buffer, MAX_PATH);
|
||||
SetEnvironmentVariable(L"CMDER_SESSION_START", buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetEnvironmentVariable(L"CMDER_SESSION_START", path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void StartCmder(std::wstring path, bool is_single_mode)
|
||||
{
|
||||
#if USE_TASKBAR_API
|
||||
@ -112,7 +139,7 @@ void StartCmder(std::wstring path, bool is_single_mode)
|
||||
}
|
||||
|
||||
SetEnvironmentVariable(L"CMDER_ROOT", exeDir);
|
||||
SetEnvironmentVariable(L"CMDER_START", path.c_str());
|
||||
ComputeStartDirectory(path);
|
||||
|
||||
STARTUPINFO si = { 0 };
|
||||
si.cb = sizeof(STARTUPINFO);
|
||||
|
8
vendor/init.bat
vendored
8
vendor/init.bat
vendored
@ -37,12 +37,4 @@
|
||||
:: Set home path
|
||||
@if not defined HOME set HOME=%USERPROFILE%
|
||||
|
||||
@if defined CMDER_START (
|
||||
@cd /d "%CMDER_START%"
|
||||
) else (
|
||||
@if "%CD%\" == "%CMDER_ROOT%" (
|
||||
@cd /d "%HOME%"
|
||||
)
|
||||
)
|
||||
|
||||
:: @call "%CMDER_ROOT%/bin/agent.cmd"
|
||||
|
7
vendor/profile.ps1
vendored
7
vendor/profile.ps1
vendored
@ -30,10 +30,3 @@ if (Get-Module posh-git) {
|
||||
Enable-GitColors
|
||||
Start-SshAgent -Quiet
|
||||
}
|
||||
|
||||
# Move to the wanted location
|
||||
if (Test-Path Env:\CMDER_START) {
|
||||
Set-Location -Path $Env:CMDER_START
|
||||
} elseif ($Env:CMDER_ROOT -and $Env:CMDER_ROOT.StartsWith($pwd)) {
|
||||
Set-Location -Path $Env:USERPROFILE
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user