Live data from Hacker News

macOS command-line tools you might not know about

saurabhs.org

111–120 of 454 posts

Re: macOS command-line tools you might not know about

#111

Earlier quoted context omitted.

That's a useless use of cat. You can use `jq . foo.json | pbcopy` or `jq < foo.json | pbcopy`.

Speaking for myself, the first form is more natural- even if it’s a useless cat, because I’m always cat-ing files to see their structure. Then progressively tacking on different transforms. And then finally putting it in whatever I want as output. It’s so ingrained, I’m more likely than not to just write it out that way even when I know exactly what I’m doing from the onset.

You could consider

    

Re: macOS command-line tools you might not know about

#112

Earlier quoted context omitted.

I love this flow! Such a powerful and clean way to solve text issues. # This will remove Windows double-spaced empty lines from your copy/paste buffer alias winlines="sed '/^$/{$!{N;s/\n//;};}'" # pbw = [P]aste [B]uffer to fix [W]indows line endings alias pbw="pbpaste | winlines | pbcopy" Also - if you want `pbpaste` and `pbcopy` on Linux... # imitate MacOS's paste buffer copy/paste: alias pbcopy='xsel --clipboard --…

Here's the xclip way (almost the same actually). alias pbcopy="xclip -selection clipboard" alias pbpaste="xclip -selection clipboard -o"

I use this, and another Mac affordance I copy in Linux is

    alias open="xdg-open"

Re: macOS command-line tools you might not know about

#115
post #98

Earlier quoted context omitted.

That's a useless use of cat. You can use `jq . foo.json | pbcopy` or `jq < foo.json | pbcopy`.

In what way do you see those alternatives as superior?

They avoid an unnecessary invocation of the cat executable.

Instead, they open a file descriptor and pass that.

Tiny difference but there you go.

Re: macOS command-line tools you might not know about

#116
post #19

Earlier quoted context omitted.

I have linux/macos-agnostic bash functions in my dotfiles that unify this to “clip” and “paste” (since “copy” is too close semantically to “cp”)

paste(1) is a POSIX standard utility, though (going back to System III), pairing with cut(1). https://pubs.opengroup.org/onlinepubs/9699919799/utilities/p...

The Unix join command is also useful:

https://en.m.wikipedia.org/wiki/Join_(Unix)

Re: macOS command-line tools you might not know about

#118
post #8

`pbcopy` and `pbpaste` are one of my most-loved in the list. Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

I have linux/macos-agnostic bash functions in my dotfiles that unify this to “clip” and “paste” (since “copy” is too close semantically to “cp”)

And I have one that unifies _both_ to `clip` so you can put the same command in both sides of the pipe, e. g. to turn a line-delimited blob on your clipboard to a space-separated one:

    clip | tr '\n' ' ' | clip
https://github.com/svieira/dotfiles/blob/a3654d6a194e3689978...

    # Use clipboard in shell pipelines
    # clip | xargs echo           # uses pbpaste
    # ps -A | grep search | clip  # uses pbcopy
    clip() {
      [ -t 0 ] && pbpaste || pbcopy
    }

Re: macOS command-line tools you might not know about

#120
post #83
post #8

`pbcopy` and `pbpaste` are one of my most-loved in the list. Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

I like to use `pbcopy` when exporting public keys to external services like GitHub. `cat ~/.ssh/mykey.pub | pbcopy`

I love this tool too!

except one time I quickly typed

`cat ~/.ssh/mykey | pbcopy`

And sent it straight away to my coworker on Slack.

I then spent the rest of the day making a new private key and adding my new pubkey to all of the 1000+ servers I had root access to. I mean we had tools to help but it still wasn’t fun.

With great power/convenience comes the potential to do dumb things at lightning speeds!

Post reply on HN