fix: address shellcheck errors

This commit is contained in:
Marc 2024-02-29 00:29:31 -05:00
parent 98890b34d2
commit 7b6aa29a78
Signed by: marc
GPG key ID: 048E042F22B5DC79
3 changed files with 29 additions and 28 deletions

View file

@ -30,14 +30,14 @@ SUBSTEP_COUNT=0
# Pretty-print step headers. # Pretty-print step headers.
pre_step() { pre_step() {
STEP_COUNT=$(($STEP_COUNT + 1)) STEP_COUNT=$((STEP_COUNT + 1))
SUBSTEP_COUNT=0 SUBSTEP_COUNT=0
echo -e "\e[1m[$STEP_COUNT/$TOTAL_STEPS] <====== $1 =======>\e[0m" echo -e "\e[1m[$STEP_COUNT/$TOTAL_STEPS] <====== $1 =======>\e[0m"
} }
# Pretty-prints substep headers. # Pretty-prints substep headers.
pre_substep() { pre_substep() {
SUBSTEP_COUNT=$(($SUBSTEP_COUNT + 1)) SUBSTEP_COUNT=$((SUBSTEP_COUNT + 1))
echo -e "\e[1m[$STEP_COUNT.$SUBSTEP_COUNT] <====== $1 =======>\e[0m" echo -e "\e[1m[$STEP_COUNT.$SUBSTEP_COUNT] <====== $1 =======>\e[0m"
} }
@ -52,12 +52,12 @@ copy_file() {
dest_path=$2 dest_path=$2
if [ ! -e "$dest_path" ]; then if [ ! -e "$dest_path" ]; then
cp $source_path $dest_path cp "$source_path" "$dest_path"
echo "Copied $source_path > $dest_path" echo "Copied $source_path > $dest_path"
return 0 return 0
fi fi
difference="$(diff $source_path $dest_path)" difference=$(diff "$source_path" "$dest_path")
if [ -z "$difference" ]; then if [ -z "$difference" ]; then
echo "$dest_path already exists, but is the same as $source_path - skipping." echo "$dest_path already exists, but is the same as $source_path - skipping."
@ -65,11 +65,11 @@ copy_file() {
fi fi
echo "Differences detected between $source_path and $dest_path:" echo "Differences detected between $source_path and $dest_path:"
diff --color $source_path $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 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 if [[ $action == "O" ]]; then
cp $source_path $dest_path cp "$source_path" "$dest_path"
echo "Overwrote $source_path > $dest_path" echo "Overwrote $source_path > $dest_path"
return 0 return 0
fi fi
@ -80,9 +80,9 @@ copy_file() {
fi fi
if [[ $action == "B" ]]; then 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" 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" echo "Overwrote $source_path > $dest_path"
return 0 return 0
fi fi
@ -120,7 +120,7 @@ ensure_apt_dependencies() {
else else
echo -e "\e[1mInstalling packages...\e[0m" 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" echo -e "\e[1;32mSystem packages installed.\e[0m"
fi fi
@ -154,9 +154,8 @@ install_and_configure_starship() {
cargo install starship --locked cargo install starship --locked
pre_substep "Add initialization command to shell configuration" pre_substep "Add initialization command to shell configuration"
STARSHIP_INIT_COMMAND='eval "$(starship init zsh)"'
if [ -z "$(rg "starship init zsh" ~/.zshrc)" ]; then 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 fi
pre_substep "Copy configuration in configuration directory" pre_substep "Copy configuration in configuration directory"
@ -173,7 +172,9 @@ install_nvm() {
pre_substep "Ensuring that NVM can be run right away" pre_substep "Ensuring that NVM can be run right away"
# Ensuring that nvm is usable right away without restarting the shell # Ensuring that nvm is usable right away without restarting the shell
export NVM_DIR="$HOME/.nvm" export NVM_DIR="$HOME/.nvm"
# shellcheck disable=SC1091
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# shellcheck disable=SC1091
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" [ -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 nektos/gh-act
gh extension install dlvhdr/gh-dash 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 gh extension upgrade --all
} }
@ -203,10 +204,10 @@ inject_shell_configuration() {
SHELL_CONFIG_PATH="$HOME/.zshrc" SHELL_CONFIG_PATH="$HOME/.zshrc"
echo "Setting up shell configuration extras..." echo "Setting up shell configuration extras..."
if [[ -z $(cat $SHELL_CONFIG_PATH | grep $BLOCK_DELIMITER_PATTERN) ]]; then if ! grep -q "$BLOCK_DELIMITER_PATTERN" < "$SHELL_CONFIG_PATH"; then
echo "# $BLOCK_DELIMITER_PATTERN\:start printf "# %s:start\nsource %s/files/shell_extras\n# %s:end" \
source $WORKING_PATH/files/shell_extras "$BLOCK_DELIMITER_PATTERN" "$WORKING_PATH" "$BLOCK_DELIMITER_PATTERN" \
# $BLOCK_DELIMITER_PATTERN\:end" >> $SHELL_CONFIG_PATH >> "$SHELL_CONFIG_PATH"
echo "✅ Added managed block to $SHELL_CONFIG_PATH" echo "✅ Added managed block to $SHELL_CONFIG_PATH"
else else
echo "No changes to apply!" echo "No changes to apply!"
@ -224,14 +225,14 @@ inject_vim_configuration() {
if [[ -f $EDITOR_CONFIG_FILE ]]; then if [[ -f $EDITOR_CONFIG_FILE ]]; then
echo "Setting up NVIM configuration extras..." echo "Setting up NVIM configuration extras..."
if [[ -z $(cat $EDITOR_CONFIG_FILE | grep $BLOCK_DELIMITER_PATTERN) ]]; then if ! grep -q "$BLOCK_DELIMITER_PATTERN" < "$EDITOR_CONFIG_FILE"; then
echo "\" $BLOCK_DELIMITER_PATTERN\:start printf "\" %s:start\nsource %s/files/extras.vim\n\" %s:end\n\n" \
source $WORKING_PATH/files/extras.vim " $BLOCK_DELIMITER_PATTERN" "$WORKING_PATH" "$BLOCK_DELIMITER_PATTERN" \
\" $BLOCK_DELIMITER_PATTERN\:end\n\n" >> $EDITOR_CONFIG_FILE.new >> "$EDITOR_CONFIG_FILE".new
cat $EDITOR_CONFIG_FILE >> $EDITOR_CONFIG_FILE.new cat "$EDITOR_CONFIG_FILE" >> "$EDITOR_CONFIG_FILE".new
mv $EDITOR_CONFIG_FILE $EDITOR_CONFIG_FILE.old mv "$EDITOR_CONFIG_FILE" "$EDITOR_CONFIG_FILE".old
mv $EDITOR_CONFIG_FILE.new $EDITOR_CONFIG_FILE mv "$EDITOR_CONFIG_FILE".new "$EDITOR_CONFIG_FILE"
echo "✅ Added managed block to $EDITOR_CONFIG_FILE" echo "✅ Added managed block to $EDITOR_CONFIG_FILE"
else else
echo "No changes to apply!" echo "No changes to apply!"
@ -239,7 +240,7 @@ inject_vim_configuration() {
fi fi
echo "Setting up git configuration..." 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!" echo "✅ Set up git configuration, see $WORKING_PATH/files/git_config for details!"
} }

View file

@ -3,3 +3,4 @@ tmux
postgresql postgresql
postgresql-contrib postgresql-contrib
gh gh
shellcheck

View file

@ -22,7 +22,7 @@ set termguicolors
call plug#begin('~/.vim/plugged') call plug#begin('~/.vim/plugged')
" Style " Style
Plug 'joshdick/onedark.vim' Plug 'bluz71/vim-nightfly-colors', { 'as': 'nightfly', 'branch': 'legacy' }
" Language support " Language support
Plug 'maxmellon/vim-jsx-pretty' Plug 'maxmellon/vim-jsx-pretty'
@ -44,7 +44,6 @@ Plug 'nvim-telescope/telescope-symbols.nvim'
Plug 'mcataford/ale' Plug 'mcataford/ale'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
call plug#end() call plug#end()
"""""""""""""""" """"""""""""""""
@ -56,6 +55,6 @@ let mapleader=" "
nmap <leader>f <cmd>Telescope live_grep<CR> nmap <leader>f <cmd>Telescope live_grep<CR>
nmap <leader>F <cmd>Telescope grep_string<CR> nmap <leader>F <cmd>Telescope grep_string<CR>
colorscheme onedark colorscheme nightfly