+snippet pkgver "pkgver() function" b
+pkgver() {
+  cd ${1:$pkgname-$pkgver}
+  ( set -o pipefail
+    git describe --long --tags 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
+    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
+  )
+}
+endsnippet
+
 snippet prep "prepare() function" b
 prepare() {
-       cd ${1:$pkgname-$pkgver}
-       $0
+  cd ${1:$pkgname-$pkgver}
+  $0
 }
 endsnippet
 
 snippet build "build() function" b
 build() {
-       cd ${1:$pkgname-$pkgver}
-       ./configure \
-               --prefix=/usr $2
-       $0
+  cd ${1:$pkgname-$pkgver}
+  ./configure \
+    --prefix=/usr $2
+  $0
 }
 endsnippet
 
 snippet pack "package() function" b
 package() {
-       cd ${1:$pkgname-$pkgver}
-       make DESTDIR="$pkgdir" install
-       $0
+  cd ${1:$pkgname-$pkgver}
+  make DESTDIR="$pkgdir" install
+  $0
 }
 endsnippet