Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set ~ to home directory #327

Closed
jebaird opened this issue Nov 20, 2014 · 11 comments
Closed

set ~ to home directory #327

jebaird opened this issue Nov 20, 2014 · 11 comments
Assignees

Comments

@jebaird
Copy link

jebaird commented Nov 20, 2014

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

@kirkouimet
Copy link

+1

@vladimir-kotikov
Copy link
Contributor

alias ~=cd /d ^%USERPROFILE^% will help you :)

@vladimir-kotikov
Copy link
Contributor

@MartiUK IMHO this can be included in default aliases.

@gustavohenke
Copy link

It would be amazing if ~ could be used as a variable.

@vladimir-kotikov
Copy link
Contributor

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

@narnaud
Copy link
Contributor

narnaud commented Jan 11, 2015

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)

@vladimir-kotikov
Copy link
Contributor

Unfortunately all of these workarounds is just a surrogates and can't provide Bash-like ~ replacement.

@MartiUK
Copy link
Member

MartiUK commented Jan 12, 2015

This will never happen, I suggest using PowerShell in cmder if you desperately want ~ aliased.

@nonbeing
Copy link

nonbeing commented Oct 3, 2015

@vladimir-kotikov Thank you for the home.lua recipe - it's exactly what I needed!

@azuria-sky
Copy link

Works beautifully, thanks so much!

@DRSDavidSoft
Copy link
Contributor

DRSDavidSoft commented Oct 2, 2020

I wrote 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:
#1051 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants