feat: show diffs before injecting managed blocks in shell+editor config
This commit is contained in:
parent
7b6aa29a78
commit
bc0f75e65c
1 changed files with 17 additions and 10 deletions
25
bootstrap.sh
25
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
|
||||
|
|
Loading…
Reference in a new issue