-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
Is it possible to include double quotes in the cmd
argument?
#508
Comments
Got it working using this code: open_in_terminal = function(state)
local node = state.tree:get_node()
local path = node:get_id()
path = path:gsub(" ", "\\ ")
local the_cmd = string.format([[1TermExec cmd="cd %s"]], path)
vim.cmd(the_cmd)
print("Opening terminal in " .. tostring(path))
end, |
I'm looking for a solution to a broader problem, namely I want to execute the currently opened file in terminal: |
Can't you just surround the filename in quotes? |
No, that won't work for cases when The best way to escape would be to wrap the whole name in |
Oh, duh. Here's my code to run the current file as a Python script. I don't specially handle anything but spaces, but hopefully this is a useful starting point. I wasn't aware of the local function run_python()
vim.cmd.write()
print("Running...")
local script_path = vim.fn.expand("%:p"):gsub(" ", "\\ ")
local command = "python \"" .. script_path .. "\""
toggleterm.exec(command)
end Note that this (being Lua) would need to be in your nvim config and assigned a keymap. |
|
|
I run Windows, and due to organizational constraints I'm forced to have spaces in my directories. I frequently want to execute the open Python file with
TermExec cmd="python %"
. As you can imagine, this causes issues if%
expands to a path with a space, as you get e.g.:I've tried every which way to escape quotes, mixing single and double quotes, escaping spaces with backslashes/backticks, etc., but I'm getting nowhere. Using the
dir
argument toTermExec
works if the terminal is not open yet, but it will not change the working directory if there's an open terminal already.Thoughts?
The text was updated successfully, but these errors were encountered: