Bash function to robustly pipe terminal output to vim

Spread the love

I often re-direct my terminal output to vim, in this fashion, which I get tired of typing all the time:
ls | vim –

I would like to define a function v to do this for me, i.e I want to be able to type:
v ls and that this somehow ‘expands’ to the previous command.
I can do this do work in simple cases with a script in this kind (of course, this can be re-factored as a small function):

touch crrt_cmd

while (( “$#” )); do
echo -n $1 >> crrt_cmd
echo -n ” ” >> crrt_cmd

chmod +x crrt_cmd
bash crrt_cmd | vim –

rm crrt_cmd

This works fine for very simple commands, for example ls or ls -l, but it does not work at all when some piping is present for example.
Any idea on how to perform something similar, but that works with any valid bash command?

So just to be clear, I would like things to work in this way if it is possible:
v ls | grep keyword | head -5

would translate into:
ls | grep keyword | head -5 | vim –

X ITM Cloud News


Leave a Reply

Next Post

how to connect the Internet via Bluetooth?

Wed Jul 1 , 2020
Spread the love          Can I connect to the internet using Bluetooth? Ubuntu 19.10 I do not have a phone or any devices that uses Bluetooth. X ITM Cloud News

Cloud Computing – Consultancy – Development – Hosting – APIs – Legacy Systems

X-ITM Technology helps our customers across the entire enterprise technology stack with differentiated industry solutions. We modernize IT, optimize data architectures, and make everything secure, scalable and orchestrated across public, private and hybrid clouds.

This image has an empty alt attribute; its file name is x-itmdc.jpg

The enterprise technology stack includes ITO; Cloud and Security Services; Applications and Industry IP; Data, Analytics and Engineering Services; and Advisory.

Watch an animation of  X-ITM‘s Enterprise Technology Stack

We combine years of experience running mission-critical systems with the latest digital innovations to deliver better business outcomes and new levels of performance, competitiveness and experiences for our customers and their stakeholders.

X-ITM invests in three key drivers of growth: People, Customers and Operational Execution.

The company’s global scale, talent and innovation platforms serve 6,000 private and public-sector clients in 70 countries.

X-ITM’s extensive partner network helps drive collaboration and leverage technology independence. The company has established more than 200 industry-leading global Partner Network relationships, including 15 strategic partners: Amazon Web Services, AT&T, Dell Technologies, Google Cloud, HCL, HP, HPE, IBM, Micro Focus, Microsoft, Oracle, PwC, SAP, ServiceNow and VMware