Tuesday, May 27, 2008

Using find and printf

This is basic stuff but I wanted to post it so I can find it when I search for it...

How to find a file and print the name, path and date and time it was last accessed...

Change filename to be the file you want, with optional wildcards. (Use -iname for case insensitive search).

find . -name -printf "%p %AD %AH:%AM\n"

Tuesday, May 13, 2008

Batch file tip ... %~dp0

Here's a nice blog post on this...

Silly batch file tricks, redirecting stdout into an evironment variable and %~dp0

But just for my own reference the cryptic looking character sequence resolves to the path to the batchfile you are running.

So if you put the following in a batch file, no matter what directory you are in when you run it, it will print the directory the batch file is in, and do a directory listing.

echo Batch file path is %~dp0
dir %~dp0

Thursday, May 1, 2008

Copying characters from the line above in emacs

The BBC microcomputer had a button called COPY, which when you pressed it would copy the character on the line above the cursor. This was quite handy, and I recently was waiting for a large amount of code to link, and thought I'd have a go at implementing it.

There's not a lot to it in fact. This function just remembers the cursor position (using save-excursion) and then goes to the previous line, gets the character after the point, and finally after the save-excursion block I just insert the character.

(defun copy-char-above()
"copy the character above point into the buffer"
(let (c)
(setq c (char-after)))
(insert (char-to-string c))))

Here I just assign the function to a key...

(global-set-key [f6] 'copy-char-above)