all repos

dotfiles @ 696e533

i use rach linux btw
1 files changed, 20 insertions(+), 22 deletions(-)
bootstrap: refactor
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2025-09-20 17:02:48 +0300
Parent: e1d3d92
M bootstrap
ยทยทยท
                1
                1
                 #!/usr/bin/env bash

              
                2
                
                -set -e

              
                
                2
                +set -euo pipefail

              
                3
                3
                 

              
                4
                
                -# the path to dir where the script and dotfiles are located

              
                5
                
                -# set to specific path so this script can be run from anywhere

              
                6
                
                -dotfilesPath="$HOME/.dotfiles"

              
                
                4
                +: "${DOTFILES_PATH:=$HOME/.dotfiles}"

              
                
                5
                +: "${DOTFILES_HOME:=$HOME}"

              
                7
                6
                 

              
                8
                
                -h() { # ln -sf and logs path

              
                9
                
                -    ln -sf "$1" "$2"

              
                10
                
                -    echo "[ln] $2"

              
                
                7
                +lnk() {

              
                
                8
                +  [[ -e "$2" ]] &&

              
                
                9
                +    echo -e "\e[31m[ln] $1 (overwritten)\e[0m" ||

              
                
                10
                +    echo -e "\r\e[32m[ln] $2\e[0m"

              
                
                11
                +  ln -sf "$1" "$2"

              
                11
                12
                 }

              
                12
                13
                 

              
                13
                
                -mkd() { # mkdir -p and logs path

              
                14
                
                -    mkdir -p "$1"

              
                15
                
                -    echo "[mkdir] $1"

              
                
                14
                +dr() {

              
                
                15
                +  mkdir -p "$1"

              
                
                16
                +  echo -e "\e[34m[mkdir] $1\e[0m"

              
                16
                17
                 }

              
                17
                18
                 

              
                18
                
                -create_links_in_dir_recursively() {

              
                19
                
                -  local base_dir="$dotfilesPath/$1"

              
                
                19
                +dotify() {

              
                
                20
                +  local base_dir="$DOTFILES_PATH/$1"

              
                20
                21
                   local target_dir="$2"

              
                21
                22
                 

              
                22
                
                -  find "$base_dir/" -type d | while read -r dir; do

              
                23
                
                -    mkd "$HOME/$target_dir${dir#"$base_dir"}"

              
                24
                
                -    find "$dir" -maxdepth 1 -type f | while read -r file; do

              
                25
                
                -      h "$file" "$HOME/$target_dir${file#"$base_dir"}"

              
                
                23
                +  find "$base_dir" -type d -print0 | while IFS= read -r -d '' dir; do

              
                
                24
                +    dr "$DOTFILES_HOME/$target_dir${dir#"$base_dir"}"

              
                
                25
                +    find "$dir" -maxdepth 1 -type f -print0 | while IFS= read -r -d '' file; do

              
                
                26
                +      lnk "$file" "$DOTFILES_HOME/$target_dir${file#"$base_dir"}"

              
                26
                27
                     done

              
                27
                28
                   done

              
                28
                29
                 }

              
                29
                30
                 

              
                30
                
                -h "$dotfilesPath/tmux.conf" "$HOME/.tmux.conf"

              
                31
                
                -

              
                32
                
                -mkd "$HOME/bin/"

              
                33
                
                -find "$dotfilesPath/bin" -type f -exec ln -sf {} "$HOME/bin/" \;

              
                34
                
                -

              
                35
                
                -create_links_in_dir_recursively "config" ".config"

              
                
                31
                +# let the lord do the linking

              
                
                32
                +dotify "config" ".config"

              
                
                33
                +dotify "bin" "bin"