summaryrefslogtreecommitdiff
path: root/bin/mkrc
blob: e27570fff7db6b92003d78504ff100722a645499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

set -x

DOTFILES=$HOME/.dotfiles
MV=mv
INSTALL=rcup
ROOT_DIR=$HOME


destination() {
  if [ $# -eq 1 ]; then
    echo $DOTFILES/$1
  else
    echo $DOTFILES/tag-$2/$1
  fi
}

install_dotfile() {
  prior_wd=`pwd`
  cd $DOTFILES
  $INSTALL -t ${2:--} $1
  cd $prior_wd
}

if [ $# -eq 0 ]; then
  echo "Usage: dotfiles-add [-t tag] filename ..."
  exit 1
fi

tag=
verbosity=0
while getopts vqt: opt; do
  case "$opt" in
    t) tag=$OPTARG;;
    v) verbosity=$(($verbosity + 1));;
    q) verbosity=$(($verbosity - 1));;
  esac
done
shift $(($OPTIND-1))

if [ $verbosity -ge 2 ]; then
  MV="$MV -v"
  INSTALL="$INSTALL -vv"
elif [ $verbosity -eq 1 ]; then
  MV="$MV -v"
  INSTALL="$INSTALL -v"
elif [ $verbosity -eq 0 ]; then
  MV="$MV -v"
else
  INSTALL="$INSTALL -q"
fi

files=$@

for file in $files; do
  dotless=`echo $file | sed -e "s|$ROOT_DIR/||" | sed -e 's/^\.//'`
  mkdir 
  $MV $file `destination $dotless $tag`
  install_dotfile $dotless $tag
done