Prevent bash from interpeting {+} in python script? #4293
-
Hello, I have a python program that calls another python module to open selected files in Neovim, each in a new tab with the cursor at the correct line. I am aware of the fzf.vim plugin. However, I prefer using my own handler, neovim_fzf_handler since this is a standalone program. The issue is that Bash interprets {+} as commands instead of treating it as raw input. How can I prevent this? I also tried using awk instead of my module but had no success. #...
for query, result in search_results:
print_heading(query)
# Complexity O(N^2) 2 loops is only for testing when config.query = ["q1", "q2"]
for res in result:
fzf_input.append(f"{res['file']}:{res['line_number']}:1 (hello)")
try:
# Run fzf with bat as a previewer, remove user env FZF_DEFAULT_OPTS
fzf_command = [
"env", "FZF_DEFAULT_OPTS=",
"fzf",
# "bat --style=numbers,changes --color=always --highlight-line {2} {1}",
"--border",
"--delimiter=:",
"--height=100%",
"--ansi",
"--multi",
"--exact",
"--pointer=👉",
"--marker=✅",
"--reverse",
"--cycle",
"--preview=bat {1} --highlight-line {2} --color=always --style=numbers",
f"--header=[ tab: select ] [ ctrl-v: open nvim tabs ] [ ctrl-q: exit ] [ query: {query} ] ",
"--preview-window=up,65%,border-bottom,+{2}+3/3,~3",
"--bind",
'''ctrl-v:become(PYTHONPATH=src:$PYTHONPATH python3 -c "import sys; from neovim_fzf_handler import process_fzf_selection; process_fzf_selection(' '.join(sys.argv[1:]))" {+} >/dev/tty 2>/dev/tty)''',
"--bind",
"ctrl-o:execute(nvim {1} +{2})",
]
fzf_process = subprocess.Popen(
fzf_command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
selected, error = fzf_process.communicate(input="\n".join(fzf_input))
#... These are the lines of interest. Here i purposely insert (hello) to debug bash. fzf_input.append(f"{res['file']}:{res['line_number']}:1 (hello)")
'''ctrl-v:become(IFS=_ PYTHONPATH=src:$PYTHONPATH python3 -c "import sys; from neovim_fzf_handler import process_fzf_selection; process_fzf_selection(' '.join(sys.argv[1:]))" {+} >/dev/tty 2>/dev/tty)''', The selection usually looks like "/path/file.txt:1:1 random text here /path/file2.txt:1:1 random text here". nvim -p \
"file1.md" \
"file2.md" \
"file3.md" \
-c "tabnext 1 | call cursor(53,1)" \
-c "tabnext 2 | call cursor(11,1)" \
-c "tabnext 3 | call cursor(10,1)" \
-c "tabnext 1" Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I don't understand. What do you mean by "command"s? |
Beta Was this translation helpful? Give feedback.
I think the problem is in my module after fzf has processed the input. Ended up writing some code to properly escape the command builder for neovim. Thanks for all the great work these years.