| 1 | |
| 2 | |
| 3 | dotfiles=( |
| 4 | "hypr:$HOME/.config/hypr" |
| 5 | "kitty:$HOME/.config/kitty" |
| 6 | "nvim:$HOME/.config/nvim" |
| 7 | "pipewire:$HOME/.config/pipewire" |
| 8 | "tmux-powerline:$HOME/.config/tmux-powerline" |
| 9 | "tmux:$HOME/.config/tmux" |
| 10 | "waybar:$HOME/.config/waybar" |
| 11 | "wezterm:$HOME/.config/wezterm" |
| 12 | "pipewire:$HOME/.config/pipewire" |
| 13 | "yabai:$HOME/.config/yabai" |
| 14 | "skhd:$HOME/.config/skhd" |
| 15 | "btop:$HOME/.config/btop" |
| 16 | "broot:$HOME/.config/broot" |
| 17 | "fastfetch:$HOME/.config/fastfetch" |
| 18 | "oh-my-zsh:$HOME/.oh-my-zsh" |
| 19 | "oh-my-zsh/zshrc:$HOME/.zshrc" |
| 20 | "oh-my-zsh/p10k.zsh:$HOME/.p10k.zsh" |
| 21 | ) |
| 22 | |
| 23 | |
| 24 | |
| 25 | iter() { |
| 26 | local src |
| 27 | local dst |
| 28 | for pair in "${dotfiles[@]}"; do |
| 29 | IFS=":" read -r src dst <<<"$pair" |
| 30 | "$1" "$src" "$dst" |
| 31 | done |
| 32 | } |
| 33 | |
| 34 | backup_dir="$PWD/backup" |
| 35 | |
| 36 | |
| 37 | |
| 38 | backup_pair() { |
| 39 | local l="$1" |
| 40 | local r="$2" |
| 41 | local src="$r" |
| 42 | local dst="$backup_dir/$l" |
| 43 | local cmd="$src not found" |
| 44 | if [ -L "$src" ]; then |
| 45 | cmd="$src is already a link" |
| 46 | elif [ -d "$src" ]; then |
| 47 | cmd="mkdir -p $dst && cp -r $src $dst" |
| 48 | eval "$cmd" |
| 49 | elif [ -f "$src" ]; then |
| 50 | cmd="cp $src $dst" |
| 51 | eval "$cmd" |
| 52 | fi |
| 53 | echo "-> $cmd" |
| 54 | } |
| 55 | |
| 56 | |
| 57 | backup() { |
| 58 | echo "Backing up current config files into $backup_dir" |
| 59 | if [ -d "$backup_dir" ]; then |
| 60 | rm -rf "$backup_dir" |
| 61 | fi |
| 62 | mkdir "$backup_dir" |
| 63 | iter backup_pair |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 68 | link_pair() { |
| 69 | local src="$PWD/$1" |
| 70 | local target="$2" |
| 71 | local cmd="rm -rf $target && ln -s $src $target" |
| 72 | eval "$cmd" |
| 73 | echo "-> $cmd" |
| 74 | } |
| 75 | |
| 76 | |
| 77 | link() { |
| 78 | echo "Destroying existing config and replacing with symbolic link to dotfile config" |
| 79 | iter link_pair |
| 80 | } |
| 81 | |
| 82 | |
| 83 | install() { |
| 84 | echo -e "Freezing zshrc to hide pushes in the future\n" |
| 85 | |
| 86 | git update-index --assume-unchanged oh-my-zsh/zshrc |
| 87 | |
| 88 | backup |
| 89 | echo |
| 90 | link |
| 91 | echo |
| 92 | echo "Checking for missing installs" |
| 93 | if [ ! -d ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions ]; then |
| 94 | git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" |
| 95 | fi |
| 96 | if [ ! -d ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting ]; then |
| 97 | git clone https://github.com/zsh-users/zsh-syntax-highlighting "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" |
| 98 | fi |
| 99 | if [ ! -d ~/.oh-my-zsh/custom/themes/powerlevel10k ]; then |
| 100 | git clone https://github.com/romkatv/powerlevel10k.git "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" |
| 101 | fi |
| 102 | if ! which go >/dev/null 2>&1; then echo "Please install golang"; fi |
| 103 | if ! which rustup >/dev/null 2>&1; then echo "Please install rust"; fi |
| 104 | if ! which nvm >/dev/null 2>&1; then echo "Please install nvm"; fi |
| 105 | if ! which fzf >/dev/null 2>&1; then echo "Please install fzf"; fi |
| 106 | if ! which lsd >/dev/null 2>&1; then echo "Please install lsd"; fi |
| 107 | if ! which conda >/dev/null 2>&1; then echo "Please install anaconda or miniconda"; fi |
| 108 | if ! which yabai >/dev/null 2>&1; then echo "If using mac, please install yubai"; fi |
| 109 | if ! which skhd >/dev/null 2>&1; then echo "If using mac, please install skhd"; fi |
| 110 | if ! which bat >/dev/null 2>&1; then echo "Please install bat"; fi |
| 111 | if ! which lazygit >/dev/null 2>&1; then echo "Please install lazygit"; fi |
| 112 | if ! which btop >/dev/null 2>&1; then echo "Please install btop"; fi |
| 113 | if ! which fastfetch >/dev/null 2>&1; then echo "Please install fastfetch"; fi |
| 114 | if ! which zsh >/dev/null 2>&1; then echo "Please install zsh"; fi |
| 115 | } |
| 116 | |
| 117 | |
| 118 | case "$1" in |
| 119 | backup) backup ;; |
| 120 | link) link ;; |
| 121 | install) install ;; |
| 122 | *) echo "Usage: $0 <backup|link|install>" ;; |
| 123 | esac |