diff --git a/bin/actions/update.sh b/bin/actions/update.sh index 5fb518f..c0fbc1d 100755 --- a/bin/actions/update.sh +++ b/bin/actions/update.sh @@ -54,26 +54,43 @@ groups() { ensure_user_groups } +ensure_symlink() { + source=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-values config.symlinks.$1.source) &>/dev/null + target=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.symlinks.$1.target) &>/dev/null + + # Based on the OS_TYPE, get the correct source + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + source=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.symlinks.$1.sources.linux) &>/dev/null + elif [[ "$OSTYPE" == "darwin"* ]]; then + source=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.symlinks.$1.sources.macos) &>/dev/null + fi + + # Try adding a default source if the OS_TYPE specific source is empty + if [ -z "$source" ]; then + source=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.symlinks.$1.source) &>/dev/null + fi + + # If this is still empty, we can't continue and should throw up an error + if [ -z "$source" ]; then + printfe "%s\n" "red" " - No valid source defined for $1" + return + fi + + check_or_make_symlink $source $target +} + symlinks() { #################################################################################################### # Update symlinks #################################################################################################### - printfe "%s\n" "cyan" "Updating config symlinks..." - check_or_make_symlink ~/.zshrc ~/dotfiles/.zshrc - check_or_make_symlink ~/.config/Code/User/settings.json ~/dotfiles/vscode/settings.json - check_or_make_symlink ~/.config/starship.toml ~/dotfiles/config/starship.toml - - if [[ "$OSTYPE" == "darwin"* ]]; then - check_or_make_symlink ~/.gitconfig ~/dotfiles/config/gitconfig.macos - else - check_or_make_symlink ~/.gitconfig ~/dotfiles/config/gitconfig.linux - fi - - check_or_make_symlink ~/.ssh/config ~/dotfiles/config/ssh/config - check_or_make_symlink ~/.ssh/config.d ~/dotfiles/config/ssh/config.d - check_or_make_symlink ~/.config/alacritty/alacritty.toml ~/dotfiles/config/alacritty.toml + # Load symlinks from config file + symlinks=($(cat $HOME/dotfiles/config/config.yaml | shyaml keys config.symlinks)) + printfe "%s\n" "cyan" "Updating symlinks..." + for symlink in $symlinks; do + ensure_symlink $symlink + done } sys_packages() { diff --git a/bin/helpers/functions.sh b/bin/helpers/functions.sh index 345c4df..66c396f 100755 --- a/bin/helpers/functions.sh +++ b/bin/helpers/functions.sh @@ -164,7 +164,8 @@ check_or_make_symlink() { fi mkdir -p $(dirname $1) ln -s $2 $1 - printfe "%s\n" "green" " - Created symlink $1 -> $2" + printfe "%s\n" "green" " - Created symlink $2 -> $1" + return fi # Confirm the symlink that already exists point to the correct location @@ -177,9 +178,20 @@ check_or_make_symlink() { rm $1 mkdir -p $(dirname $1) ln -s $2 $1 - printfe "%s\n" "green" " Created symlink $1 -> $2" + printfe "%s\n" "green" " Created symlink $2 -> $1" + return fi fi + + if [ ! -L $1 ]; then + printfe "%s\n" "red" " - Failed to create symlink $2 -> $1" + return + fi + + printfe "%s" "green" " - OK: " + printfe "%-30s" "blue" "$1" + printfe "%s" "cyan" " -> " + printfe "%-30s\n" "blue" "$2" } clear_line() { diff --git a/config/alacritty.toml b/config/alacritty.toml index c997975..e196c06 100644 --- a/config/alacritty.toml +++ b/config/alacritty.toml @@ -29,6 +29,7 @@ render_timer = false [font] size = 14.0 +family = "Hack Nerd Font" [font.bold] family = "Hack Nerd Font" diff --git a/config/config.yaml b/config/config.yaml index b5c0d50..80c8f38 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,4 +1,46 @@ config: + # Symbolic links to create + symlinks: + # Gitconfig + gitconfig: + sources: + macos: ~/dotfiles/config/gitconfig.macos + linux: ~/dotfiles/config/gitconfig.linux + target: ~/.gitconfig + + # SSH config + ssh: + source: ~/dotfiles/config/ssh/config + target: ~/.ssh/config + + ssh_config_d: + source: ~/dotfiles/config/ssh/config.d + target: ~/.ssh/config.d + + # Zshrc + zshrc: + source: ~/dotfiles/.zshrc + target: ~/.zshrc + + # VSCode settings + vscode: + source: ~/dotfiles/vscode/settings.json + target: ~/.config/Code/User/settings.json + + vscode-argv: + source: ~/dotfiles/vscode/argv.json + target: ~/.vscode/argv.json + + # Starship config + starship: + source: ~/dotfiles/config/starship.toml + target: ~/.config/starship.toml + + # Alacritty config + alacritty: + source: ~/dotfiles/config/alacritty.toml + target: ~/.config/alacritty/alacritty.toml + # What groups users should be added user_groups: menno: @@ -109,7 +151,7 @@ config: - vim - sl - jq - - just +# - just - libglvnd-dev - libwayland-dev - libseat-dev @@ -159,4 +201,4 @@ config: - libffi-dev - tk-dev - alacritty - \ No newline at end of file + diff --git a/vscode/argv.json b/vscode/argv.json new file mode 100644 index 0000000..eea6f2d --- /dev/null +++ b/vscode/argv.json @@ -0,0 +1,3 @@ +{ + "enable-crash-reporter": false, +} diff --git a/vscode/settings.json b/vscode/settings.json index 4770454..dcddea0 100755 --- a/vscode/settings.json +++ b/vscode/settings.json @@ -17,5 +17,5 @@ "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, - "git.openRepositoryInParentFolders": "never", + "git.openRepositoryInParentFolders": "always", } \ No newline at end of file