Skip to content

Commit

Permalink
add setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Chen committed Mar 26, 2024
1 parent dd437cb commit c173ec5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Usage
1. Install [oh-my-zsh](https://ohmyz.sh/#install) and set zsh as your default shell
2. `source setup.sh` which will setup symbolic links for you. When you update this repo, the file contents will be updated
3. Open a new terminal to check for the updated config, enjoy!
43 changes: 43 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Automatically get the directory from which the script is run
REPO_DIR=$(pwd)

# Define the location of the files in the home directory
VIMRC="$HOME/.vimrc"
TMUX_CONF="$HOME/.tmux.conf"

# Backup .vimrc if it exists
if [ -f "$VIMRC" ]; then
echo "Backing up .vimrc to .vimrc.bak"
cp "$VIMRC" "${VIMRC}.bak"
fi

# Backup .tmux.conf if it exists
if [ -f "$TMUX_CONF" ]; then
echo "Backing up .tmux.conf to .tmux.conf.bak"
cp "$TMUX_CONF" "${TMUX_CONF}.bak"
fi

# Backup .zshrc if it exists
if [ -f "$HOME/.zshrc" ]; then
echo "Backing up .zshrc to .zshrc.bak"
cp "$HOME/.zshrc" "$HOME/.zshrc.bak"
fi

# Create symbolic links for .vimrc and .tmux.conf
ln -sf "$REPO_DIR/config/.vimrc" "$HOME/.vimrc"
ln -sf "$REPO_DIR/config/.tmux.conf" "$HOME/.tmux.conf"

# Replace the ZSH_CUSTOM line with the correct path
ZSHRC="$REPO_DIR/config/.zshrc"
ZSH_CUSTOM_LINE="ZSH_CUSTOM=$REPO_DIR/config"
sed -i "/^ZSH_CUSTOM=/c\\$ZSH_CUSTOM_LINE" "$ZSHRC" || echo "$ZSH_CUSTOM_LINE" >> "$ZSHRC"

# Create a symbolic link for .zshrc
ln -sf "$ZSHRC" "$HOME/.zshrc"

# Ignore changes in .zshrc in the future
git update-index --assume-unchanged "config/.zshrc"

echo "Setup completed successfully."

0 comments on commit c173ec5

Please sign in to comment.