-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
integration with clink #941
Comments
As the problem is specific to Windows (more specifically to the old CMD.exe), I'd like a Windows user to investigate this. But I'm affraid that if clink uses the old CMD, which doesn't support terminal functions, then it won't support broot (or any TUI). |
no, clink works fine in WT |
I wanted to have it working some time ago, had to use a temporary file, don't even remember what it does but it works, and I've been using it since then... Here's what I have in local function onfilterinput(text)
args = string.explode(text, ' ', '"')
if #args == 0 then
return
end
if args[1] == "br" then
local command
local tmpoutfile_name = os.tmpname()
local tmpoutfile = io.open(tmpoutfile_name, 'w+')
tmpoutfile:close()
table.remove(args, 1)
br_args = table.concat(args, ' ')
local br_command = string.format('broot --outcmd "%s" %s', tmpoutfile_name, br_args)
local broot_out_file = io.popen(br_command, 'r')
local broot_out = broot_out_file:read('*all')
broot_out_file:close()
tmpoutfile = io.open(tmpoutfile_name, 'r')
local cd_command = tmpoutfile:read('*all')
tmpoutfile:close()
os.remove(tmpoutfile_name)
return cd_command
else
return
end
end
if clink.onfilterinput then
clink.onfilterinput(onfilterinput)
else
clink.onendedit(onfilterinput)
end
clink.argmatcher("br"):addarg(clink.dirmatches) Lmk if it helps, would be glad to have it made clean by someone who knows how all this works 😄 |
CMD is a shell, not a terminal. Windows 10 and newer have terminal support built in. And Clink happens to include a terminal emulator for when it runs on Windows 8.1 and older. |
The lua script I use and have shared above was just me trying to port the broot bash function to clink's lua, I made it in lua with clink tools because I didn't want to try scripting this in batch like it has been done for Powershell, because well...it's batch, and I thought it'd be more comfortable to write in lua, also to have clink highlighting it and have completion support for it. It might be possible to write the equivalent of what I did in lua in pure batch just for the As you said CMD is a shell and not a terminal, |
@oletf the Lua script is very readable, and it looks pretty clean (both from a Lua perspective and from a Clink perspective). Two minor suggestions:
- args = string.explode(text, ' ', '"')
+ local args = string.explode(text, ' ', '"')
return cd_command
- else
- return
end
end Input filtering in Clink can let simple cases work, but not the following kinds of usage:
On Win8.1 and lower, things like ConEmu or AnsiCon could be used to add terminal support into Windows consoles.
It looks pretty straightforward. Redirect output from broot to a tempfile (the hardest part is just picking a unique tempfile name in batch), then use (I don't know what broot actually does, but from context I gather maybe it's a tool for changing the current directory, similar to z or zoxide or cddeluxe and etc.) |
It's a TUI file explorer, command launcher, etc. and one of its features is that indeed it lets you change the current directory, which involves calling (see https://dystroy.org/broot/ if interested) |
@Canop Thanks. It looks like the only integration needed for use in cmd.exe is a br.cmd@echo off
echo.>broot.tmp.cmd
broot --outcmd tmpfile.cmd %*
if not errorlevel 1 call broot.tmp.cmd Except that something needs to be done to make a unique temp file name, so that multiple concurrent broot don't stomp on each other. One way to accomplish that could be to call PowerShell to get the cmd.exe parent process ID (and maybe append powershell -NoProfile -Command "(Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=`'$pid`'").ParentProcessId" Credit: lit in answer on stack overflow. Caution I'm leaving out basic stuff: for example, of course add The issue about terminal support isn't related to cmd -- it's instead related to what version of Windows is used. PowerShell and bash and etc have the same limitation as cmd when run in a legacy console (i.e. terminal) on Windows 8.1 or earlier. Mintty or ConEmu or AnsiCon are a few ways to have support for ANSI escape codes (i.e. "terminal support") on Windows 8.1 or earlier. |
I already asked the neighbors, but they sent me to you :)
How can I make broot work in cmd+clink ?
The text was updated successfully, but these errors were encountered: