-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup
executable file
·32 lines (29 loc) · 1.25 KB
/
setup
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
#!/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
END_WITH_NEW_LINE=false
for LINE in "# added for npm-completion https://github.com/Jephuff/npm-bash-completion" "PATH_TO_NPM_COMPLETION=\"$NPM_PATH\"" "source \$PATH_TO_NPM_COMPLETION/npm-completion.sh"; do
grep -F "$LINE" $SOURCE_FILE > /dev/null
if [ $? != 0 ]; then
printf "\n$LINE" >> $SOURCE_FILE
END_WITH_NEW_LINE=true
fi
done
if [[ $END_WITH_NEW_LINE = true ]]; then
printf "\n\n" >> $SOURCE_FILE
fi
done
(cd $NPM_PATH && git clone --depth 1 https://github.com/Jephuff/npm-package-names)
# echo messages
if [ ! -z "$SOURCE_FILES" ]; then
printf "\nadd this line to a cron job or startup script\n"
printf " PATH=\$PATH:\"$(dirname "$(which node)")\":\"$(dirname "$(which npm)")\":\"$(dirname "$(which git)")\" && cd $NPM_PATH && ./update && cd -\n"
printf "\nrestart terminal to start using\n\n"
else
printf "\ncouldn't find source file. Please create ~/.bashrc, ~/.bash_profile or ~/.zshrc and run\n npm-completion-setup\n\n"
fi