From 159243c3f93c303f7321c8e3bc61587961968c0f Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Thu, 25 Jan 2024 20:54:24 -0500 Subject: [PATCH] Implement replacing add-export --- copy.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/copy.sh b/copy.sh index 5505217..bc21e94 100755 --- a/copy.sh +++ b/copy.sh @@ -38,9 +38,16 @@ echo "$dotfiles" | while read -r dotfile; do done function add-export { - if ! grep "$1" "$HOME/.zsh_local" &> /dev/null; then - echo "$1\"$2\"" >> "$HOME/.zsh_local" + local final="$1\"$2\"" + if grep "$final" "$HOME/.zsh_local" &> /dev/null; then + return fi + if grep "$1" "$HOME/.zsh_local" &> /dev/null; then + echo "Replacing '$(grep "$1" "$HOME/.zsh_local")' with '$final'" + local escaped="$(echo "$1" | sed 's@/@\\/@g')" + sed -i "/$escaped/d" "$HOME/.zsh_local" + fi + echo "$final" >> "$HOME/.zsh_local" } add-export "export DOT_DIR=" "$SCRIPT_DIR"