Refactor to use __install_with function
This commit is contained in:
+78
-48
@@ -8,8 +8,22 @@ fi
|
|||||||
CONFIG_DIR=$PWD
|
CONFIG_DIR=$PWD
|
||||||
DID_UPDATE_BREW="NO"
|
DID_UPDATE_BREW="NO"
|
||||||
|
|
||||||
USAGE=$(cat <<< END
|
USAGE=$(cat <<-END
|
||||||
USAGE: $0
|
USAGE: $0 <package>|all
|
||||||
|
|
||||||
|
This script bootstraps your shell environment by installing configs,
|
||||||
|
installers (e.g., brew), and useful programs. The following packages are
|
||||||
|
supported:
|
||||||
|
|
||||||
|
configs only install shell config files
|
||||||
|
coffeescript install coffeescript language tools
|
||||||
|
go install go language tools
|
||||||
|
heroku install the Heroku CLI
|
||||||
|
node install NodeJS language tools
|
||||||
|
python install Python language tools
|
||||||
|
ruby install Ruby language tools
|
||||||
|
typescript install TypeScript language tools
|
||||||
|
webtools install tools for web development
|
||||||
END
|
END
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +44,6 @@ function __configure_git() {
|
|||||||
|
|
||||||
function __install_all() {
|
function __install_all() {
|
||||||
__install_configs
|
__install_configs
|
||||||
__configure_git
|
|
||||||
|
|
||||||
__install_brew
|
__install_brew
|
||||||
__install_basics
|
__install_basics
|
||||||
@@ -43,8 +56,8 @@ function __install_all() {
|
|||||||
__install_node
|
__install_node
|
||||||
__install_python
|
__install_python
|
||||||
__install_ruby
|
__install_ruby
|
||||||
__install_webtools
|
|
||||||
__install_typescript
|
__install_typescript
|
||||||
|
__install_webtools
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_brew() {
|
function __install_brew() {
|
||||||
@@ -55,6 +68,30 @@ function __install_brew() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __install_with() {
|
||||||
|
INSTALLER="$1"
|
||||||
|
PACKAGE="$2"
|
||||||
|
CHECK="$3"
|
||||||
|
OPTS=""
|
||||||
|
|
||||||
|
[[ "$CHECK" == "" ]] && CHECK="$PACKAGE"
|
||||||
|
|
||||||
|
if ! which -s "$CHECK"; then
|
||||||
|
if [[ "$INSTALLER" == "brew" ]]; then
|
||||||
|
__update_brew
|
||||||
|
elif [[ "$INSTALLER" == "npm" ]]; then
|
||||||
|
__install_node
|
||||||
|
OPTS="-g"
|
||||||
|
elif [[ "$InSTALLER" == "pip" ]]; then
|
||||||
|
__install_python
|
||||||
|
fi
|
||||||
|
|
||||||
|
$INSTALLER install $OPTS $PACKAGE
|
||||||
|
else
|
||||||
|
echo "$CHECK was already installed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function __update_brew() {
|
function __update_brew() {
|
||||||
__install_brew
|
__install_brew
|
||||||
|
|
||||||
@@ -69,22 +106,18 @@ function __update_brew() {
|
|||||||
# Package Functions ####################################################################################################
|
# Package Functions ####################################################################################################
|
||||||
|
|
||||||
function __install_basics() {
|
function __install_basics() {
|
||||||
__update_brew
|
__install_with brew ag
|
||||||
|
__install_with brew ctags
|
||||||
which -s ag || brew install ag
|
__install_with brew fswatch
|
||||||
which -s ctags || brew install ctags
|
__install_with brew reattach-to-user-namespace
|
||||||
which -s fswatch || brew install fswatch
|
__install_with brew tmux
|
||||||
which -s tmux || brew install tmux
|
__install_with brew tmuxinator
|
||||||
which -s watch || brew install watch
|
__install_with brew watch
|
||||||
which -s wget || brew install wget
|
__install_with brew wget
|
||||||
|
|
||||||
which -s reattach-to-user-namespace || brew install reattach-to-user-namespace
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_coffeescript() {
|
function __install_coffeescript() {
|
||||||
__install_node
|
__install_with npm coffeescript
|
||||||
|
|
||||||
which -s coffee || npm install -g coffeescript
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_configs() {
|
function __install_configs() {
|
||||||
@@ -95,70 +128,67 @@ function __install_configs() {
|
|||||||
[[ -e "$FILE" ]] && rm -rf "$FILE"
|
[[ -e "$FILE" ]] && rm -rf "$FILE"
|
||||||
ln -sf "$CONFIG_DIR/home/$FILE" "$FILE"
|
ln -sf "$CONFIG_DIR/home/$FILE" "$FILE"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
__configure_git
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_gcc() {
|
function __install_gcc() {
|
||||||
__update_brew
|
__install_with brew gcc
|
||||||
|
|
||||||
which -s gcc || brew install gcc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_go() {
|
function __install_go() {
|
||||||
__update_brew
|
__install_with brew go
|
||||||
|
|
||||||
which -s go || brew install go
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_heroku() {
|
function __install_heroku() {
|
||||||
__update_brew
|
(brew tap heroku/brew && __install_with brew heroku)
|
||||||
|
|
||||||
which -s heroku || (brew tap heroku/brew && brew install heroku)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_node() {
|
function __install_node() {
|
||||||
__update_brew
|
__install_with brew node
|
||||||
|
__install_with npm nodemon
|
||||||
which -s node || brew install node
|
|
||||||
which -s nodemon || npm install -g nodemon
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_python() {
|
function __install_python() {
|
||||||
__update_brew
|
|
||||||
|
|
||||||
which -s pyenv || brew install pyenv
|
__install_with brew pyenv
|
||||||
pyenv install python3.9
|
VERSION=$(pyenv install --list | sed 's/^ *//' | grep '^3.9' | tail -1)
|
||||||
pyenv global python3.9
|
|
||||||
|
pyenv install -s "$VERSION"
|
||||||
|
pyenv global "$VERSION"
|
||||||
|
pyenv version
|
||||||
|
|
||||||
pip install --upgrade pip
|
pip install --upgrade pip
|
||||||
pip install jedi
|
__install_with pip jedi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_ruby() {
|
function __install_ruby() {
|
||||||
which -s rbenv || brew install rbenv
|
__install_with brew rbenv
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_webtools() {
|
function __install_webtools() {
|
||||||
__install_node
|
__install_node
|
||||||
|
|
||||||
which -s browserify || npm install -g browserify
|
__install_with npm browserify
|
||||||
which -s eslint || npm install -g eslint
|
__install_with npm eslint
|
||||||
which -s sass || npm install -g node-sass
|
__install_with npm node-sass
|
||||||
which -s pug || npm install -g pug-cli
|
__install_with npm pug-cli
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_typescript() {
|
function __install_typescript() {
|
||||||
__install_node
|
__install_node
|
||||||
|
|
||||||
which -s tsc || npm install -g typescript
|
__install_with npm typescript tsc
|
||||||
which -s tslint || npm install -g tslint
|
__install_with npm tslint
|
||||||
which -s ts-node || npm install -g ts-node
|
__install_with npm ts-node
|
||||||
which -s tsserver || npm install -g tsserver
|
__install_with npm tsserver
|
||||||
}
|
}
|
||||||
|
|
||||||
function __install_vim() {
|
function __install_vim() {
|
||||||
__upgrade_brew
|
__upgrade_brew
|
||||||
|
|
||||||
ls -l $(which vim) | grep "Cellar/vim" >/dev/null || brew install vim
|
ls -l $(which vim) | grep "Cellar/vim" >/dev/null || __install_with brew vim
|
||||||
vim +PlugClean +PlugInstall +qall
|
vim +PlugClean +PlugInstall +qall
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,16 +197,16 @@ function __install_vim() {
|
|||||||
DID_RUN="NO"
|
DID_RUN="NO"
|
||||||
while [[ "$1" != "" ]]; do
|
while [[ "$1" != "" ]]; do
|
||||||
FUNC="__install_$1"
|
FUNC="__install_$1"
|
||||||
if [[ $(type "$FUNC") == "function" ]]; then
|
if [[ $(type "$FUNC") == *"function"* ]]; then
|
||||||
DID_RUN="YES"
|
DID_RUN="YES"
|
||||||
FUNC
|
$FUNC
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$DID_RUN" == "NO" ]]; then
|
if [[ "$DID_RUN" == "NO" ]]; then
|
||||||
echo $USAGE
|
echo "$USAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|||||||
Reference in New Issue
Block a user