diff --git a/bootstrap.sh b/bootstrap.sh index 1e082e6..3ee55b9 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -30,14 +30,14 @@ SUBSTEP_COUNT=0 # Pretty-print step headers. pre_step() { - STEP_COUNT=$(($STEP_COUNT + 1)) + STEP_COUNT=$((STEP_COUNT + 1)) SUBSTEP_COUNT=0 echo -e "\e[1m[$STEP_COUNT/$TOTAL_STEPS] <====== $1 =======>\e[0m" } # Pretty-prints substep headers. pre_substep() { - SUBSTEP_COUNT=$(($SUBSTEP_COUNT + 1)) + SUBSTEP_COUNT=$((SUBSTEP_COUNT + 1)) echo -e "\e[1m[$STEP_COUNT.$SUBSTEP_COUNT] <====== $1 =======>\e[0m" } @@ -52,12 +52,12 @@ copy_file() { dest_path=$2 if [ ! -e "$dest_path" ]; then - cp $source_path $dest_path + cp "$source_path" "$dest_path" echo "Copied $source_path > $dest_path" return 0 fi - difference="$(diff $source_path $dest_path)" + difference=$(diff "$source_path" "$dest_path") if [ -z "$difference" ]; then echo "$dest_path already exists, but is the same as $source_path - skipping." @@ -65,11 +65,11 @@ copy_file() { fi echo "Differences detected between $source_path and $dest_path:" - diff --color $source_path $dest_path - read -p "$dest_path already exists. What should be done? [O:overwrite,S:skip,B:save backup and copy] " action + diff --color "$source_path" "$dest_path" + read -p "$dest_path already exists. What should be done? [O:overwrite,S:skip,B:save backup and copy] " -r action if [[ $action == "O" ]]; then - cp $source_path $dest_path + cp "$source_path" "$dest_path" echo "Overwrote $source_path > $dest_path" return 0 fi @@ -80,9 +80,9 @@ copy_file() { fi if [[ $action == "B" ]]; then - cp $dest_path $dest_path.old + cp "$dest_path" "$dest_path".old echo "Backed up $dest_path up to $dest_path.old" - cp $source_path $dest_path + cp "$source_path" "$dest_path" echo "Overwrote $source_path > $dest_path" return 0 fi @@ -120,7 +120,7 @@ ensure_apt_dependencies() { else echo -e "\e[1mInstalling packages...\e[0m" - sudo apt install $(cat ./files/apt.txt) -y --autoremove + sudo apt install "$(cat ./files/apt.txt)" -y --autoremove echo -e "\e[1;32mSystem packages installed.\e[0m" fi @@ -154,9 +154,8 @@ install_and_configure_starship() { cargo install starship --locked pre_substep "Add initialization command to shell configuration" - STARSHIP_INIT_COMMAND='eval "$(starship init zsh)"' if [ -z "$(rg "starship init zsh" ~/.zshrc)" ]; then - echo "#Initialize Starship prompt\n$STARSHIP_INIT_COMMAND" >> ~/.zshrc + printf "#Initialize Starship prompt\neval \"\$(starship init zsh)\"" >> ~/.zshrc fi pre_substep "Copy configuration in configuration directory" @@ -173,7 +172,9 @@ install_nvm() { pre_substep "Ensuring that NVM can be run right away" # Ensuring that nvm is usable right away without restarting the shell export NVM_DIR="$HOME/.nvm" + # shellcheck disable=SC1091 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + # shellcheck disable=SC1091 [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" } @@ -183,7 +184,7 @@ install_gh_plugins() { gh extension install nektos/gh-act gh extension install dlvhdr/gh-dash - copy_file ./files/gh-dash_config.$ENV_PROFILE.yml ~/.config/gh-dash/config.yml + copy_file ./files/gh-dash_config."$ENV_PROFILE".yml ~/.config/gh-dash/config.yml gh extension upgrade --all } @@ -203,10 +204,10 @@ inject_shell_configuration() { SHELL_CONFIG_PATH="$HOME/.zshrc" echo "Setting up shell configuration extras..." - if [[ -z $(cat $SHELL_CONFIG_PATH | grep $BLOCK_DELIMITER_PATTERN) ]]; then - echo "# $BLOCK_DELIMITER_PATTERN\:start - source $WORKING_PATH/files/shell_extras - # $BLOCK_DELIMITER_PATTERN\:end" >> $SHELL_CONFIG_PATH + if ! grep -q "$BLOCK_DELIMITER_PATTERN" < "$SHELL_CONFIG_PATH"; then + printf "# %s:start\nsource %s/files/shell_extras\n# %s:end" \ + "$BLOCK_DELIMITER_PATTERN" "$WORKING_PATH" "$BLOCK_DELIMITER_PATTERN" \ + >> "$SHELL_CONFIG_PATH" echo "✅ Added managed block to $SHELL_CONFIG_PATH" else echo "No changes to apply!" @@ -224,14 +225,14 @@ inject_vim_configuration() { if [[ -f $EDITOR_CONFIG_FILE ]]; then echo "Setting up NVIM configuration extras..." - if [[ -z $(cat $EDITOR_CONFIG_FILE | grep $BLOCK_DELIMITER_PATTERN) ]]; then - echo "\" $BLOCK_DELIMITER_PATTERN\:start - source $WORKING_PATH/files/extras.vim - \" $BLOCK_DELIMITER_PATTERN\:end\n\n" >> $EDITOR_CONFIG_FILE.new - cat $EDITOR_CONFIG_FILE >> $EDITOR_CONFIG_FILE.new + if ! grep -q "$BLOCK_DELIMITER_PATTERN" < "$EDITOR_CONFIG_FILE"; then + printf "\" %s:start\nsource %s/files/extras.vim\n\" %s:end\n\n" \ + " $BLOCK_DELIMITER_PATTERN" "$WORKING_PATH" "$BLOCK_DELIMITER_PATTERN" \ + >> "$EDITOR_CONFIG_FILE".new + cat "$EDITOR_CONFIG_FILE" >> "$EDITOR_CONFIG_FILE".new - mv $EDITOR_CONFIG_FILE $EDITOR_CONFIG_FILE.old - mv $EDITOR_CONFIG_FILE.new $EDITOR_CONFIG_FILE + mv "$EDITOR_CONFIG_FILE" "$EDITOR_CONFIG_FILE".old + mv "$EDITOR_CONFIG_FILE".new "$EDITOR_CONFIG_FILE" echo "✅ Added managed block to $EDITOR_CONFIG_FILE" else echo "No changes to apply!" @@ -239,7 +240,7 @@ inject_vim_configuration() { fi echo "Setting up git configuration..." - source $WORKING_PATH/files/git_config + source "$WORKING_PATH"/files/git_config echo "✅ Set up git configuration, see $WORKING_PATH/files/git_config for details!" } diff --git a/files/apt.txt b/files/apt.txt index 17dbd6e..9f679bf 100644 --- a/files/apt.txt +++ b/files/apt.txt @@ -3,3 +3,4 @@ tmux postgresql postgresql-contrib gh +shellcheck diff --git a/files/extras.vim b/files/extras.vim index 715c00d..c590654 100644 --- a/files/extras.vim +++ b/files/extras.vim @@ -22,7 +22,7 @@ set termguicolors call plug#begin('~/.vim/plugged') " Style -Plug 'joshdick/onedark.vim' +Plug 'bluz71/vim-nightfly-colors', { 'as': 'nightfly', 'branch': 'legacy' } " Language support Plug 'maxmellon/vim-jsx-pretty' @@ -44,7 +44,6 @@ Plug 'nvim-telescope/telescope-symbols.nvim' Plug 'mcataford/ale' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} - call plug#end() """""""""""""""" @@ -56,6 +55,6 @@ let mapleader=" " nmap f Telescope live_grep nmap F Telescope grep_string -colorscheme onedark +colorscheme nightfly