aboutsummaryrefslogtreecommitdiff
path: root/pwc
blob: 12ea5ad8abe5ee8ebefe8beb1f5d9d328b978607 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
MY_PWC_DIR_NAME=${PWC_DIR_NAME}

MY_PWC_ROOT=${PWC_ROOT}

MY_PWC_LANG=${PWC_LANG}

MY_PWC_GIT_USER=${PWC_GIT_USER}

function pwc() {

  if [ $# -ne 0 ]

  then

    if ! [[ "$1" =~ ^[0-9]+$ ]]

    then

      echo

      echo "  "Usage: pwc {challenge number}? - must be positive integer
      echo

      echo "  "Omitting the challenge number will take you to the most recent challenge.
      echo

      echo "  "Created by James Smith.
      echo

      return

    fi

  fi

  ROOT_DIR=$MY_PWC_ROOT/perlweeklychallenge-club

  if [ ! -d "$ROOT_DIR" ]

  then

    echo

    echo "  "You will need a git checkout of the challenge repo here!

    echo

    echo "  "cd $MY_PWC_ROOT

    echo "  git clone git@github.com:MY_PWC_GIT_USER/perlweeklychallenge-club.git"

    echo

    return

  fi

  cd $ROOT_DIR

  git fetch upstream

  git merge upstream/master --ff-only

  git pull --no-rebase

  if [ $# -eq 0 ]

  then

    CHALLENGE_NO=$((10#`ls -1d /www/baggy/perlweeklychallenge-club/challenge-* | tail -1 | cut -d '-' -f 3`))

  else

    CHALLENGE_NO=$1

  fi

  DIR=$ROOT_DIR/challenge-`printf %03d $CHALLENGE_NO`/$MY_PWC_DIR_NAME

  if [ ! -d "$DIR" ]

  then

    echo

    echo "  "That challenge [$CHALLENGE_NO] does not exist

    echo

    return

  fi

  if [ ! -d "$DIR/$MY_PWC_LANG" ]

  then

    mkdir $DIR/$MY_PWC_LANG

    cd $DIR

    git add $MY_PWC_LANG

  fi

  cd $DIR/$MY_PWC_LANG

}