From 90554015b77727078bddfe22234ee9b2553f178e Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Fri, 25 Sep 2020 21:13:34 +0100 Subject: [PATCH] chore(zsh): install rbenv, pyenv and nodenv with zinit instead of brew Main benefit is that these tools will now auto-install correctly on Linux systems too. --- Brewfile | 12 ----- zsh/direnv.zsh | 6 +-- zsh/golang.zsh | 11 ++++- zsh/nodejs.zsh | 110 ++++++++++++++++++++++--------------------- zsh/python.zsh | 66 ++++++++++++++++---------- zsh/rbenv.zsh | 55 ---------------------- zsh/ruby.zsh | 125 +++++++++++++++++++++++++++++++++++++------------ zshenv | 6 +-- 8 files changed, 208 insertions(+), 183 deletions(-) delete mode 100644 zsh/rbenv.zsh diff --git a/Brewfile b/Brewfile index 674e91f..2a5dabf 100644 --- a/Brewfile +++ b/Brewfile @@ -44,13 +44,10 @@ brew 'node' brew 'pandoc' brew 'peco' brew 'pgformatter' -brew 'pyenv' -brew 'rbenv' brew 'rclone' brew 'readline' brew 'redis' brew 'ripgrep' -brew 'ruby-build' brew 'rustup-init' brew 'shellcheck' brew 'source-highlight' @@ -71,15 +68,6 @@ brew 'zsh' tap 'heroku/brew' brew 'heroku' -# node.js version manager -tap 'nodenv/nodenv' -brew 'nodenv' -brew 'node-build' -brew 'nodenv-aliases' -brew 'nodenv-each' -brew 'nodenv-nvmrc' -brew 'nodenv-package-rehash' - # sshfs requires osxfuse cask 'osxfuse' brew 'sshfs' diff --git a/zsh/direnv.zsh b/zsh/direnv.zsh index b4358ae..bbd72ed 100644 --- a/zsh/direnv.zsh +++ b/zsh/direnv.zsh @@ -2,7 +2,7 @@ # direnv setup # -zinit from"gh-r" as"program" mv"direnv* -> direnv" \ +zinit ice wait lucid from'gh-r' as'program' mv'direnv* -> direnv' \ atclone'./direnv hook zsh > zhook.zsh' atpull'%atclone' \ - pick"direnv" src="zhook.zsh" for \ - direnv/direnv + pick'direnv' src='zhook.zsh' +zinit light direnv/direnv diff --git a/zsh/golang.zsh b/zsh/golang.zsh index 944640c..a3c6c69 100755 --- a/zsh/golang.zsh +++ b/zsh/golang.zsh @@ -1,7 +1,11 @@ # -# Go (golang) setup. +# Go (golang) environment setup. # +# ============================================================================== +# global golang packages +# ============================================================================== + install_go_global_packages() { local packages=( github.com/akavel/up @@ -23,4 +27,9 @@ install_go_global_packages() { echo "installing/updating \"$package\"" go get -u "$package" done + + if command-exists goenv && [ "$(goenv version-name)" != "system" ]; then + echo "running: goenv rehash..." + goenv rehash + fi } diff --git a/zsh/nodejs.zsh b/zsh/nodejs.zsh index d25141e..9ccc6e7 100755 --- a/zsh/nodejs.zsh +++ b/zsh/nodejs.zsh @@ -1,14 +1,67 @@ # -# Node.js +# Node.js environment setup. # -# Aliases +# ============================================================================== +# nodenv +# ============================================================================== + +# install nodenv +zinit ice wait lucid as'program' pick'bin/nodenv' from'gh' \ + atclone'src/configure && make -C src' atpull'%atclone' nocompile'!' +zinit light nodenv/nodenv + +# install node-build +zinit ice wait lucid as'program' pick'bin/node-build' from'gh' +zinit light nodenv/node-build + +# install nodenv-aliases plugin +zinit ice wait lucid as'program' pick'bin/nodenv-aliases' from'gh' +zinit light nodenv/nodenv-aliases + +# install nodenv-each plugin +zinit ice wait lucid as'program' pick'bin/nodenv-each' from'gh' +zinit light nodenv/nodenv-each + +# install nodenv-nvmrc plugin +zinit ice wait lucid as'program' pick'bin/nodenv-nvmrc' from'gh' +zinit light ouchxp/nodenv-nvmrc + +# install nodenv-package-rehash plugin +zinit ice wait lucid as'program' pick'bin/nodenv-package-*' from'gh' +zinit light nodenv/nodenv-package-rehash + +# lazy-load nodenv +nodenv() { + load-nodenv + nodenv "$@" +} + +_nodenv() { + load-nodenv + _nodenv "$@" +} + +compctl -K _nodenv nodenv + +load-nodenv() { + unset -f load-nodenv _nodenv nodenv + eval "$(command nodenv init -)" +} + +# ============================================================================== +# aliases +# ============================================================================== + alias no="node" alias np="npm" alias ni="npm install" alias ngi="npm install -g" alias cof="coffee" -alias tl="tldr" + +# ============================================================================== +# global node packages +# ============================================================================== install_node_global_packages() { local packages=( @@ -43,54 +96,3 @@ install_node_global_packages() { npm install -g "${packages[@]}" } - -# Support for nodenv (https://github.com/nodenv/nodenv) -if command-exists nodenv; then - # lazy-load nodenv - nodenv() { - load-nodenv - nodenv "$@" - } - - _nodenv() { - load-nodenv - _nodenv "$@" - } - - compctl -K _nodenv nodenv - - load-nodenv() { - unset -f load-nodenv _nodenv nodenv - eval "$(command nodenv init -)" - } -fi - -# Support for nvm (https://github.com/nvm-sh/nvm) -if [ -f "$HOME/.nvm/nvm.sh" ]; then - export NVM_DIR="$HOME/.nvm" - - # If default alias is set, add that Node version's bin direcotry to PATH to - # ensure CLI tools from npm packages work before nvm is lazy-loaded. - if [ -s "$NVM_DIR/alias/default" ]; then - path_prepend "$NVM_DIR/versions/node/$(cat "$NVM_DIR/alias/default")/bin" - fi - - # lazy-load nvm - nvm() { - load-nvm - nvm "$@" - } - - _nvm() { - load-nvm - _nvm "$@" - } - - compctl -K _nvm nvm - - load-nvm() { - unset -f load-nvm nvm _nvm - source "$NVM_DIR/nvm.sh" - [ -s "$NVM_DIR/bash_completion" ] && source "$NVM_DIR/bash_completion" - } -fi diff --git a/zsh/python.zsh b/zsh/python.zsh index e8c31e8..2fdebfb 100644 --- a/zsh/python.zsh +++ b/zsh/python.zsh @@ -1,7 +1,46 @@ # -# Python environment setup +# Python environment setup. # +# ============================================================================== +# pyenv +# ============================================================================== + +# install pyenv +zinit ice wait lucid as'program' pick'bin/pyenv' from'gh' \ + atclone'src/configure && make -C src' atpull'%atclone' nocompile'!' +zinit light pyenv/pyenv + +# lazy-load pyenv +pyenv() { + load-pyenv + pyenv "$@" +} + +_pyenv() { + load-pyenv + _pyenv "$@" +} + +compctl -K _pyenv pyenv + +load-pyenv() { + unset -f load-pyenv _pyenv pyenv + eval "$(command pyenv init -)" +} + +# ============================================================================== +# aliases +# ============================================================================== + +alias ap="env OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES ansible-playbook" +alias av="env OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES ansible-vault" +alias mo="env OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES molecule" + +# ============================================================================== +# global python package +# ============================================================================== + install_python_global_packages() { local packages=( 'ansible' @@ -16,28 +55,3 @@ install_python_global_packages() { "$pipcmd" install --upgrade setuptools "$pipcmd" install --upgrade "${packages[@]}" } - -# Aliases -alias ap="env OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES ansible-playbook" -alias av="env OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES ansible-vault" -alias mo="env OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES molecule" - -if command-exists pyenv; then - # lazy-load pyenv - pyenv() { - load-pyenv - pyenv "$@" - } - - _pyenv() { - load-pyenv - _pyenv "$@" - } - - compctl -K _pyenv pyenv - - load-pyenv() { - unset -f load-pyenv _pyenv pyenv - eval "$(command pyenv init -)" - } -fi diff --git a/zsh/rbenv.zsh b/zsh/rbenv.zsh deleted file mode 100644 index ef00dd1..0000000 --- a/zsh/rbenv.zsh +++ /dev/null @@ -1,55 +0,0 @@ -# -# rbenv (Ruby version manager) setup. -# - -# ============================================================================== -# Lazy-load rbenv -# ============================================================================== - -rbenv() { - load-rbenv - rbenv "$@" -} - -_rbenv() { - load-rbenv - _rbenv "$@" -} - -compctl -K _rbenv rbenv - -load-rbenv() { - unset -f load-rbenv _rbenv rbenv - eval "$(command rbenv init -)" -} - -# ============================================================================== -# Plugins -# ============================================================================== - -zinit ice as'program' pick'bin/rbenv-each' from'gh' -zinit light rbenv/rbenv-each - -# ============================================================================== -# Misc. -# ============================================================================== - -solargraph-install() { - rbenv each -v gem install solargraph -} - -solargraph-download-cores() { - rbenv each -v solargraph download-core -} - -solargraph-list-versions() { - rbenv each -v gem list -q solargraph -} - -rubygems-upgrade() { - rbenv each -v gem update --system -} - -upgrade-bundler() { - rbenv each -v gem install --no-document 'bundler:~> 1.0' 'bundler:~> 2.0' -} diff --git a/zsh/ruby.zsh b/zsh/ruby.zsh index b32e169..5bd31bf 100755 --- a/zsh/ruby.zsh +++ b/zsh/ruby.zsh @@ -2,6 +2,78 @@ # Ruby environment setup. # +# ============================================================================== +# rbenv +# ============================================================================== + +# Install rbenv +zinit ice wait lucid as'program' pick'bin/rbenv' from'gh' \ + atclone'src/configure && make -C src' atpull'%atclone' nocompile'!' +zinit light rbenv/rbenv + +# install ruby-build +zinit ice wait lucid as'program' pick'bin/ruby-build' from'gh' +zinit light rbenv/ruby-build + +# install rbenv-each plugin +zinit ice wait lucid as'program' pick'bin/rbenv-each' from'gh' +zinit light rbenv/rbenv-each + +# lazy-load rbenv +rbenv() { + load-rbenv + rbenv "$@" +} + +_rbenv() { + load-rbenv + _rbenv "$@" +} + +compctl -K _rbenv rbenv + +load-rbenv() { + unset -f load-rbenv _rbenv rbenv + eval "$(command rbenv init -)" +} + +# ============================================================================== +# aliases +# ============================================================================== + +# bundler +alias bch="bundle check" +alias bcn="bundle clean" +alias bco="bundle console" +alias be="bundle exec" +alias bi="bundle_install" +alias bl="bundle list" +alias bo="bundle open" +alias bp="bundle package" +alias bu="bundle update" + +# bundle exec wrappers +alias ru="bundle exec ruby" +alias ra="bundle exec rake" +alias rai="bundle exec rails" +alias rs="bundle exec rspec -f doc" +alias cu="bundle exec cucumber" +alias scu="RAILS_ENV=cucumber bundle exec spring cucumber" + +# gems +alias po="powify" +alias lu="lunchy" +alias he="heroku" +alias f="foreman" +alias fs="foreman start" +alias fr="foreman run" +alias pe="procodile exec" +alias sm="schmersion" + +# ============================================================================== +# global ruby packages +# ============================================================================== + install_ruby_global_packages() { local packages=( 'bundler:~> 1.0' @@ -25,35 +97,30 @@ install_ruby_global_packages() { gem install --no-document "${packages[@]}" } -# Aliases -alias po="powify" -alias lu="lunchy" -alias he="heroku" -alias f="foreman" -alias fs="foreman start" -alias fr="foreman run" -alias pe="procodile exec" -alias sm="schmersion" +# ============================================================================== +# bundler +# ============================================================================== -# Aliases for specific ruby commands -alias ru="bundle exec ruby" -alias ra="bundle exec rake" -alias rai="bundle exec rails" -alias rs="bundle exec rspec -f doc" -alias cu="bundle exec cucumber" -alias scu="RAILS_ENV=cucumber bundle exec spring cucumber" +upgrade-bundler() { + rbenv each -v gem install --no-document 'bundler:~> 1.0' 'bundler:~> 2.0' +} -# Bundler aliases -alias bch="bundle check" -alias bcn="bundle clean" -alias bco="bundle console" -alias be="bundle exec" -alias bi="bundle_install" -alias bl="bundle list" -alias bo="bundle open" -alias bp="bundle package" -alias bu="bundle update" +# ============================================================================== +# solargraph +# ============================================================================== -if command-exists rbenv; then - source "$DOTZSH/rbenv.zsh" -fi +solargraph-install() { + rbenv each -v gem install solargraph +} + +solargraph-download-cores() { + rbenv each -v solargraph download-core +} + +solargraph-list-versions() { + rbenv each -v gem list -q solargraph +} + +rubygems-upgrade() { + rbenv each -v gem update --system +} diff --git a/zshenv b/zshenv index bbd3d88..81f75e1 100644 --- a/zshenv +++ b/zshenv @@ -153,15 +153,15 @@ path_prepend "/opt/emacs/bin" # Use custom tmux install if available path_prepend "/opt/tmux/bin" -# Ruby setup +# Ruby setup for rbenv (./zsh/ruby.zsh) path_prepend "$HOME/.rbenv/shims" path_prepend "$HOME/.rbenv/bin" -# Python setup +# Python setup for pyenv (./zsh/python.zsh) path_prepend "$HOME/.pyenv/shims" path_prepend "$HOME/.pyenv/bin" -# Node setup +# Node setup for nodenv (./zsh/nodejs.zsh) path_prepend "$HOME/.nodenv/shims" path_prepend "$HOME/.nodenv/bin"