3 ms·
My only annoyance with fish is when I copy bash one liners and forget, and get errors or issues. Otherwise, fish is fantastic.
by giancarlostoro 2y ago
My only annoyance with fish is when I copy bash one liners and forget, and get errors or issues. Otherwise, fish is fantastic.
- porridgeraisin 2y agoThere'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 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` #! /usr/bin/env bash rm -f /tmp/bash_daemon_pipe /tmp/bash_daemon_out mkfifo /tmp/bash_daemon_pipe mkfifo /tmp/bash_daemon_out echo $$ > /tmp/bash_daemon.pid while true; do read cmd < /tmp/bash_daemon_pipe { eval "$cmd"; echo "###DONE###"; } > /tmp/bash_daemon_out done
- giancarlostoro 2y agoWow! This is fantastic! I will have to set this up ASAP.
- xk3 2y agoThis is nice! But you should probably use $XDG_RUNTIME_DIR or /run/user/1000 instead of /tmp