chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.45k stars 135 forks source link

Question: Expanding environment variables during auto complete #604

Closed DRSDavidSoft closed 4 months ago

DRSDavidSoft commented 4 months ago

Hi there, sorry to bother you, I have a quick question regarding env variables when using auto-complete (either Tab or Ctrl-Space)

I was under the assumption that if I entered something like cd %some_var%\ and hit tab, I could access the sub folders of that path. For example:

C:\Users\David
λ cd %cmder_root%\

If I press tab, nothing happens.

Clink is updated to the latest version and the env var is defined:

C:\Users\David
λ clink update
Checking latest version...
Downloading latest release v1.6.13...
Expanding zip file...

Updated Clink to v1.6.13.

To view the release notes, visit the Releases page:
  https://github.com/chrisant996/clink/releases
C:\Users\David
λ set cmder_root
CMDER_ROOT=C:\development\cmder\vendor\bin\..\..

I'm sorry if this is a duplicate question but I didn't quite find what I was looking for. Is this a supported feature? If not, is it possible to add something like this?

P.S. Also as sidenote, is it possible to reload clink in Cmder after I have changed some configurations, without closing and launching a new shell?

Thank you Chris!

chrisant996 commented 4 months ago

You're thinking of https://chrisant996.github.io/clink/clink.html#match_expand_envvars.

chrisant996 commented 4 months ago

is it possible to reload clink in Cmder after I have changed some configurations, without closing and launching a new shell?

It depends entirely on what you mean by "changed some configurations". Can you elaborate?

DRSDavidSoft commented 4 months ago

@chrisant996 Thanks for the help! A bit embarrassing that it didn't occur to me to RTFM, surely with a more thorough search I would have found it.

As for reloading the changes, I was wondering if it's possible to do something like this to change prompt variables:

nano %cmder_root%\config\cmder_prompt_config.lua

Which changes the prompt in Clink (as it's used by clink.lua). Essentially, now I need to reload the .lua files and re-assign the clink.prompt.value value.

One more off-topic question (I'm super-sorry for being lazy to read the docs) but is there a way to disable the hints that are shown at the end of the prompt such as "Right=Accept Suggestion")?

chrisant996 commented 4 months ago

Refer to docs,

DRSDavidSoft commented 4 months ago

Thanks again!

DRSDavidSoft commented 4 months ago

@chrisant996 Is it possible to trigger clink-reload without pressing a key, i.e. something like clink run-command clink-reload?

chrisant996 commented 3 months ago

@chrisant996 Is it possible to trigger clink-reload without pressing a key, i.e. something like clink run-command clink-reload?

No. While running a program, e.g. dir or git or clink whatever, there is no input line. When there's no input line, there's no way to run input line commands.

If you frequently run nano %cmder_root%\config\cmder_prompt_config.lua and want to force resetting the Lua engine afterwards (but what if you don't make any changes?) then why not make a key binding to handle it all? That would save you lots of typing, and also automatically forcibly reset the Lua engine.

E.g. in a file somescript.lua:

function nano_cmder_prompt_config()
    os.execute(`nano %cmder_root%\config\cmder_prompt_config.lua`)
    clink.reload()
end

rl.describemacro("luafunc:nano_cmder_prompt_config", "Use nano to edit cmder_prompt_config.lua, and reset the Lua engine afterwards")

E.g. in your .inputrc file:

"\en":    "luafunc:nano_cmder_prompt_config"    # Alt-N to edit cmder prompt config and reload Lua.

See Customizing Key Bindings for details on key bindings and how to find what input string is produced by different key combinations.

DRSDavidSoft commented 3 months ago

@chrisant996 That's an excellent suggestion, actually!

Of course, I'm more looking into ways to provide easy access for Cmder users to customize their clink shell, so adding a binding like this would be an awesome way to quickly re-configure their prompt.

I also added match.expand_envvars to Cmder's default configuration: https://github.com/cmderdev/cmder/commit/c9b77f618a9314d56bb0572d7209c1d02f0e593e

My original misunderstanding is that I wasn't aware of the "Enhanced default settings" by Clink, since I've never directly installed Clink without Cmder. I'll be reading the documentation more carefully now since I would like to add more of the cool Clink features to my own setup, and maybe as well as Cmder's default clink settings.

Thanks for all these wonderful features!

chrisant996 commented 3 months ago

P.S. Alt-N was just an example (a mnemonic for "nano"). It would be best to find a key that isn't already bound to something. Maybe some Ctrl-FN key combination.