Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ error() {
# command -v git >/dev/null 2>&1 || error "Git is required but not installed. https://git-scm.com/downloads"
# }

# Create a symbolic link, removing existing file/link if necessary
# Create a symbolic link
# @param $1 Source file path
# @param $2 Destination link path
safe_link() {
Expand All @@ -47,10 +47,10 @@ safe_link() {
ln -s "$src" "$dest"
}

# Copy a directory, removing existing directory if necessary
# Copy a directory
# @param $1 Source directory path
# @param $2 Destination directory path
safe_copy_dir() {
copy_dir() {
local src="$1"
local dest="$2"

Expand All @@ -59,8 +59,8 @@ safe_copy_dir() {
fi

if [ -d "$dest" ]; then
log "Found $dest - removing..."
rm -rf "$dest"
log "Found $dest - renaming..."
mv "$dest" "$dest.old"
fi

log "Copying directory $src to $dest"
Expand All @@ -69,6 +69,28 @@ safe_copy_dir() {
fi
}

# Copy a file
# @param $1 Source file path
# @param $2 Destination file path
copy_file() {
local src="$1"
local dest="$2"

if [ ! -f "$src" ]; then
error "Source file $src does not exist!"
fi

if [ -f "$dest" ]; then
log "Found $dest - renaming..."
mv "$dest" "$dest.old"
fi

log "Copying file $src to $dest"
if ! cp "$src" "$dest"; then
error "Failed to copy file $src to $dest"
fi
}

# Install Homebrew if not already installed
install_brew() {
if ! command -v brew >/dev/null 2>&1; then
Expand Down Expand Up @@ -105,17 +127,17 @@ install_deno() {

# Configure Git settings by linking gitconfig file
setup_git() {
safe_link "$DIR/git/.gitconfig" "$HOME/.gitconfig"
safe_link "$DIR/git/.gitignore" "$HOME/.gitignore"
safe_link "$DIR/git/.gitattributes" "$HOME/.gitattributes"
copy_file "$DIR/git/.gitconfig" "$HOME/.gitconfig"
copy_file "$DIR/git/.gitignore" "$HOME/.gitignore"
copy_file "$DIR/git/.gitattributes" "$HOME/.gitattributes"
}

# Configure Zsh settings by linking various configuration files
setup_zsh() {
safe_link "$DIR/zsh/.zshrc" "$HOME/.zshrc"
safe_link "$DIR/zsh/themes/dracula.zsh-theme" "$HOME/.oh-my-zsh/themes/dracula.zsh-theme"
safe_link "$DIR/zsh/aliases.zsh" "$HOME/.oh-my-zsh/custom/aliases.zsh"
safe_link "$DIR/zsh/custom-functions" "$HOME/.oh-my-zsh/plugins/custom-functions"
copy_file "$DIR/zsh/.zshrc" "$HOME/.zshrc"
copy_dir "$DIR/zsh/themes" "$HOME/.oh-my-zsh/themes"
copy_file "$DIR/zsh/aliases.zsh" "$HOME/.oh-my-zsh/custom/aliases.zsh"
copy_dir "$DIR/zsh/custom-functions" "$HOME/.oh-my-zsh/plugins/custom-functions"
}

# Install global NPM packages required for development
Expand All @@ -128,7 +150,7 @@ install_global_npm_pkg() {

# Configure NPM settings and install global packages
setup_npm() {
safe_link "$DIR/.npmrc" "$HOME/.npmrc"
copy_file "$DIR/.npmrc" "$HOME/.npmrc"

# Install npm globally without sudo. Based on https://github.com/sindresorhus/guides/blob/main/npm-global-without-sudo.md
if [ -d "$HOME/.npm-packages" ]; then
Expand All @@ -142,7 +164,7 @@ setup_npm() {

# Configure Homebrew and install packages from Brewfile
setup_brew() {
safe_link "$DIR/Brewfile" "$HOME/Brewfile"
copy_file "$DIR/Brewfile" "$HOME/Brewfile"
log "Executing brew bundle install..."
if ! brew bundle install; then
error "Brew bundle install failed"
Expand Down Expand Up @@ -178,7 +200,7 @@ setup_macos() {
if [[ "$OSTYPE" == "darwin"* ]]; then
log "Setting up macOS..."
sh .macos
safe_link "$DIR/extras/duti_picview.config" "$HOME/duti_picview.config" # Configure duti (macOS default application manager) settings
copy_file "$DIR/extras/duti_picview.config" "$HOME/duti_picview.config" # Configure duti (macOS default application manager) settings
fi
}

Expand Down