If you can’t remember the command line arguments to rsync, take heart. Start with something like
rsync -av src dest
and work your way from there.
code snippets. useful tricks. shell scripts.
heavy GNU/Linux bias.
heck, maybe some mac stuff.
If you can’t remember the command line arguments to rsync, take heart. Start with something like
rsync -av src dest
and work your way from there.
You can re-auto-indent (?) some text in Vim with =. (It works with ST2, as well.) This can save you a bunch of manual > and/or <.
It’s seems close to useless with Python, but otherwise it can be very useful.
I always forget this, so here is the most basic of basics.
Right now, you’re typing this:
ssh foo@home.bar.com
You’d rather type this:
ssh home
Add this to ~/.ssh/config:
Host home
HostName home.bar.com
User foo
ssh home should now work as expected.
This is a ruby gem which allows you to monitor files and perform some action when they change. You limit which files you want to monitor with a regex. You can configure which actions guard performs yourself, using their DSL, or by installing one of the many plugins.
If all you want to do is run a shell command, guard-shell will suffice.
An example Guardfile, roughly:
guard :shell do
watch /(.*)\.mkd/ do |m|
`markdown #{m[1]}.mkd >#{mkd[1]}.html`
end
end
That’s about all you need to get started. Whenever you alter foo.mkd, guard will invoke the command line above, which will output a corresponding foo.html.
Obviously you could use this for compiling, running unit tests, or whatever you like.
It’s actually super easy to use git and ssh to pull repos between your machines. Pull is the operative word, though. More on that in a bit.
Create a repo on machine A, whose hostname for this example is desktop.local. We’ll clone from this repo at first.
mkdir -p ~/src/my-repo
cd ~/src/my-repo
git init
On machine B, hostname laptop.local, we clone the repo:
mkdir -p ~/src
cd ~/src
git clone ssh://desktop.local/~src/my-repo
Now your laptop has a copy of my-repo and pulls from desktop.local.
If we want to be able to pull from laptop.local, we’ll need to tell desktop.local about it.
git remote add origin ssh://laptop.local/~src/my-repo
git branch --set-upstream master origin/master
That should do you.
Now, you can set up a scenario where you push to a repo, but it will work differently. You won’t be able to work in that repo; it’s purely for pushing and pulling, not committing. That’s a bit like github except your stuff doesn’t have to be public, and is instead secured behind ssh on your private machine.
Holy mother of crap. I forget this one all the time and it drives me up a wall.
This works in bash and zsh:
declare -f
Or
typeset -f
This will list all the functions defined in your shell, including the source.
Sometimes you want to monitor what changes are happening to a file or the output of a command. The poor man’s way to do it is via something like
while true; do echo foo; sleep 1; done
Fortunately, there exists a simpler way:
watch -n 1 'echo foo'
It appears to ship with Linux, but not Mac OS 10.7. Homebrew has it, however.
Assumptions:
Let’s tunnel.
VNC is basically plain text, including any keystrokes you send. Authentication is weak compared to such as ssh. And to access VNC remotely you’d ostensibly have to open that port to the Internet.
With ssh tunneling, you don’t have to open a special port in your firewall for VNC. All authentication and subsequent traffic happens over ssh.
Try this:
ssh -C user@myhost.com -L 5900:127.0.0.1:5900
Feel free to add -fNq to background ssh (so you can’t accidentally close a terminal window and lose it), -N so that it doesn’t run any commands, and -q so that it’s quiet.
This connects you to myhost.com, forwarding your local port (hence -L) 5900 to the remote port 5900.
Use your favorite VNC client, connecting to localhost, port 5900, and with whatever credentials you set up.
I’ve only tested this once or twice. It seems pretty slow! I can’t tell if it’s the quality of this connection or what. So maybe prepare yourself.
Example: I have a big ol’ PATH variable, necessarily : separated. I want to see each entry on a separate line. Here you go:
echo $PATH | tr ':' '\n'
Or if you’re feeling even more terse:
tr ':' '\n' <<<$PATH
tr is one of my blind spots, I’ll admit. I’m more inclined to reach for sed or awk, which are overkill for little jobs like these.
Well, at long last, I’ve switched from Vim to Sublime Text 2. If I had to summarize my motivation, it would be two parts:
Vintage plugin. I highly recommend taking it for a spin.
A license will set you back $59. In the final consideration, it was worth it to me for a few reasons.
The first is that it’s cross-platform, Mac and Linux. (Maybe there’s a Windows version? I don’t know.)
The second is that you can install it on as many machines as you want. I have it on all of my work and home machines.
Lastly, ST2 does nag you if you have no license. However, it’s very, very easy to ignore. In other words, you can evaluate it as long as you like. And it’s one person writing it, as far as I can tell. This is something I want to support with my money.