How can I pipe the output of *all* entered shell commands into another? (e.g. pipe everything into 'lolcat')

6,641

Solution 1

You can redirect stdout in your shell:

exec 1> >(lolcat)

BUT

if lolcat sends its own output to stdout, you're bound to run into problems. This might work

exec 1> >(lolcat >&2)

Solution 2

You could do this:

bash | lolcat

this enters into bash and whatever command you run will be rainbow

Share:
6,641

Related videos on Youtube

user1442303
Author by

user1442303

Updated on September 18, 2022

Comments

  • user1442303
    user1442303 over 1 year

    Good Afternoon,

    (OS X user)

    I am specifically trying to pipe the output of every shell command I type into the ruby gem 'lolcat' (which makes the output to the terminal rainbow colored).

    Is there a way to do this without explicitly aliasing command individually? I was thinking perhaps there might be a way to pipe anything before the return key is pressed , but I am not sure how to do this.

    Your assistance is appreciated, as I am tired of looking at just one color in my terminal.

  • user1442303
    user1442303 over 10 years
    Thanks Glenn! How would I incorporate this into my .bashrc, alias the exec command?
  • glenn jackman
    glenn jackman over 10 years
    I'm not sure that's working, so I'd explicitly turn it on (don't make it the default behaviour): lol() { exec 1> >(lolcat); } and to turn it off: unlol() { exec 1> /dev/stdout; }
  • user1442303
    user1442303 over 10 years
    I'm sure there will be some issues (I've noticed when turned on programs like 'nano' will not work), but this is exactly what I was looking for. Thank you.
  • glenn jackman
    glenn jackman over 10 years
    I feel like you want to shoot yourself in the foot and I just gave you the gun. Good luck.
  • user1442303
    user1442303 over 10 years
    At the risk of accidentally doing something I'll regret (which now seems to be much higher than usual), I'm leaving it off and just aliasing ls for now.
  • Shawn
    Shawn about 7 years
    Did not work for me. sh: syntax error near unexpected token >'`
  • glenn jackman
    glenn jackman about 7 years
    The process substitution >(...) is a bash feature. Cannot use plain sh
  • DavidPostill
    DavidPostill almost 4 years
    Welcome to Super User! Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places.