Skip to content

Instantly share code, notes, and snippets.

@MatthewAlner
MatthewAlner / js-package-manager-utils.sh
Created May 12, 2024 10:55
Bash functions to automatically detect and use the correct JavaScript package manager for installing dependencies and running scripts defined in package.json. Supports Yarn, npm, pnpm, and Bun.
# Function to install JavaScript dependencies based on the lock file present in the current directory.
# as this uses else if statements, it will only install dependencies for the first lock file found
# this means you can use the order as a preference list
install_js_dependencies() {
if [ -f "yarn.lock" ]; then
echo "Using Yarn"
yarn install
elif [ -f "package-lock.json" ]; then
echo "Using npm"
npm install
#!/usr/bin/env bash
type_exists() {
if [ "$(type -P "$1")" ]; then
return 0
fi
return 1
}
if type_exists montage; then
#!/usr/bin/env bash
# sh -c "$(curl -fsSL https://gist.githubusercontent.com/MatthewAlner/c2eda17c075127a364ed8844eb57c3e1/raw/f223fbc8ba87c23d21836c536940f7776d73e659/codeanywhere_setup.sh)"
echo "hello world"
# setup shell stuff
sudo apt-get -y update
sudo apt-get -y install git curl wget tmux zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
sudo usermod -s /bin/zsh "$(whoami)"