Live data from Hacker News

OS X Command Line Utilities

mitchchn.me

51–60 of 243 posts

Re: OS X Command Line Utilities

#51

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)

That's cool. Thanks!

Re: OS X Command Line Utilities

#52
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.

cd is a shell built-in, not an external command. It has to be, since it changes the directory of the shell process, which can't be done by a child process. So shells do have to implement this specially.

Re: OS X Command Line Utilities

#53
post #42
post #33

Earlier quoted context omitted.

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.

Yes but I use the default bash, as do probably most OS X users.

Re: OS X Command Line Utilities

#54
This was supposed to be few lines of remarks. It expanded quickly in relation with my enthusiasm for this topic.

I've been investing some time in the command line on my Mac. I am moving from a dilettante going to the shell on a per-need basis to a more seasoned terminal native. It pays off handesomely! It's hard to convey how nice it to have to have a keyboard-based unified environment instead of a series of disjoined mouse-based GUI experiences.

Here are some recommendations pertaining to mastering the command line on a Mac specifically:

-You can make the terminal start instantaneously instead of it taking several seconds. Remove the .asl files in /private/var/log/asl/. Also remove the file /users//Library/Preferences/com.apple.terminal.plist

- Install iterm2. It possesses many fancy features but honestly I hardly ever use them. The main reason to use it instead of the default Terminal application is that It just works©.

-Make your terminal look gorgeous. It may sound superficial but it actually is important when you spend expanded period of time in the terminal. You go from this http://i.imgur.com/cx3zZL8.png to this http://i.imgur.com/MQbx8yK.png . You become eager to go to your terminal instead of reluctant. Pick a nice color scheme https://code.google.com/p/iterm2/wiki/ColorGallery . Use a nice font (Monaco, Source Code Pro, Inconsolata are popular). Make it anti aliased.

-Go fullscreen. Not so much for the real estate but for the mental switch. Fullscreen mode is a way to immerse yourself into your productive development world. No browser, no mail, no application notification. Only code.

-Install Alfred. It's the command line for the GUI/Apple part of your system. Since I installed it I stopped using the dock and Spotlight. Press ⌘+space then type what you want and it comes up. In just a few keystrokes you can open an application, open gmail/twitter/imdb/..., make a webs search, find a file (by name, by text content), open a directory,... It's difficult to describe how empowering it is to being able to go from 'I want to check something out in the directory x which is somewhere deep deep in my dev folders' to having it displayed in 2 seconds flat.

-Make a few symlinks from your home directory to the directories you use frequently. Instead of doing cd this/that/code/python/project/ you just do cd ~/project.

-Learn the shell. I recommend the (free) book The Linux Command Line: http://linuxcommand.org/tlcl.php . It guides you gently from simple directory navigation all the way up to shell scripting.

-Use tmux. Essential if you want to spend some time in the terminal. You can split the window in multiple independent panes. Your screen will have multiple terminals displayed simultaneously that you can edit independently. For example I'll have the code in one side and on the other side a REPL or a browser. You can also have multiple windows each with its own set of panes and switch from on to the other. With the multiple windows I can switch from one aspect of a project to another instantly. E.g: one window for the front-end dev, a second one for the backend and another for misc file management/git/whatever.

-Pick an editor and work towards mastery. I don't care if you choose vi or emacs. You'll be surprised how simple features can make a big change in how you type. You'll be even more surprised at how good it feels

The terminal is here to stay. It's a skill that bears a lot of fruits and that deprecate slowly. The more you sow the more you reap.

Re: OS X Command Line Utilities

#55

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 don't know if there's an equivalent for OSX but if you're running linux you can use x11 forwarding to do this:

  ssh -x example.com
  cat /var/log/syslog | grep event | xclip -i
Your X clipboard will be shared with the host so the output will be placed into your local clipboard.

Re: OS X Command Line Utilities

#56
post #3

My favorite command is 'say'. You can do all kinds of silly voices. Try this out: say hello -v Good

It knows how to sing "In The Hall Of The Mountain King" as well: say -v cellos "Dum dum dum dum dum dum dum he he he ho ho ho fa lah lah lah lah lah lah fa lah full hoo hoo hoo"

OK, how did you discover that?

Re: OS X Command Line Utilities

#57

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)

You could probably squash the 'ssh localhost -p 19999 pbcopy' into an alias too, to reduce the typing further.

EDIT: oh wait.. remote host.. ok, maybe, maybe not. depends on your environments I guess.

Re: OS X Command Line Utilities

#59
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

Homebrew actually uses /usr/local/Cellar for all its installations, and then makes symlinks in the relevant /usr/local/{bin,sbin} directories. Not sure if that's what you meant.

Thanks for the clarification. Still, a quick Google search seems to indicate that this does not solve all related problems (symlinking, overriding, etc.).

Re: OS X Command Line Utilities

#60

This was supposed to be few lines of remarks. It expanded quickly in relation with my enthusiasm for this topic. I've been investing some time in the command line on my Mac. I am moving from a dilettante going to the shell on a per-need basis to a more seasoned terminal native. It pays off handesomely! It's hard to convey how nice it to have to have a keyboard-based unified environment instead of a series of disjoine…

I'd add installing zsh+oh-my-zsh. Impressive autocompletion, fuzzy matching, shortcuts, themes (I think agnoster is great), plugins... It's really great and I wouldn't go back to bash. Some resources:

https://github.com/robbyrussell/oh-my-zsh/wiki/Cheatsheet http://www.quora.com/zsh/What-are-the-cool-features-of-zsh-t...

I'd also install autojump https://github.com/joelthelion/autojump to jump quickly between directories instead of using symlinks. Instead of cd ~/project, you just do j project, or maybe j proj is enough for autojump to know where you want to go.

Post reply on HN