[lang]

Present Perfect

Personal
Projects
Packages
Patches
Presents
Linux

Picture Gallery
Present Perfect

zoning

Filed under: Hacking — Thomas @ 5:47 pm

2007-6-21
5:47 pm

The number one irritation I had when editing zone files was having to update the serial number.

After googling for a while, I found some ideas on how to make vim help there. And then I tweaked it a little for my Fedora Core setup, and made it automatic so that it does it when I open the file. That’s fine, since only if you save the file (which means, you made a change you want) does it actually update the serial on disk.

Now it’s edit – save – reload.

.vimrc snippet:


" define command to increment the SOA in zone files
function! UPDSERIAL(date, num)
if (strftime("%Y%m%d") == a:date)
return a:date . a:num+1
endif
return strftime("%Y%m%d") . '01'
endfunction

command Soa :%s/(2[0-9]{7})([0-9]{2})(s*; serial)/=UPDSERIAL(submatch(1), submatch(2)) . submatch(3)/g

" executed the command when you edit the zone file
autocmd BufRead /var/named/*zone Soa

2 Comments »

  1. Nice :-) Months ago, I made a little sh script to do that for a zone, but didn’t even think to make a vim function out of it…

    Comment by Simon van der Linden — 2007-6-21 @ 7:17 pm

  2. […] Here is a nice trick for using Vim to edit zone files. […]

    Pingback by Edit zone files with Vim at MontyNet — 2007-6-23 @ 3:51 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

picture