Topic: https://brettterpstra.com/2014/11/14/safer-command-line-paste-in-iterm-2/
hide preview

What's next? verify your email address for reply notifications!

unverified 4y, 360d ago

Hi Brett, Thanks for your post. I am looking for a solution to paste the output from clipboard into other command (say as additional argument to completely new command). Unfortunately I haven't found any useful information for that. Any idea how to past to contents of clipboard into command? pbpaste command works if I run it as a coprocess without any others. But when I use either run command or send text option, nothing happens. Iterm documentation doesn't say anythin about this. I was using SecureCrt earlier and it had \v switch which pastes clipboard into input, but can't find anything in iTerm2 for now. Thanks a lot in advance!

remark link
hide preview

What's next? verify your email address for reply notifications!

Brett 4y, 359d ago

Sounds like you either want piping, e.g. pbpaste | command or substitution, e.g. command "$(pbpaste)". Or is there something I'm not understanding about the question?

remark link parent
hide preview

What's next? verify your email address for reply notifications!

unverified 4y, 359d ago

Thanks for you reply, Brett. command "$(pbpaste)" is what I need, but when I use a trigger with either "send text" or "run command" option, the pasteboard is not triggered. And what I get instead with "send text" option is just the following: command "$(pbpaste)" And with "run command" action I get nothing at all. I am out of ideas now :-(

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Brett 4y, 358d ago

Are you trying to put it on a keyboard shortcut? Why do you need "send text" or "run command" at all?

remark link parent

load more (1 remarks)
hide preview

What's next? verify your email address for reply notifications!

unverified 4y, 358d ago

Here is my use case: Check output of one command, copy part of that output into pasteboard and then run another command to check something else with pasteboard contents. Ideally I'd like to run second command just with one click/trigger/hotkey. But when I try to use pasteboard for that it just doesn't work. Hope my answer makes sense :)

hide preview

What's next? verify your email address for reply notifications!

elbeavers 10y, 125d ago

Thanks for the safety tip. Clever!

hide preview

What's next? verify your email address for reply notifications!

Florian Schrödl 10y, 125d ago

Got the same here, but I've added an optional "$" removal at the start of the line:

echo $(pbpaste) | sed 's/^\$//' | tr -d '\n'

Of course, you should always be cautious, what you paste into your command line :)

hide preview

What's next? verify your email address for reply notifications!

kavu 10y, 125d ago

If you only want to delete *trailing* newlines you can change the command to:

printf '%s' "$(pbpaste)"

which uses the fact that command substitution removes any trailing newlines.

This feature is coming to readline, and so bash,[0] and with this plugin[1] is available in zsh.

[0]: http://lists.gnu.org/archiv...
[1]: https://github.com/robbyrus...

hide preview

What's next? verify your email address for reply notifications!

jordantbro 10y, 126d ago

Why not just make the shortcut ⌘V? E.g. http://cl.ly/image/2Z1k3j3a...

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 10y, 126d ago

you'll be unpleasantly surprised when you go to paste in vim...

remark link parent
hide preview

What's next? verify your email address for reply notifications!

EmptyJay 10y, 126d ago

It took me a moment to figure that out, too...

hide preview

What's next? verify your email address for reply notifications!