-
Notifications
You must be signed in to change notification settings - Fork 123
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
.bashrc equivalent? #51
Comments
I'm not sure what you're getting at: Are you trying to avoid writing Lua scripts? Are you asking for a second language to be added to Clink? |
I was looking for something like this: Currently I have a script in my home directory called init.cmd, which auto sets some aliases and variables at each shell startup. The location of this script has to be added to the Autorun variable of Command Processor in the Windows Registry. The script looks like this: @echo OFF
set WTSettings="C:\Users\RashilGandhi\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
set ClinkReadlineHistory="C:\Users\RashilGandhi\AppData\Local\clink\clink_history"
doskey arch=wsl -d arch-linux genie -s
doskey admin=sudo
doskey ls=dir
'
'
' and now this basically acts as a .bashrc for Windows CMD. I was basically asking if there was a way to do this through Clink at each injection. I'm not aware if doskeys and variables (that can be accessed in the shell itself) can be set through Lua scripts, if yes, could you tell me how? |
I think what you're asking about is really more of a shell feature, but Clink isn't a shell and isn't trying to be a shell. .bashrc is part of the Bash shell itself. CMD's equivalent is the AutoRun regkey. Clink runs Lua scripts, and you can do via Lua all of the things that .bashrc can do, you'd just go about it a little differently. Clink uses Readline, and so it already has a .inputrc file whose format is defined by Readline and shouldn't be extended because it would break compatibility with existing .inputrc files, etc. You can currently share them between Bash and Clink, because inputrc files are only about Readline, not about the shell. But you're asking for new shell features in CMD, and that heads into murky territory. Try using Lua first. There is a lot of Lua API documentation in clink.html, and a lot of public Lua documentation. What have you found so far from those? Something to know about me: I don't tend to just hand out answers when the questions are easy to answer without my help. In those cases I try to ask questions to spark critical thought. "Give a man a fish, feed him for a day; teach a man to fish, feed him for life." So, think about what it is you're trying to do, and what would be needed. Try searching for those things. If you've done that already, share what's been tried so far so that the respondent (me, in this case) doesn't have to guess at what's being done and try to predict what might have been missed. Try to make it inexpensive and easy for someone to respond. 🙂 One suggestion, though -- launching processes is expensive. Maybe instead of launching doskey once per alias, make use of its input file mechanism to load a bunch of aliases at once. P.S. This is also a good exercise to help ensure Clink has what it needs; if you run into problems that can't be solved or that have messy solutions, then that may reveal some spots where Clink can be enhanced (e.g. adding an |
I found the function Update: |
It's about how Doskey works, rather than about how popen works (and execute, etc).
(The details of how they communicate is public knowledge, but the point is we don't need to know that. We only need to know whether they do, and we can deduce that from observing that doskey.exe is a program rather than a command.) |
If that's the case, I can safely assume that neither Thanks for the info though; I learnt a cool thing about doskey.exe today! |
Correct! |
Thanks, I'll close this. |
If I'm understanding it correctly, the new |
I should mention that the reason I have come back to this 6 month old issue is because there are things that absolutely can't be done by Lua scripts (in the shell's context). I have a couple of examples to illustrate this:
FOR /f "tokens=*" %i IN ('fnm env --use-on-cd') DO CALL %i As you can see, this won't be possible to do in a Lua script.
The solution to both of these was just prepending the startup script name in the AutoRun registry key as follows:
This method isn't very reliable; I have found many instances where CMD shell just freezes in the presence of certain commands in the init.cmd (regardless of whether the I just wanted to say thanks for the |
More or less. I didn't originally explain the technical reasons why it's difficult/problematic to fulfill the request (I later explained them in #91). The only way Clink can "run" a command line in the current session is to give control back to CMD. So the only way Clink can "run a startup script" is to notice the first time CMD asks Clink to prompt the user, and instead don't prompt, return a hidden command as though the user had typed in the startup script/program/command name. When CMD eventually asks Clink to prompt for the next time, then Clink has to figure out whether the previous command it returned resulted in any output and reset the cursor position accordingly, then show a prompt. So what the user experiences as "the first prompt" is in reality the second prompt. I got tired of needing to explicitly specify a startup script, and decided to try an experiment to see how well the above might work in practice.
The issue wasn't about "why" it was desired (I expect the desire is nearly universal), the issue was about "how" to even accomplish it. Injection into a process with Detours has many limitations as far as what is possible to do.
Can you share an example of a script that causes CMD to freeze when it's included in the AutoRun regkey? The only reason I know of for that to happen is if the script waits on something (such as input another process, etc). If there are other things that can cause a freeze then it would be useful to know -- there might be other side effects that can affect Clink as well. |
Yes, I understood that from the discussion in #91.
So the way I can reproduce this is like this:
@echo OFF
bfetch where
@echo OFF
for /f "tokens=*" %%i in ('fnm env') do call %%i |
What is |
It's a bug in your script -- or rather, your script is causing an extremely expensive infinite loop and creating thousands of new cmd.exe processes as quickly as possible, when the script is invoked as part of launching cmd.exe. (Use TaskMgr or Process Explorer to see the processes.) Your script launches cmd.exe... So:
This type of syntax launches a new cmd.exe in order to run the command that the
Just like The reason it doesn't go into an infinite loop when used in |
set FNM_ENVIRONMENT=some\temp\path
set FNM_CONTEXT=some\other\path\
set FNM_SESSION_ID=somerandomnumber
set FNM_HOME=some\persistent\path
doskey cd=somefunctiontochangeversionondirectorychange These commands need to be run in order to set up the FNM environment. The paths here depend on session ID, which are different for each CMD session. |
Oohhhh, now it makes sense!!! This means that we should think twice before putting arbitrary shell commands in AutoRun batch scripts 😅
How do you detect interactive sessions? (In bash there is an automatic variable |
clink/clink/app/src/host/host_cmd.cpp Line 363 in 80dfad8
|
Is there a way to initialize some variables, aliases (doskeys), much like .bashrc or .zshrc or PowerShell's profile in Clink? They should run/get initialized every time Clink is injected.
Thanks!
The text was updated successfully, but these errors were encountered: