3 ms·
Something I’ve been wanting to do but haven’t found a perfect solution for yet: storing the output of previous command in some variable by default. I use Termi
by tambourine_man 5y ago
Something I’ve been wanting to do but haven’t found a perfect solution for yet: storing the output of previous command in some variable by default.
I use Terminal.app’s Select Between Marks or tmux, but I wish this was a thing.
- quesera 5y agoYou can use: VAR=$(!!) to accomplish something similar. Not by default of course. It re-runs the command, so if not idempotent/etc it will not return expected results. Also when re-run, the command will not be in a tty context, so if the executable is sensitive to such things (e.g. `ls`), the output format might be different.
- tambourine_man 5y agoYeah, I know, but I don’t want to re-run and I want it by default.
- oh_sigh 5y agoYou could put that line in your PS1, I think?
- yakshaving_jgt 5y agoPerhaps you could change your prompt so that everything is wrapped with tee. Interesting rabbit hole to go down… https://unix.stackexchange.com/q/562018 https://unix.stackexchange.com/q/562018
- tambourine_man 5y agoI saw that too, but the amount of stuff that can go wrong is crazy. Thanks though
- kjellsbells 5y agomight be kludgey but i wonder if bash coproc would help, it basically can send stdout to a named pipe that makes it avail as a environment variable fike descriptor.
- ttyprintk 5y agoSince bash can only handle one coproc at a time, using it behind the scenes blocks that function interactively.
- ttyprintk 5y agoOops, that’s not true for v5. Sorry
- tambourine_man 5y agoThat's interesting, but wouldn't work on an SSH session, I guess
- arccy 5y agokitty can do this with shell integration https://sw.kovidgoyal.net/kitty/shell-integration/ https://sw.kovidgoyal.net/kitty/shell-integration/