#!/bin/sh
NPM_PATH=$(cd $(dirname $0) && pwd)/$(basename $0)
while [ -h $NPM_PATH ]; do
  NPM_PATH=$(dirname $NPM_PATH)/$(ls -ld -- "$NPM_PATH" | awk '{print $11}')
done
NPM_PATH=$( dirname $NPM_PATH )

SOURCE_FILES=$($NPM_PATH/get-source-files.sh)
for SOURCE_FILE in $SOURCE_FILES; do
  for LINE in "# added for npm-completion" "PATH_TO_NPM_COMPLETION=" "source \$PATH_TO_NPM_COMPLETION\/npm-completion.sh"; do
    sed -i "" "/$LINE/d" "$SOURCE_FILE"
  done
done

# echo messages
printf "\nremove this line from a cron job or startup script if added\n"
printf "    PATH=\$PATH:\"$(dirname "$(which node)")\":\"$(dirname "$(which npm)")\" && cd $NPM_PATH && ./update\n"
