#!/usr/bin/env bash

locked_init() {
  pushd ~/ > /dev/null || exit 1

  mkdir -p ~/.emacs.d/.cache/
  AUTOJUMP_TXT="$HOME/.local/share/autojump/autojump.txt"
  mkdir -p "$(dirname "$AUTOJUMP_TXT")"
  touch "$AUTOJUMP_TXT"

  # clone all missing repos
  mr checkout > /dev/null

  printf "" > /tmp/mr-repos
  mr inject > /dev/null

  printf "(\\n" > /tmp/mr-projectile
  sed -E 's/\/home\/andreh/~/' /tmp/mr-repos | awk '{print "\""$1"/""\""}' >> /tmp/mr-projectile
  printf ")" >> /tmp/mr-projectile
  cp /tmp/mr-projectile ~/.emacs.d/.cache/projectile-bookmarks.eld

  popd > /dev/null || exit 1
}
export -f locked_init
