-
Notifications
You must be signed in to change notification settings - Fork 2k
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
~ doesn't work in cmder? #1051
Comments
Does it work if you don't use the ' I have Alt-~ mapped to tidle-expand for cases like this. (I believe that is a default setting -- use Alt-h from the shell to list key bindings). |
I just tried So this is an issue of |
|
Try using PowerShell. |
So to clarify: Cmder does not interpret shell arguments (like '~'). If the underlying shell is cmd.exe then tilde is not supported in paths. If the underlying shell is PowerShell or Bash it will work. If you want to use a cmd.exe shell, then one thing you can do is expand the tilde before executing the command. This is supported via tilde-expand, which is mapped to Alt-~ by default. For example:
before hitting Enter here, you can hit Alt-~, which results in something like:
Cmder provides a bunch of (configurable) key bindings like this. Try Alt-h to see what is available. |
I use 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) in |
@JanSchulz Ah, that's handy! Based on your example I'm using the following to handle any path that starts with tilde: local function tilde_match (text, f, l)
if text == '~' then
clink.add_match(clink.get_env('home'))
clink.matches_are_files()
return true
end
if text:sub(1, 1) == '~' then
clink.add_match(string.gsub(text, "~", clink.get_env('home'), 1))
-- second match prevents adding a space so we can look for more matches
clink.add_match(string.gsub(text, "~", clink.get_env('home'), 1) .. '+')
clink.matches_are_files()
return true
end
end The one funny thing is the second bogus match to prevent a space being added, since the path may not actually be complete just by replacing the ~. For example:
|
i had to change the 3 for other's coming here for clink only, just tack this (along with the |
I put "tilde_match" function in cmderroot\config\tilde.lua but it's not work for me. I tried:
But nothing. I also tried to insert the function into cmderroot\vendor\clink.lua at the end, but it still not working. |
Just tested this with latest cmder master branch build that re-enables loading user lua files and it works. I added a local function tilde_match (text, f, l)
if text == '~' then
clink.add_match(clink.get_env('home'))
clink.matches_are_files()
return true
end
if text:sub(1, 1) == '~' then
clink.add_match(string.gsub(text, "~", clink.get_env('home'), 1))
-- second match prevents adding a space so we can look for more matches
clink.add_match(string.gsub(text, "~", clink.get_env('home'), 1) .. '+')
clink.matches_are_files()
return true
end
end
clink.register_match_generator(tilde_match, 1) Started an new
Update: Using recent clink versions (1.1.8 and up, since 2020) this script is no longer necessary as clink now supports this natively. For more information, please refer to the link below: ~DRSDavidSoft |
Personally, I went the other way and wrote a small batch script to handle @if "%~1"=="/?" (@cd %*)
@set excd=%*
@set excd=%excd:"=%
@if "%excd:~0,1%"=="~" (@set excd=%userprofile%\%excd:~1%)
@if not "%~1"=="/d" (@set excd_param="/d") else (@set excd_param=)
@cd %excd_param% "%excd%" You can save this as
Now you can alias it to alias cd=excd $* Or, if the alias cd=%cmder_root%\config\excd.cmd $* Results:It's so satisfying to use! Using this approach allows you to Note: As stated in the comment above, the tab completion using tilde has arrived in clink so you no longer need to use the provided lua scripts. |
Very nice. Maybe it should be included in |
@daxgames Thanks, I was going to make a pull request, but I thought I'd ask people to try it first. If it's alright, I'll open a PR in the next days :) |
Veally slick—Cmder is great! Just wanted to share in case you haven't tried it yet: the new Microsoft Terminal with PowerShell (Pwsh) is also worth checking out. It supports tilde paths, allows UNC paths as the current directory, and, you haven't lived until you've seen color emojis in your Windows' terminal. Definitely a game-changer for Windows users! 😄 |
I'm pretty sure
Untitled.png
exists, but I cannot remove it through therm
command.The text was updated successfully, but these errors were encountered: