From 221d8465c9d7278717ca284ac8e1eb849bae7cd9 Mon Sep 17 00:00:00 2001 From: Jim Richter Date: Tue, 22 Jun 2021 13:05:12 +0200 Subject: [PATCH 1/2] feat: manage versions with asdf --- Dockerfile | 2 +- configs/.zshrc | 7 ++-- configs/zsh/aliases.sh | 2 +- configs/zsh/functions/fp.zsh | 39 +++++++++++--------- helpers/asdf-install.sh | 16 +++++++++ helpers/installer.sh | 4 +-- helpers/multiselect.sh | 4 +-- install.sh | 2 +- install/install-asdf.sh | 12 +++++++ install/install-config.sh | 46 ------------------------ install/install-nvim.sh | 15 ++++++++ install/oh-my-zsh.sh | 0 install/p10k.sh | 4 +-- install/zsh-autosuggestions.sh | 0 setup.sh | 66 +++++++++++++++++++++++----------- 15 files changed, 124 insertions(+), 95 deletions(-) create mode 100644 helpers/asdf-install.sh create mode 100755 install/install-asdf.sh delete mode 100644 install/install-config.sh create mode 100755 install/install-nvim.sh mode change 100644 => 100755 install/oh-my-zsh.sh mode change 100644 => 100755 install/p10k.sh mode change 100644 => 100755 install/zsh-autosuggestions.sh diff --git a/Dockerfile b/Dockerfile index 09d2518..fbe9d0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM debian:latest -ADD . ~/.dotfiles +ADD . /root/.dotfiles RUN apt-get update && apt-get upgrade -y RUN apt-get install curl git zsh -y diff --git a/configs/.zshrc b/configs/.zshrc index 001c0d8..5a755fd 100644 --- a/configs/.zshrc +++ b/configs/.zshrc @@ -76,9 +76,10 @@ source $HOME/.dotfiles/configs/zsh/update-repo.zsh # The next line enables shell command completion for gcloud. #if [ -f '/home/coder/downloads/google-cloud-sdk/completion.zsh.inc' ]; then . '/home/coder/downloads/google-cloud-sdk/completion.zsh.inc'; fi -. $HOME/.asdf/asdf.sh -. $HOME/.asdf/completions/asdf.bash - +if [ -s "$HOME/.asdf" ]; then + . $HOME/.asdf/asdf.sh + . $HOME/.asdf/completions/asdf.bash +fi # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh diff --git a/configs/zsh/aliases.sh b/configs/zsh/aliases.sh index 53ed4fe..e7850a7 100644 --- a/configs/zsh/aliases.sh +++ b/configs/zsh/aliases.sh @@ -9,7 +9,7 @@ alias yoink="curl" alias pls='sudo -E env "PATH=$PATH"' -alias zshc="cd ~/.dotfiles && vim configs/.zshrc" +alias zshc="cd ~/.dotfiles && vim configs/.zshrc && cd -" alias zshu="source ~/.zshrc" alias nano="nvim" diff --git a/configs/zsh/functions/fp.zsh b/configs/zsh/functions/fp.zsh index 4e894f6..3840f45 100644 --- a/configs/zsh/functions/fp.zsh +++ b/configs/zsh/functions/fp.zsh @@ -2,28 +2,33 @@ function fp(){ - PORT=$1; + for p in "$@" + do - if [ "$(which lsof)" = "lsof not found" ]; then - echo "lsof not installed" - else - PIDS="$(lsof -t -i:$PORT)" - - AMOUNT=$(wc -w<<<$PIDS); - - if [ $AMOUNT = 0 ]; then - - echo "No processes use port $PORT"; + PORT=$var; + if [ "$(which lsof)" = "lsof not found" ]; then + echo "lsof not installed" else + PIDS="$(lsof -t -i:$PORT)" - echo "Killing $AMOUNT process(es) using port $PORT"; + AMOUNT=$(wc -w<<<$PIDS); - echo "$PIDS" | while IFS= read -r pid ; do - kill -9 $pid; - done + if [ $AMOUNT = 0 ]; then + echo "No processes use port $PORT"; + + else + + echo "Killing $AMOUNT process(es) using port $PORT"; + + echo "$PIDS" | while IFS= read -r pid ; do + kill -9 $pid; + done + + fi fi - fi -} \ No newline at end of file + done + +} diff --git a/helpers/asdf-install.sh b/helpers/asdf-install.sh new file mode 100644 index 0000000..39418be --- /dev/null +++ b/helpers/asdf-install.sh @@ -0,0 +1,16 @@ +asdfInstall(){ + . "$HOME/.asdf/asdf.sh" + if [ "$(which asdf)" = "" ]; then + echo "Asdf not installed" + else + echo "-------------- ASDF install ------------------" + echo "-- $1" + asdf plugin add $1 + asdf install $1 latest + asdf global $1 latest + echo "----------------------------------------------" + fi +} + + +[[ "${1}" != "--source-only" ]] && asdfInstall "${@}" diff --git a/helpers/installer.sh b/helpers/installer.sh index f8f2e36..15eef8b 100644 --- a/helpers/installer.sh +++ b/helpers/installer.sh @@ -24,11 +24,11 @@ installOptional() { install() { # Check if program is already installed if isInstalled $1; then - echo " - $1 is already installed" + echo " ✓ $1 is already installed" else echo " - installing $1 ..." apt-get install $1 -y >/dev/null - echo " - finished" + echo " ✓ finished" fi } diff --git a/helpers/multiselect.sh b/helpers/multiselect.sh index 18a91f0..66acd29 100644 --- a/helpers/multiselect.sh +++ b/helpers/multiselect.sh @@ -68,9 +68,9 @@ function multiselect() { # print options by overwriting the last lines local idx=0 for option in "${options[@]}"; do - local prefix=" [ ]" + local prefix=" [ ]" if [[ ${selected[idx]} == true ]]; then - prefix=" [x]" + prefix=" [x]" fi cursor_to $(($startrow + $idx)) diff --git a/install.sh b/install.sh index f34f448..de3dae5 100644 --- a/install.sh +++ b/install.sh @@ -1,8 +1,8 @@ #!/bin/bash # - Prerequesits - -echo "-- Installing git --" if [ "$(which git)" = "" ]; then + echo "-- Installing git --" apt-get install git -y >/dev/null fi diff --git a/install/install-asdf.sh b/install/install-asdf.sh new file mode 100755 index 0000000..0483c2f --- /dev/null +++ b/install/install-asdf.sh @@ -0,0 +1,12 @@ +if [ -d ~/.asdf ] ; then + + echo " ✓ asdf already installed" + +else + + git clone --quiet https://github.com/asdf-vm/asdf.git ~/.asdf > /dev/null + cd ~/.asdf + git checkout --quiet "$(git describe --abbrev=0 --tags)" > /dev/null + . asdf.sh + +fi diff --git a/install/install-config.sh b/install/install-config.sh deleted file mode 100644 index 6bf3e05..0000000 --- a/install/install-config.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -e -cd "$(dirname "$0")" - -# Make config directory for Neovim's init.vim -echo '[*] Preparing Neovim config directory ...' -mkdir -p ~/.config/nvim - -# Install nvim (and its dependencies: pip3, git), Python 3 and ctags (for tagbar) -echo '[*] App installing Neovim and its dependencies (Python 3 and git), and dependencies for tagbar (exuberant-ctags) ...' -sudo apt update -sudo apt install neovim python3 python3-pip python3-venv git curl exuberant-ctags -y - -# Install virtualenv to containerize dependencies -echo '[*] Pip installing venv to containerize Neovim dependencies (instead of installing them onto your system) ...' -python3 -m venv ~/.config/nvim/env - -# Install pip modules for Neovim within the virtual environment created -echo '[*] Activating virtualenv and pip installing Neovim (for Python plugin support), libraries for async autocompletion support (jedi, psutil, setproctitle), and library for pep8-style formatting (yapf) ...' -source ~/.config/nvim/env/bin/activate -pip install pynvim jedi psutil setproctitle yapf doq # run `pip uninstall neovim pynvim` if still using old neovim module -deactivate - -# Install vim-plug plugin manager -echo '[*] Downloading vim-plug, the best minimalistic vim plugin manager ...' -curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim - -# (Optional but recommended) Install a nerd font for icons and a beautiful airline bar (https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts) (I'll be using Iosevka for Powerline) -echo "[*] Downloading patch font into ~/.local/share/fonts ..." -curl -fLo ~/.fonts/Iosevka\ Term\ Nerd\ Font\ Complete.ttf --create-dirs https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/Iosevka/Regular/complete/Iosevka%20Term%20Nerd%20Font%20Complete.ttf - -# (Optional) Alias vim -> nvim -echo '[*] Aliasing vim -> nvim, remember to source ~/.bashrc ...' -echo "alias vim='nvim'" >>~/.bashrc - -# Enter Neovim and install plugins using a temporary init.vim, which avoids warnings about missing colorschemes, functions, etc -echo -e '[*] Running :PlugInstall within nvim ...' -sed '/call plug#end/q' ../configs/init.vim >~/.config/nvim/init.vim -nvim -c ':PlugInstall' -c ':UpdateRemotePlugins' -c ':qall' -rm ~/.config/nvim/init.vim - -# Copy init.vim in current working directory to nvim's config location ... -echo '[*] Linking init.vim -> ~/.config/nvim/init.vim' -cd .. -ln -s $(pwd)/configs/init.vim ~/.config/nvim/init.vim - -echo -e "[+] Done, welcome to \033[1m\033[92mNeoVim\033[0m! Try it by running: nvim/vim. Want to customize it? Modify ~/.config/nvim/init.vim" diff --git a/install/install-nvim.sh b/install/install-nvim.sh new file mode 100755 index 0000000..cb9f6ab --- /dev/null +++ b/install/install-nvim.sh @@ -0,0 +1,15 @@ +if [ -f "$HOME/.config/nvim/init.vim" ]; then + echo " - moving old file to init.vim.BAK" + mv "$HOME/.config/nvim/init.vim" "$HOME/.config/nvim/init.vim.BAK" +fi + +echo " - linking init.vim --> init.vim" +mkdir -p $HOME/.config/nvim +ln -s "$HOME/.dotfiles/configs/init.vim" "$HOME/.config/nvim/init.vim" + +echo " - installing vim-plug" +sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' + +echo " - installing vim plugins" +nvim --headless +PlugInstall +q diff --git a/install/oh-my-zsh.sh b/install/oh-my-zsh.sh old mode 100644 new mode 100755 diff --git a/install/p10k.sh b/install/p10k.sh old mode 100644 new mode 100755 index 266ec33..16d7306 --- a/install/p10k.sh +++ b/install/p10k.sh @@ -1,3 +1,3 @@ -echo " - cloning github.com/zsh-users/zsh-autosuggestions into ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" +echo " - cloning github.com/romkatv/powerlevel10k into ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" git clone --quiet --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k > /dev/null -echo " - finished" \ No newline at end of file +echo " - finished" diff --git a/install/zsh-autosuggestions.sh b/install/zsh-autosuggestions.sh old mode 100644 new mode 100755 diff --git a/setup.sh b/setup.sh index 67502eb..399216a 100755 --- a/setup.sh +++ b/setup.sh @@ -1,10 +1,12 @@ #!/bin/bash cd "$(dirname "$0")" +#Loading all the helper scripts . ./helpers/installer.sh --source-only . ./helpers/prompt.sh --source-only . ./helpers/linker.sh --source-only . ./helpers/multiselect.sh --source-only +. ./helpers/asdf-install.sh --source-only echo "-- welcome to my setup script --" echo "-- installing prerequesits (git, curl) --" @@ -31,35 +33,66 @@ echo "-----------------------------------" #Make the selection echo "-- what do you want to install? --" -OPTIONS_VALUES=("ZSH" "NVIM" "DRNV" "GVM" "NVM" "SDKM") -OPTIONS_LABELS=("zsh + oh-my-zsh" "Neovim" "Direnv" "Go Version Manager" "Node Version Manager" "Java Version Manager") + +# 0 - ZSH +# 1 - NVIM +# 2 - DRNV +# 3 - NODE +# 4 - GO +# 5 - ZSH +# 6 - ZSH +# 7 - ZSH + +OPTIONS_VALUES=("ZSH" "NVIM" "ASDF" "DRNV" "NODE" "GO" "PYTH" "DENO" "HUGO" "RUST") +OPTIONS_LABELS=("zsh + oh-my-zsh" "Neovim" "Asdf" "Direnv" "NodeJS" "Golang" "Python" "Deno" "Hugo" "Rust") for i in "${!OPTIONS_VALUES[@]}"; do OPTIONS_STRING+="${OPTIONS_VALUES[$i]} (${OPTIONS_LABELS[$i]});" done if [ $INTERACTIVE = "true" ]; then - multiselect SELECTED "$OPTIONS_STRING" + multiselect SELECTED "$OPTIONS_STRING": fi # Variables INST_ZSH=${SELECTED[0]} INST_NVIM=${SELECTED[1]} -INST_DRNV=${SELECTED[2]} -INST_GVM=${SELECTED[3]} -INST_NVM=${SELECTED[4]} -INST_SDKM=${SELECTED[5]} +INST_ASDF=${SELECTED[2]} +INST_DRNV=${SELECTED[3]} +INST_NODE=${SELECTED[4]} +INST_GO=${SELECTED[5]} +INST_PYTH=${SELECTED[6]} +INST_DENO=${SELECTED[7]} +INST_HUGO=${SELECTED[8]} +INST_RUST=${SELECTED[9]} if [ $INTERACTIVE = "false" ]; then INST_ZSH=true + INST_NVIM=true fi echo "-----------------------------------" echo -e "-- installing programs --" [[ "$INST_DRNV" = true ]] && install direnv -[[ "$INST_GVM" = true ]] && echo " - installing GVM" -[[ "$INST_NVM" = true ]] && echo " - installing NVM" -[[ "$INST_SDKM" = true ]] && echo " - installing SDKM" +if [ "$INST_ASDF" = true ]; then + + # Requirements for ASDF + install gnupg2 + install unzip + ./install/install-asdf.sh + + if [ "$INST_NVIM" = true ]; then + asdfInstall neovim + ./install/install-nvim.sh + fi + + [[ "$INST_NODE" = true ]] && asdfInstall nodejs + [[ "$INST_GO" = true ]] && asdfInstall golang + [[ "$INST_PYTH" = true ]] && asdfInstall python + [[ "$INST_DENO" = true ]] && asdfInstall deno + [[ "$INST_HUGO" = true ]] && asdfInstall hugo + [[ "$INST_RUST" = true ]] && asdfInstall rust +fi echo "-- linking .dotfiles --" @@ -81,15 +114,6 @@ if [ "$INST_ZSH" = true ]; then echo "-----------------------------------" fi -if [ "$INST_NVIM" = true ]; then - install neovim - - echo "-- Configuring Optixal's Neovim (https://github.com/Optixal/neovim-init.vim) --" - - sh $(pwd)/install/install-config.sh - echo "-----------------------------------" -fi - if [ "$INST_ZSH" = true ]; then # Change default shell @@ -106,4 +130,6 @@ cd ~ echo "-- ALL DONE --" -zsh +if [ "$INST_ZSH" = true ]; then + zsh +fi From fd29af46f4b7474c71c205c813965094ab07c741 Mon Sep 17 00:00:00 2001 From: Jim Richter Date: Tue, 22 Jun 2021 13:07:02 +0200 Subject: [PATCH 2/2] fix: quitting install vim plugins --- install/install-nvim.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/install-nvim.sh b/install/install-nvim.sh index cb9f6ab..a99290a 100755 --- a/install/install-nvim.sh +++ b/install/install-nvim.sh @@ -12,4 +12,4 @@ sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug. https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' echo " - installing vim plugins" -nvim --headless +PlugInstall +q +nvim --headless +PlugInstall +qa