Live data from Hacker News

OS X Command Line Utilities

mitchchn.me

41–50 of 243 posts

Re: OS X Command Line Utilities

#41
One command I can't live without: textutil.

Basically it's a command-line front end to Apple's TextKit file import/export library. Works with a bunch of rich text/word processor formats, including OpenDoc, RTF, HTML 5, and MS Word. Critically, the HTML it emits is vastly better than the bloated crap that comes out of Microsoft Word or LibreOffice when you save as HTML ...

Install pandoc and multimarkdown as well and you've got the three pillars of a powerful, easy-to-use multiformat text processing system.

Re: OS X Command Line Utilities

#42
post #33
post #25

It seems odd to have open /Applications/Safari.app/ as an example, when open -a safari does the same thing.

Except that the first one is supported by TAB-completion.

With the right zsh plugin, either of them will tab complete properly. (I think "osx" from oh-my-zsh is the one that does it on mine)

Edit: looks like this is actually built into zsh. Slightly surprised, but just goes to show I know almost nothing about the shell I use every day.

Re: OS X Command Line Utilities

#43
I want "remote pbcopy"! I'd like to be able to log in to any remote host (usually Linux in my case), then tack something onto the command line I'm typing to copy it into the pastebuffer.

    ssh somehost
    cd /some/dir
    grep -lr foo . | remote_pbcopy
I guess something like this is possible with GNU Screen or with Tmux, and perhaps the Tmux/iTerm interaction helps, but I've never figured it out.

Re: OS X Command Line Utilities

#44
post #32
post #28

Earlier quoted context omitted.

Many people love them, but I never got the hang of pushd and popd. These days, I use a CDPATH and z[1]. I also use zsh, which supports handy little things such as cd - (cd to previous directory). If you haven't tried it, I highly recommend z. It's impossible to Google for, but it's oh-so-convenient. 1. https://github.com/rupa/z

'cd -' is implemented by the cd command using the OLDPWD environment variable. It works in all shells.

I did some digging and it turns out I had autopushd set. No wonder I didn't understand the usefulness of pushd/popd; I was already using them.

Also, by "cd -" I meant cd -[tab], cd -1, cd -2, etc.

Re: OS X Command Line Utilities

#45

What always surprises me is that so many don't know or use the directory stack commands, pushd and popd. I'll admit I was also ignorant of them until something like 2005, but once I learned of them I switched and never looked back. Now I can't see someone write or type "cd" without a little bit of a cringe.

I've always just relied on zsh to deal with my pushd stack automatically. I don't frequently need to pushd (thanks to tmux's vertical splits), but when I do, it's inevitably something I don't think about until after I've swapped directories.

Re: OS X Command Line Utilities

#46

What always surprises me is that so many don't know or use the directory stack commands, pushd and popd. I'll admit I was also ignorant of them until something like 2005, but once I learned of them I switched and never looked back. Now I can't see someone write or type "cd" without a little bit of a cringe.

Wow. I never knew about those commands. I've been getting by with just plain cd, and "cd -" if I need to go back.

Re: OS X Command Line Utilities

#47

I want "remote pbcopy"! I'd like to be able to log in to any remote host (usually Linux in my case), then tack something onto the command line I'm typing to copy it into the pastebuffer. ssh somehost cd /some/dir grep -lr foo . | remote_pbcopy I guess something like this is possible with GNU Screen or with Tmux, and perhaps the Tmux/iTerm interaction helps, but I've never figured it out.

On your Mac:

    ssh -R 19999:localhost:22 remote_host
On the remote host:

    command_that_prints_stuff | ssh localhost -p 19999 pbcopy

________

The first command routes the port 19999 on the remote host to port 22 on the computer you're using.

ssh part on the second command connects to 19999 (and thus 22 on your computer) and runs the pbcopy command in the current shell (which is the pipe from command_that_prints_stuff)

Re: OS X Command Line Utilities

#49

I want "remote pbcopy"! I'd like to be able to log in to any remote host (usually Linux in my case), then tack something onto the command line I'm typing to copy it into the pastebuffer. ssh somehost cd /some/dir grep -lr foo . | remote_pbcopy I guess something like this is possible with GNU Screen or with Tmux, and perhaps the Tmux/iTerm interaction helps, but I've never figured it out.

I usually try to stick it all on one line when I have to do that, something like

    ssh somehost 'cd /some/dir; grep -lr foo .' | pbcopy
not very flexible, but it works for many cases

Re: OS X Command Line Utilities

#50
post #12

/usr/local is the default location for user-installed stuff, but I personally like to have my package manager do its stuff in a separate directory. I like the way Fink [1] uses the /sw (software) directory. Does anyone have a valuable opinion on the comparison between Fink and Homebrew — or maybe MacPorts? [1] http://www.finkproject.org

I work on pkgsrc which is another alternative. Its main advantages are:

* A large number of pre-built binary packages with an apt-get style command (pkgin) to install them. Over 10,000 packages are available for OSX in the most recent release (2014Q1).

* It is cross-platform to over 20 different platforms. At Joyent we provide binary packages for SmartOS/illumos, OSX, and Linux, so you can use identical packaging tools across multiple platforms, rather than having to use different tools on each OS. It is the default package manager on SmartOS, with over 12,000 binary packages available for that platform.

* As the 'src' in 'pkgsrc' implies, it's very easy to build from source too if you want to tweak build options or compiler flags. You can also install into any prefix you desire (we default to /usr/pkg), even as an unprivileged user to your home directory.

Our binary packages are available from http://pkgsrc.joyent.com/installing.html and we'd love to hear feedback on how to improve them or adding support for different platforms.

Post reply on HN