There's a nice way to halfway-fix that issue. It makes use of the fact that most bash commands that we copy are prefixed with a $ and a space. It also requires your terminal emulator to have a way to hook into the paste mechanism and edit the to-be-pasted text. To my knowledge, Kitty and iTerm both have this feature.
Basically, the terminal will replace each line of the pasted text that match (start with)
$ rest
with
pbash 'rest_escaped'
or more elegantly
\$ 'rest_escaped'
We will then define a function with either of these names in fish.
This function will start (if not exists) a persistent background bash instance connected on both ends to FIFOs, with the same lifetime as your fish session. We then pass the `rest_escaped` to one FIFO, capture the output from the other FIFO, and echo it.
Because its a persistent session, stuff you copy that makes use of variables or bash aliases all Just Work. Being able to blindly copy-paste the entire bash codefence from a github readme.md is especially nice.
It all happens automatically after a one-time setup, and overall works pretty well for me. Here is a demo: https://i.imgur.com/HdqGkRk.png
This is the fish function
function \$
if not test -f /tmp/bash_daemon.pid; or not kill -0 (cat /tmp/bash_daemon.pid) 2>/dev/null
echo "Starting bash daemon..."
bash ~/scripts/bash_daemon.sh &
sleep 0.5
end
echo "$argv" > /tmp/bash_daemon_pipe &
while read -l line
if test "$line" = "###DONE###"
break
end
echo $line
end < /tmp/bash_daemon_out
end
And this is the bash script `~/scripts/bash_daemon.sh`
Basically, the terminal will replace each line of the pasted text that match (start with)
with or more elegantly We will then define a function with either of these names in fish.This function will start (if not exists) a persistent background bash instance connected on both ends to FIFOs, with the same lifetime as your fish session. We then pass the `rest_escaped` to one FIFO, capture the output from the other FIFO, and echo it.
Because its a persistent session, stuff you copy that makes use of variables or bash aliases all Just Work. Being able to blindly copy-paste the entire bash codefence from a github readme.md is especially nice.
It all happens automatically after a one-time setup, and overall works pretty well for me. Here is a demo: https://i.imgur.com/HdqGkRk.png
This is the fish function
And this is the bash script `~/scripts/bash_daemon.sh`