Perl Weekly Challenge: Bonus Script

Recently, the Perl Weekly Challenge has been linking to a EZPWC script that tries to automate a bunch of the interaction that’s necessary to participate in the challenge. But it does a bunch of stuff I don’t need, and it feels a bit like overkill. So I decided to whip up my own pwc script that I can run each week to take care of the repetitive stuff I do each week when I work on my challenge solutions.

#!bash - for syntax highlighting

function pwc_skeleton () {
  SKELETON=$1
  FILE=$2
  if [[ ! -f $FILE ]]; then
    cp $SKELETON $FILE
  fi
  chmod +x $FILE
}

function pwc () {
  cd $HOME/git/perlweeklychallenge-club/

  # update the repository to the latest week
  if ! git remote | grep upstream >/dev/null; then
    git remote add upstream \
      git@github.com:manwar/perlweeklychallenge-club.git
  fi
  git fetch upstream 
  git switch master
  git merge upstream/master
  git push

  # find the latest challenge directory
  CHALLENGE_DIR=$(ls -d challenge-* | tail -1)
  cd $CHALLENGE_DIR/packy-anderson

  # set up the skeleton files
  mkdir raku
  pwc_skeleton $CFGDIR/pwc/skeleton.raku raku/ch-1.raku
  pwc_skeleton $CFGDIR/pwc/skeleton.raku raku/ch-2.raku

  mkdir perl
  pwc_skeleton $CFGDIR/pwc/skeleton.pl perl/ch-1.pl
  pwc_skeleton $CFGDIR/pwc/skeleton.pl perl/ch-2.pl

  mkdir python
  pwc_skeleton $CFGDIR/pwc/skeleton.py python/ch-1.py
  pwc_skeleton $CFGDIR/pwc/skeleton.py python/ch-2.py

  touch blog.txt
  git add .
  code .
}

And yes, it’s in Bash and not Perl or Raku. Because sometimes Bash is just the right tool for the job. This file gets sourced from my .bashrc file, so the functions are defined and when I type pwc it’s executed in my current shell.

This and my skeleton files are under source control at https://github.com/packy/maccfg/tree/master/pwc.