1

I have a plugin that generates and copies to the clipboard a ready-to-paste command. For now I open a new terminal, paste the command and execute it. I want to write a script that automatically opens a new terminal and runs that command using the clipboard as input.

I tried to use xclip but can't figure out how to pipe its output to gnome-terminal, and all of the threads I saw focus on the opposite problem: saving command output to clipboard which is NOT what I want to do.

What I tried: xclip -se c -o | gnome-terminal -e

It says "Failed to parse arguments: Missing argument for -e". So at the very least I have a syntax problem.

I have a feeling that I might not be approaching this problem the right way. Complete noob here, so the more details the better!

Thanks!

1 Answers1

1

It seems like gnome-terminal can't take input from stdin, so you have to use command substitution:

gnome-terminal -e "$(xclip -se c -o)"

Also, if you want to perform word splitting and globbing on the clipboard contents before it's run, you can use this:

gnome-terminal -x $(xclip -se c -o)

If you need to hold the terminal open when the command completes, you could use this:

gnome-terminal -x bash -c "$(xclip -se c -o); read -p 'Press Enter to close.'"

Or if you want to go to an interactive prompt:

gnome-terminal -x bash -c "$(xclip -se c -o); bash"

For more ideas, see With a launcher for a terminal application, how can I keep the terminal open after the program is complete?

wjandrea
  • 14,504