Netsight Blog

Cool stuff Netsight are up to in Zope and Plone

Blog > Entries tagged unix

Never knew this before:

grep --color foo bar.txt

will search for 'foo' in the file bar.txt and will highlight the colour. Works on MacOS and FreeBSD (and probabaly Linux).

If you've added a bunch of changes to a local SVN copy, in a bunch of different places, then try running this little beauty:

svn stat | grep '^?' | awk '{print $2}' | xargs svn add

Basically, it checks the status, searches the results for lines beginning in '?' (files svn doesn't know about yet), strips off the ? char, leaving the filename, and then whacks them all into svn add.

Woot.

Be sure to run an 'svn stat' before calling this to make sure that you don't have any files lying about that you *DON'T* want added, as this command will just add them AAALL.

If you want to search for something and replace it with a newline (or some text containing a newline), to enter a newline character into the "replace" box, use:

C-q C-j

I.e. Ctrl-q then Ctrl-j.

Emacs 'tramp' (remote file loading) is great, but what if you are in an ssh session and want to open a file without having to work out the full remote path you're in and type it into your local emacs?

Here's my magical solution:

location="/`whoami`@`hostname`:`pwd`/$2"
ssh $1 emacsclient $location --no-wait

Put the above two lines into a script (called emacs-remote or something) and save it on the remote server you want to work on (make sure its in the PATH or your home dir or somewhere easy to reference). Also make sure your local copy of emacs is in server mode (type Meta-x server-start, or put (server-start) in your .emacs file and reload)

Then you can do the following:

  1. Load up ssh to a remote server (ssh username@host)
  2. Navigate to a directory
  3. Type "/emacs-remote localusername@localmachine filetoopen.txt"

Where localusername@localmachine are your login to the machine which is running the emacs you want to use

Et voila - the remote file should load up in your chosen copy of emacs!! This works best if you have SSH ControlMaster setup to re-use your ssh connections, otherwise you'll need to type your remote password again into emacs before it can load the file.

If you don't want to be nagged by the new Emacs 22 splash screen anymore then simply stick this line in your .emacs file:

(setq inhibit-startup-message t)

Voila.. Richard Stallman will now leave you alone to edit your files in peace without telling you how great he is everytime you start it :)

Rather than initialising new ssh connections each time you want a new terminal window to a server, you can set up a ControlMaster session, which allows other ssh connections to re-use it (so you dont have to retype your password... amongst other things).

First stick these 3 lines in you ssh config file( /.ssh/config ) which you can create if you don't already have one:

# Where to find the control path, if we have one
Host *
  ControlPath ~/.ssh/master-%r@%h:%p
  ControlMaster auto

This allows connections with the same username, hostname and port to share sessions.

So now, just ssh as normal and you'll only have to login the first time, subsequent sessions will re-use the existing connection automagically!

If you get a conflict on an svn update, manually edit your file to sort out the conflict and then run:

svn resolved myfile.txt

This will clear up the temporary files created by the conflict, and tell svn that its all ok. Then you are safe to run:

svn commit myfile.txt -m "All ok now"

Reference: http://svnbook.red-bean.com/en/1.1/ch03s05.html#svn-ch-3-sect-5.4