-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacos_install.sh
147 lines (124 loc) · 3.92 KB
/
macos_install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
set clipboard=unnamedplus#!/bin/bash
# Install script for .zshrc, .vimrc, .ssh/config and their dependencies on macOS
set -e # Exit immediately if a command exits with a non-zero status
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to copy dotfiles or directories with backup
copy_dotfile_or_dir() {
src="$1"
dest="$HOME/$2"
# Check if destination exists
if [ -e "$dest" ]; then
backup_suffix=".bak_$(date +%s)"
echo "Backing up existing $dest to ${dest}${backup_suffix}"
mv "$dest" "${dest}${backup_suffix}"
fi
# Check if source is a directory
if [ -d "$src" ]; then
# Copy directory recursively
cp -r "$src" "$dest"
echo "Copied directory $src to $dest"
else
# Copy file
cp "$src" "$dest"
echo "Copied file $src to $dest"
fi
}
# Get the directory where the script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check for Homebrew and install if not present
if ! command_exists brew; then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> "$HOME/.zprofile"
eval "$(/opt/homebrew/bin/brew shellenv)"
else
echo "Homebrew is already installed."
fi
# Update Homebrew
echo "Updating Homebrew..."
brew update
# Install zsh if not installed
if ! command_exists zsh; then
echo "Installing zsh..."
brew install zsh
else
echo "zsh is already installed."
fi
# Install oh-my-zsh
if [ ! -d "$HOME/.oh-my-zsh" ]; then
echo "Installing oh-my-zsh..."
# Install oh-my-zsh without changing the default shell
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
else
echo "oh-my-zsh is already installed."
fi
# Install fzf
if [ ! -d "$HOME/.fzf" ]; then
echo "Installing fzf..."
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install --all
else
echo "fzf is already installed."
fi
# Install zsh plugins
ZSH_CUSTOM=${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}
# zsh-autosuggestions
if [ ! -d "${ZSH_CUSTOM}/plugins/zsh-autosuggestions" ]; then
echo "Installing zsh-autosuggestions..."
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM}/plugins/zsh-autosuggestions
else
echo "zsh-autosuggestions is already installed."
fi
# zsh-syntax-highlighting
if [ ! -d "${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting" ]; then
echo "Installing zsh-syntax-highlighting..."
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting
else
echo "zsh-syntax-highlighting is already installed."
fi
# fzf-tab
if [ ! -d "${ZSH_CUSTOM}/plugins/fzf-tab" ]; then
echo "Installing fzf-tab..."
git clone https://github.com/Aloxaf/fzf-tab ${ZSH_CUSTOM}/plugins/fzf-tab
else
echo "fzf-tab is already installed."
fi
# Install Vim via Homebrew
if ! command_exists vim; then
echo "Installing Vim..."
brew install vim
else
echo "Vim is already installed."
fi
# Copy configuration files
echo "Copying configuration files..."
# Copy .zshrc
if [ -f "${SCRIPT_DIR}/.zshrc" ]; then
copy_dotfile_or_dir ".zshrc" ".zshrc"
else
echo "Warning: zshrc file not found."
fi
# Copy .vimrc
if [ -f "${SCRIPT_DIR}/.vimrc" ]; then
copy_dotfile_or_dir ".vimrc" ".vimrc"
else
echo "Warning: vimrc file not found."
fi
# Copy .ssh/config
if [ -f "${SCRIPT_DIR}/.ssh/config" ]; then
mkdir -p "$HOME/.ssh"
copy_dotfile_or_dir ".ssh/config" ".ssh/config"
chmod 600 "$HOME/.ssh/config"
else
echo "Warning: .ssh/config file not found."
fi
# Copy .vim directory
if [ -d "${SCRIPT_DIR}/.vim" ]; then
copy_dotfile_or_dir "${SCRIPT_DIR}/.vim" ".vim"
else
echo "Warning: .vim directory not found."
fi