Przeglądaj źródła

setup.sh: improved the setup script

rain.esteva 1 rok temu
rodzic
commit
b5bf31cd16
1 zmienionych plików z 16 dodań i 5 usunięć
  1. 16 5
      setup.sh

+ 16 - 5
setup.sh

@@ -6,10 +6,20 @@ chmod 660 ./*
 chmod 660 "$HOME/.bashrc"
 chmod 770 "$HOME/dots"
 
-# Aliases
-echo "# Setup Aliases" >> "$HOME/.bashrc"
-echo "source $HOME/dots/aliases" >> "$HOME/.bashrc" && source "$HOME/.bashrc"
-echo "source $HOME/dots/seafly-prompt" >> "$HOME/.bashrc" && source "$HOME/.bashrc"
+function add_string_to_file() {
+    # Checks if a string is in a file
+    # adds it if it isn't in that file
+    local file="$1"
+    local string="$2"
+
+    if ! grep -q "$string" "$file"; then
+        echo "$string" >> "$file"
+    fi
+}
+
+add_string_to_file "$HOME/.bashrc" "# Setup Aliases"
+add_string_to_file "$HOME/.bashrc" "source $HOME/dots/aliases" && source "$HOME/.bashrc"
+add_string_to_file "$HOME/.bashrc" "source $HOME/dots/seafly-prompt" && source "$HOME/.bashrc"
 
 # NVIM
 mkdir -p "$HOME/.config/nvim/"
@@ -19,4 +29,5 @@ cp "./nvim" "$HOME/.config/nvim/init.vim"
 cp "./tmux.conf" "$HOME/.tmux.conf"
 
 # Scripts
-echo "bash $HOME/dots/life.sh 1993-07-21 control" >> "$HOME/.bashrc" && source "$HOME/.bashrc"
+add_string_to_file "$HOME/.bashrc" "# Scripts"
+add_string_to_file "$HOME/.bashrc" "bash $HOME/dots/life.sh 1993-07-21 control" && source "$HOME/.bashrc"