I've just started using Vim.

Here is a shell script which I use frequenty from within [BBedit](http://barbones.com/products/bbedit/).

```
#!/bin/sh

filename=$(basename "${BB_DOC_PATH##*/}" .ly)
directory=${BB_DOC_PATH%/*}/

cd "${directory}"

lilypondPDFoutput="${directory}"$filename".pdf"

/Applications/Lilypond.app/Contents/Resources/bin/  lilypond -dno-point-and-click -ddelete-intermediate-    files "$BB_DOC_PATH"

wait

open "${lilypondPDFoutput}"

```

BB\_DOC\_PATH is a variable which represents the path of the currently open file. (e.g. `/Users/me/Documents/file.ly`)

How would I go about placing this script in my .vimrc, and invoking it with simple command like `:typeset`?

Note: I am typesetting a [Lilypond](http://lilypond.org) file.