chrisant996 / clink

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

clink_start.cmd is run twice when clink is installed in %localappdata%\clink #653

Closed hutcho closed 1 month ago

hutcho commented 1 month ago

clink_start.cmd gets executed twice if you have installed clink into %localappdata%\clink on Windows 10. I have tested the same steps below on different paths, and the issue only occurs when clink is installed at %localappdata%\clink.

Steps to reproduce:

  1. Download clink .zip and extract to %localappdata%\clink
  2. Install clink by running clink autorun install from the above folder
  3. Create a clink_start.cmd file e.g. echo doskey e = explorer $* > clink_start.cmd
  4. Close all command prompts, and start a new command prompt.

Result shown in terminal

<some text above>
https://github.com/chrisant996/clink

doskey e = explorer $*

doskey e = explorer $*

>

It is unexpected to see doskey e = explorer $* appear twice on terminal startup.

I noticed clink info shows 2 identical entries on the scripts line:

scripts: C:\Users\USERNAME\AppData\Local\clink ; C:\Users\USERNAME\AppData\Local\clink

But using clink set clink.path C:\Users\USERNAME\AppData\Local\clink does not stop the double running of the .cmd file.

chrisant996 commented 1 month ago

You've installed Clink into its own profile directory. That's not something that was considered as something that might ever be attempted. I guess I can understand why someone could choose to do that, though.

As an analogy, it's similar to installing Windows into C:\users\myname instead of C:\Windows.

The Startup Cmd Script documentation says:

When Clink is injected, it looks for a clink_start.cmd script in the binaries directory and profile directory. Clink automatically runs the script(s), if present, when the first CMD prompt is shown after Clink is injected and before any Lua scripts run. You can set the clink.autostart setting to run a different command, or set it to "nul" to run no command at all.

The program directory (the "binaries" directory) and the profile directory were meant to be separate directories. In your case, they're the same directory, so when Clink checks for clink_start.cmd in each of the directories, it finds one in each, and executes both of them.

I can make it check whether the two clink_start.cmd files are the same file, and if so then only run it once.

You're welcome to experiment with putting the binaries in the profile directory, but you might run into other strange quirks as well. It's not an intended or tested way of using Clink.

hutcho commented 1 month ago

Ah thankyou that makes sense if it's unsupported. Since the .zip is offered as a way to install clink, could there be a recommended path for installing it to like in your example, it's recommended to install windows to c:\Windows. What would be the default expected location for clink?

chrisant996 commented 1 month ago

Ah thankyou that makes sense if it's unsupported. Since the .zip is offered as a way to install clink, could there be a recommended path for installing it to like in your example, it's recommended to install windows to c:\Windows. What would be the default expected location for clink?

The difference is that we don't manually copy files out of a zip file to install Windows.

The Clink setup.exe installer is the recommended way to install the program, and it recommends installing to the place that Windows recommends programs be installed.

To me it feels presumptuous or insulting to recommend where to copy a program, if the user has already made the choice to avoid using an installer program.

(Windows doesn't recommend to manually install files into Program Files; that's something that typically only installer programs should do. And %LOCALAPPDATA% is intended for use by programs for storing data and settings, which is part of why it's a hidden folder. Nothing will block a user from peeking into it or putting things in it, though.)

hutcho commented 1 month ago

The problem with the Clink setup.exe installer is that it requires admin privileges, but the .zip doesn't. Therefore the choice to not use the installer will not always be a user choice if they dont have admin rights. They may wish they could use the installer but are forced to use the .zip. In this case, I think that specific user would appreciate guidance on an install location, and it wouldn't be an insult to them. We've already developed some guidelines here about where not to put it (e.g. not in %localappdata%/clink, and not in Program Files.)