Maybe this is easy to do, but how do I set ~ to the current users home directory?
+1
alias ~=cd /d ^%USERPROFILE^% will help you :)
@MartiUK IMHO this can be included in default aliases.
It would be amazing if ~ could be used as a variable.
I think here is two options. First is set ~=%USERPROFILE% and something like cd %~%\Documents will work then, but you will have to wrap tilda into %% always. Not sure that this will be valuable.
Second recipe is to place home.lua file with following content
local function tilde_match (text, f, l)
if text == '~' then
clink.add_match(clink.get_env('userprofile'))
clink.matches_are_files()
return true
end
end
clink.register_match_generator(tilde_match, 1)
to Cmder's config directory. This will add ~ -> %USERPROFILE% expansion after {TAB} key press
A last option is to use AutoHotkey
::~::D:/nicolas
This will replace ~ by whatever you want, as soon as you type anotther character ('/' or Enter):
cd ~
user type '/', it becomes
cd D:/nicolas/
Note that it's working all the time in ConEmu, meaning it would work even if you ssh into another machine (whic seems plain wrong - I usually stop AutoHotKey aat this point)
Unfortunately all of these workarounds is just a surrogates and can't provide Bash-like ~ replacement.
This will never happen, I suggest using PowerShell in cmder if you desperately want ~ aliased.
@vladimir-kotikov Thank you for the home.lua recipe - it's exactly what I needed!
Works beautifully, thanks so much!
Sorry to revive this old issue, but I've written a small batch script that exactly handles this, and I think it's a better solution rather than aliasing ~ itself.
If anyone comes along in the future, please have a look here:
https://github.com/cmderdev/cmder/issues/1051#issuecomment-702983948
Most helpful comment
I think here is two options. First is
set ~=%USERPROFILE%and something like cd %~%\Documents will work then, but you will have to wrap tilda into%%always. Not sure that this will be valuable.Second recipe is to place
home.luafile with following contentto Cmder's
configdirectory. This will add~ -> %USERPROFILE%expansion after {TAB} key press