There is a codeblock I copy from a personal handbook .txt
file. I paste it in the terminal and execute by hitting Enter (Return). Recently I indented it there from aesthetic reasons but when I copy it indented the execution breaks (a secondary prompt is opened). To deal with this phenomenon I thought of using a FIFO.
I try make a FIFO to which I pass the following codeblock:
⇨⇨⇨⇨(
⇨⇨⇨⇨Indented commands...
⇨⇨⇨⇨)
The FIFO should remove all leading whitespaces (usually tabulations but maybe also spaces) from this original codeblock, and return a unindented version of it:
(
commands...
)
As far as I understand, the code I should put in the FIFO file is 's/^\s*//g'
.
My question:
When I paste the code block to a Bash terminal, how could I make it effected by the FIFO file I created, before I execute it?
Update:
This is the full syntax I tested. It failed to be executed properly (no errors, just a secondary prompt opened), hence I consider a FIFO filter:
⇨⇨⇨⇨(
⇨⇨⇨⇨command1...
⇨⇨⇨⇨cat <<-'PMA' > /opt/script.sh
⇨⇨⇨⇨⇨⇨⇨⇨#!/bin/bash
⇨⇨⇨⇨⇨⇨⇨⇨strings...
⇨⇨⇨⇨PMA
⇨⇨⇨⇨command2...
⇨⇨⇨⇨) | sed 's/^\s*//g'
preexec
hook function, Bash doesn't; still, you can do something. I believe one does not paste to Bash directly but to the terminal emulator. For this reason Bash cannot know whether the particular command was typed or pasted, so your hook will affect every command. Your desktop environment may have a method to change its clipboard content on the fly (e.g. KDE has, I think) but it will alter copy-pasting desktop-wide. I don't know any terminal emulator with the ability to change pasted text, maybe there is at least one. – Kamil Maciorowski May 02 '17 at 21:15.txt
file into scripts and/or functions and/or aliases? It seems to me you seek an overcomplicated solution to a problem originating in your cumbersome way of work. – Kamil Maciorowski May 02 '17 at 21:28