getwp bashrc command

.bashrc command to quickly download WordPress

Today I will share a small snippet that will make it easier for you to download wordpress. I need to create lots of wordpress project frequently and downloading/extracting wordpress is very regular thing for me. As I have to frequently do this process – I made this code snippet that save few seconds/minute of my life 🙂
This is a .bashrc snippet. .bashrc is great configuration for all the linux terminal geek. And now a days not only linux but lots of windows based developer enjoying this cool feature via GIT bash. If you want use that on windows, check this post – “Setting up dev environement for WAMP developer

The Snippet

# ----------------------------------
# Download WordPress and extract it
# ----------------------------------
getwp(){ 
  #if folder name specified
  if [ $@ ]; then
    # If that folder is not exist
    if [ -x./$@ ]; then
        mkdir ./$@
    fi
  fi

  cd ./$@

  # If you don't have curl installed - you can use wget.
  # wget  -O ./wordpress.tar.gz "http://wordpress.org/latest.tar.gz"
  curl -o ./wordpress.tar.gz http://wordpress.org/latest.tar.gz
  tar -xvzf ./wordpress.tar.gz
  rm ./wordpress.tar.gz
  mv ./wordpress/* ./
  rm -r ./wordpress

  echo '-------------------------'
  echo 'Finished getting wordpress'

}

Paste the above snippet in your ~/.bashrc file and restart your console or source your .bashrc by typing source ~/.bashrc.

Once you are done with above, you can just type in your terminal –

getwp

and it will

  1. Download latest version of wordpress.
  2. Extract downloaded archive file in the current directory
  3. Remove all temporary files (ex. the downloaded wordpress archive file)

You can also use following command –

getwp directoryName

This will create a new directory direcotoryName if not already exist and download the wordpress in that directory.

Let me know if you like this snippet. Also let me know your feedback/ideas so that I can improve that snippet and do more cool stuffs with it.