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

[Feature request] Use pushd for "Directory shortcuts" #333

Closed
pukkandan opened this issue Aug 14, 2022 · 8 comments
Closed

[Feature request] Use pushd for "Directory shortcuts" #333

pukkandan opened this issue Aug 14, 2022 · 8 comments
Labels
enhancement New feature or request question Question about something

Comments

@pukkandan
Copy link

pukkandan commented Aug 14, 2022

As far as I know, Clink's Directory shortcuts are not currently configurable. I prefer to use pushd/popd instead of cd /d for directory navigation. Would it be possible to implement this?

Even better if you can make this customizable so that custom batch files can be used

@chrisant996
Copy link
Owner

How about using clink.onfilterinput() to replace cd /d usage with pushd?

@pukkandan
Copy link
Author

Just to clarify, this is what I am talking about
image

The cd here is sent by clink internally, not typed by me. I didn't think onfilterinput will get the full command line in this case. Does it? If so, that would be acceptable solution.

Technically, this would mean I can never intentionally send a cd /d, but that's fine. If I really need to, there's always chdir

@chrisant996
Copy link
Owner

intercept_directory() happens before onfilterinput:

if (ret && !resolved)
{
// If the line is a directory, rewrite the line to invoke the CD command
// to change to the directory.
intercepted = intercept_directory(out.c_str(), &out, true/*only_cd_chdir*/);
if (intercepted != intercept_result::none)
{
if (intercepted == intercept_result::prev_dir)
prev_dir_history(out);
resolved = true; // Don't test for a doskey alias.
}
}
#ifdef DEBUG
const bool was_signaled = clink_is_signaled();
#endif
if (send_event)
{
lua_state& state = lua;
lua_pushlstring(state.get_state(), out.c_str(), out.length());
lua.send_event("onendedit", 1);
}
std::list<str_moveable> more_out;
if (send_event)
lua.send_event_cancelable_string_inout("onfilterinput", out.c_str(), out, &more_out);

(It also happens after onfilterinput, in case something filters the input to turn it into a directory shortcut.)

Directory shortcuts are translated into:

 cd /d "directory"

Note the leading space.

So you could still use cd /d blah, without a leading space.
Or even cd /d blah, without quotes.

@pukkandan
Copy link
Author

ah, nice. I should be able to implement this. Thanks as always

@chrisant996
Copy link
Owner

chrisant996 commented Aug 14, 2022

Cool. If something more sophisticated or simpler to configure is needed, then I can look into making some kind of change. But if a change isn't needed then I'd lean towards using the existing mechanisms.

@chrisant996 chrisant996 added enhancement New feature or request question Question about something labels Dec 18, 2022
@chrisant996
Copy link
Owner

Hi @pukkandan, your custom script will need to be updated:

Issues #569 and #570 are about failures in Clink when command extensions are disabled.
cd /d requires command extensions, so Clink needs to avoid using cd /d.

So, places that previously used cd /d dir now use cd dir, or X: & cd dir if the drive needs to change as well.

@pukkandan
Copy link
Author

Thanks for the heads up.

The space at the start is still present, right? If so, I just need to adjust my regex. No big deal

@chrisant996
Copy link
Owner

The space at the start is still present, right? If so, I just need to adjust my regex. No big deal

Yup, two kinds of commands possible now, and both still start with a space:

  • X: & cd somedir
  • cd somedir

Also, some .lua scripts may use 2 leading spaces. E.g. cwdhistory.lua, and there are others as well. And fzf.lua's luafunc:fzf_directory command uses no leading spaces (and it already didn't), but it's intentionally inserting a command into the input line as though it was typed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Question about something
Projects
None yet
Development

No branches or pull requests

2 participants