Skip to content

Instantly share code, notes, and snippets.

@dclowd9901
Last active October 13, 2015 14:37
Show Gist options
  • Save dclowd9901/4210396 to your computer and use it in GitHub Desktop.
Save dclowd9901/4210396 to your computer and use it in GitHub Desktop.
JSHintLI-install
#!/bin/sh
if ! type "node" > /dev/null; then
echo " "
echo "Node not installed. Please visit http://nodejs.org to download and install the correct Node package."
exit 1
else
echo " "
echo "Node installed correctly; continuing..."
fi
if ! type "git" > /dev/null; then
echo " "
echo "Git not installed. Please visit http://git-scm.com/ to download and install the correct Git package."
exit 1
else
echo " "
echo "Git installed correctly; continuing..."
fi
USERNAME=$(id -un)
SOSB="SublimeOnSaveBuild"
# If Mac, else
if [ $(uname) = 'Darwin' ]; then
SUBL_PATH="/Users/$USERNAME/Library/Application Support/Sublime Text 2/Packages"
HINTRC_PATH="/Users/$USERNAME"
LINUX_APPEND=""
else
SUBL_PATH="/home/$USERNAME/.config/sublime-text-2/Packages"
HINTRC_PATH="/home/$USERNAME"
LINUX_APPEND=' "linux" : { "path":"/usr/local/bin:/opt/local/bin" }'
fi
update_jshintrc()
{
curl http://viewvc.corp.linkedin.com/viewvc/netrepo/network/trunk/content/static/.jshintrc?view=co# > ~/.jshintrc
}
if [ "$1" = "update" ]; then
echo " "
echo "Updating your local .jshintrc..."
update_jshintrc
exit 0
else
echo " "
echo "Downloading most current version of .jshintrc from trunk..."
update_jshintrc
fi
# Escaped $file and $packages for Sublime Text 2 (python-specific) build variables
NEW_CONFIG_LINE="\"cmd\": [\"jshint\", \"\$file\", \"--reporter\", \"\$packages/JSHint/reporter.js\", \"--config\", \"$HINTRC_PATH/.jshintrc\"],"
if [ -x "/usr/local/bin/jshint" ]; then
echo " "
echo "JSHint already installed; skipping..."
else
# Install JSHint globally
echo " "
echo "Installing JSHint globally..."
sudo npm install -g jshint@2.0.1
fi
# Install JSHint SublimeText Package
if [ -d "$SUBL_PATH" ]; then
cd "$SUBL_PATH"
if [ -d "JSHint" ]; then
echo " "
echo "JSHint Sublime Text package already installed; skipping installation..."
else
echo " "
echo "Installing JSHint Sublime Text package..."
git clone git://github.com/uipoet/sublime-jshint.git JSHint
fi
echo "Editing JSHint.sublime-build..."
cd "$SUBL_PATH/JSHint/"
sed -E "s/\"cmd\".+\"jshint\".+/$(echo $NEW_CONFIG_LINE | sed -e 's/[\/&]/\\&/g')/" < JSHint.sublime-build | sudo tee newJSHint.sublime-build && sudo mv newJSHint.sublime-build JSHint.sublime-build
cd "$SUBL_PATH"
# Install SublimeSaveOnBuild
if [ -d "$SOSB" ]; then
echo " "
echo "$SOSB already installed; skipping..."
else
echo " "
echo "Installing SublimeText 2 $SOSB plugin..."
git clone git://github.com/alexnj/SublimeOnSaveBuild.git "$SOSB"
fi
echo " "
echo "Successful! Simply start Sublime Text 2 and on saving any Javascript file, your file will be checked for JSHint compliance."
else
echo " "
echo "ERROR: Could not find SublimeText application directory."
fi
if [ $(uname) = 'Darwin' ]; then
# Install JSHint TextMate
echo " "
echo "Installing TextMate JSHint..."
if [ -d "/Users/$USERNAME/Library/Application Support/TextMate/Pristine Copy/Bundles" ]; then
cd "/Users/$USERNAME/Library/Application Support/TextMate/Pristine Copy/Bundles"
if [ -d "JSHint" ]; then
echo " "
echo "TextMate JSHint already installed; skipping..."
else
git clone git://github.com/rondevera/jslintmate.git "JavaScript JSLintMate.tmbundle"
osascript -e 'tell app "TextMate" to reload bundles'
fi
echo " "
echo "Successful! To check Javascript files in Textmate, save a file, or key Ctrl+L."
else
echo " "
echo "Textmate not installed; skipping plugin..."
fi
else
echo " "
echo "Textmate not installed; skipping plugin..."
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment