Cmder: set ~ to home directory

Created on 21 Nov 2014  路  11Comments  路  Source: cmderdev/cmder

Maybe this is easy to do, but how do I set ~ to the current users home directory?

wontfix

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.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

All 11 comments

+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

IfWinActive ahk_class VirtualConsoleClass

::~::D:/nicolas

IfWinActive

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bmeverett picture bmeverett  路  3Comments

GlassGruber picture GlassGruber  路  3Comments

AaronKaa picture AaronKaa  路  3Comments

vincentntang picture vincentntang  路  3Comments

danwellman picture danwellman  路  3Comments