From bc0f75e65c5350c510fc2de265b86cd9afdece75 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Thu, 29 Feb 2024 00:50:03 -0500 Subject: [PATCH] feat: show diffs before injecting managed blocks in shell+editor config --- bootstrap.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 3ee55b9..4780841 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -19,6 +19,8 @@ # ########################################################### +CURRENT_TIME=$(date +%T) + ########################################################### # # 1. Helpers and utilities @@ -205,35 +207,40 @@ inject_shell_configuration() { echo "Setting up shell configuration extras..." if ! grep -q "$BLOCK_DELIMITER_PATTERN" < "$SHELL_CONFIG_PATH"; then + TEMPORARY_PATH=/tmp/init_vim_$CURRENT_TIME + copy_file "$SHELL_CONFIG_PATH" "$TEMPORARY_PATH" printf "# %s:start\nsource %s/files/shell_extras\n# %s:end" \ "$BLOCK_DELIMITER_PATTERN" "$WORKING_PATH" "$BLOCK_DELIMITER_PATTERN" \ - >> "$SHELL_CONFIG_PATH" + >> "$TEMPORARY_PATH" + copy_file "$TEMPORARY_PATH" "$SHELL_CONFIG_PATH" echo "✅ Added managed block to $SHELL_CONFIG_PATH" + rm "$TEMPORARY_PATH" else echo "No changes to apply!" fi - - EDITOR_CONFIG=$HOME/.config/nvim - EDITOR_CONFIG_FILE=$EDITOR_CONFIG/init.vim } # Injects a managed block in the vim configuration inject_vim_configuration() { pre_step "Inject managed block in vim configuration" + EDITOR_CONFIG=$HOME/.config/nvim + EDITOR_CONFIG_FILE=$EDITOR_CONFIG/init.vim WORKING_PATH=$(git rev-parse --show-toplevel) - + if [[ -f $EDITOR_CONFIG_FILE ]]; then echo "Setting up NVIM configuration extras..." if ! grep -q "$BLOCK_DELIMITER_PATTERN" < "$EDITOR_CONFIG_FILE"; then + TEMPORARY_PATH=/tmp/init_vim_$CURRENT_TIME 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 + "$BLOCK_DELIMITER_PATTERN" "$WORKING_PATH" "$BLOCK_DELIMITER_PATTERN" \ + >> "$TEMPORARY_PATH" + cat "$EDITOR_CONFIG_FILE" >> "$TEMPORARY_PATH" - mv "$EDITOR_CONFIG_FILE" "$EDITOR_CONFIG_FILE".old - mv "$EDITOR_CONFIG_FILE".new "$EDITOR_CONFIG_FILE" + copy_file "$EDITOR_CONFIG_FILE" "$EDITOR_CONFIG_FILE".old + copy_file "$TEMPORARY_PATH" "$EDITOR_CONFIG_FILE" echo "✅ Added managed block to $EDITOR_CONFIG_FILE" + rm "$TEMPORARY_PATH" else echo "No changes to apply!" fi