Skip to content

Instantly share code, notes, and snippets.

@Fatpandac
Last active November 18, 2023 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fatpandac/a01bb465b0fafde4f1ebdb86579233f9 to your computer and use it in GitHub Desktop.
Save Fatpandac/a01bb465b0fafde4f1ebdb86579233f9 to your computer and use it in GitHub Desktop.
Change npm source
#!/usr/bin/env bash
if ! type fzf >/dev/null 2>&1; then
echo "请先安装 fzf"
exit 0
fi
declare -A source
source["npm"]="https://registry.npmjs.org/"
source["taobao"]="https://registry.npm.taobao.org/"
source["2dfire"]="http://npm.2dfire.net/"
listAll=""
for key in "${!source[@]}"; do
listAll+="$key "
done
listAll=`echo "$listAll" | tr ' ' '\n'`
selected=`printf "$listAll" | fzf`
if [[ -z $selected ]]; then
exit 0
fi
echo "npm set registry ${source[$selected]}"
npm set registry ${source[$selected]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment