iOS Dev Nugget 165 Copy and Paste from Shell


Need to run a code review on your codebase? Hire me

As developers, we often copy and paste to and fro the shell. So I thought I write a tiny tip that I learnt about a while back, yet not particularly specific to iOS app development. Normally you'd do something like this to copy the output of a command you ran in the shell:

do_something | pbcopy

Or to paste something:

pbpaste | do_something_else

If you define a small function in bash (e.g. you can put it in your ~/.profile):

function clip { [ -t 0 ] && pbpaste || pbcopy; }

then you can do this for copying:

do_something | clip

and pasting:

clip | do_something_else

If you use fish shell, you can define this in a file in ~/.config/fish/functions/:

function clip
    if not tty >/dev/null

PS: I'm not sure if tips such as this are of interest to you. If you can hit reply and let me know in a few words if you want more or less of this, it'll be much appreciated!

Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No



Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter


View archives of past issues