Skip to content

Commit

Permalink
fix: Fix base path for scripts (#49)
Browse files Browse the repository at this point in the history
- use DOTPATH if it exists
- minor visual changes

## Summary by Sourcery

Fix the base path for scripts by using DOTPATH if available and enhance
visual feedback with updated echo statements.

Bug Fixes:
- Fix the base path for scripts by using the DOTPATH environment
variable if it exists, otherwise defaulting to the script's directory.

Enhancements:
- Improve visual feedback in scripts by updating echo statements with
new color codes.
  • Loading branch information
martimlobao authored Nov 5, 2024
1 parent de33b09 commit e9993f4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
5 changes: 4 additions & 1 deletion dock.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

# Root is $DOTPATH if it exists, otherwise the directory of this script
root=$(realpath "${DOTPATH:-$(dirname "$(realpath "$0")")}")

# Source the bash_traceback.sh file
source "$(dirname "$0")/bash_traceback.sh"
source "$root/bash_traceback.sh"

###############################################################################
# FUNCTIONS FOR MANIPULATING MACOS DOCK #
Expand Down
5 changes: 4 additions & 1 deletion dotsync.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

# Root is $DOTPATH if it exists, otherwise the directory of this script
root=$(realpath "${DOTPATH:-$(dirname "$(realpath "$0")")}")

# Source the bash_traceback.sh file
source "$(dirname "$0")/bash_traceback.sh"
source "$root/bash_traceback.sh"

###############################################################################
# UPDATE DOTFILES #
Expand Down
16 changes: 11 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

# Root is $DOTPATH if it exists, otherwise the directory of this script
root=$(realpath "${DOTPATH:-$(dirname "$(realpath "$0")")}")

# Source the bash_traceback.sh file
source "$(dirname "$0")/bash_traceback.sh"
source "$root/bash_traceback.sh"

###############################################################################
# INSTALL APPS AND PACKAGES #
Expand All @@ -17,9 +20,12 @@ fi

# Ensure yq is installed to parse the apps.toml file
if ! command -v yq &> /dev/null; then
echo -e "โฌ‡๏ธ \033[1;34mInstalling yq to parse apps.toml...\033[0m"
brew install yq
fi

apps_toml="$root/apps.toml"

# Initialize arrays to store installed apps
installed_casks=()
installed_formulas=()
Expand Down Expand Up @@ -105,7 +111,7 @@ install () {

brew_sync() {
local toml_apps
toml_apps=$(yq eval 'to_entries | map(.value | to_entries | map(select(.value == "cask" or .value == "formula") | .key)) | flatten | .[]' apps.toml)
toml_apps=$(yq eval 'to_entries | map(.value | to_entries | map(select(.value == "cask" or .value == "formula") | .key)) | flatten | .[]' "$apps_toml")
toml_apps=$(echo "$toml_apps" | sed -E 's|.*/||') # get name from tapped apps (slashes in name)

local missing_formulae
Expand Down Expand Up @@ -141,7 +147,7 @@ brew_sync() {

uv_sync() {
local toml_apps
toml_apps=$(yq eval 'to_entries | map(.value | to_entries | map(select(.value == "uv") | .key)) | flatten | .[]' apps.toml)
toml_apps=$(yq eval 'to_entries | map(.value | to_entries | map(select(.value == "uv") | .key)) | flatten | .[]' "$apps_toml")

local missing_uv_apps
missing_uv_apps=$(comm -23 <(uv tool list | awk '{print $1}' | grep -v '^-*$' | sort) <(echo "$toml_apps" | sort))
Expand Down Expand Up @@ -170,7 +176,7 @@ uv_sync() {

mas_sync() {
local toml_apps
toml_apps=$(yq eval 'to_entries | map(.value | to_entries | map(select(.value == "mas") | .key)) | flatten | .[]' apps.toml)
toml_apps=$(yq eval 'to_entries | map(.value | to_entries | map(select(.value == "mas") | .key)) | flatten | .[]' "$apps_toml")

local installed_mas_apps
installed_mas_apps=$(mas list | sed -E 's/^([0-9]+)[[:space:]]+(.*)[[:space:]]+\(.*/\1 \2/' | sort)
Expand Down Expand Up @@ -216,7 +222,7 @@ populate_installed_apps

# Use yq to parse the TOML file and store the output in a variable
# shellcheck disable=2016
parsed_toml=$(yq e 'to_entries | .[] | .key as $category | .value | to_entries[] | [$category, .key, .value] | @tsv' apps.toml)
parsed_toml=$(yq e 'to_entries | .[] | .key as $category | .value | to_entries[] | [$category, .key, .value] | @tsv' "$apps_toml")

# Install apps from each category in the apps.toml file
current_category=""
Expand Down
5 changes: 4 additions & 1 deletion local.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

# Root is $DOTPATH if it exists, otherwise the directory of this script
root=$(realpath "${DOTPATH:-$(dirname "$(realpath "$0")")}")

# Source the bash_traceback.sh file
source "$(dirname "$0")/bash_traceback.sh"
source "$root/bash_traceback.sh"

###############################################################################
# LOCAL SETTINGS AND VARIABLES #
Expand Down
5 changes: 4 additions & 1 deletion macos.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

# Root is $DOTPATH if it exists, otherwise the directory of this script
root=$(realpath "${DOTPATH:-$(dirname "$(realpath "$0")")}")

# Source the bash_traceback.sh file
source "$(dirname "$0")/bash_traceback.sh"
source "$root/bash_traceback.sh"

echo -e "\033[1;34m๐Ÿ’ป Setting macOS preferences...\033[0m"

Expand Down
22 changes: 15 additions & 7 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env bash

# Root is $DOTPATH if it exists, otherwise the directory of this script
root=$(realpath "${DOTPATH:-$(dirname "$(realpath "$0")")}")

# Source the bash_traceback.sh file
source "$(dirname "$0")/bash_traceback.sh"
source "$root/bash_traceback.sh"

###############################################################################
# Install Homebrew #
###############################################################################
echo -e "\033[1;34m๐Ÿบ Installing Homebrew...\033[0m"
echo
echo -e "\033[1;33m๐Ÿบ Installing Homebrew...\033[0m"
if ! command -v brew &> /dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo -e "๐Ÿป \033[1;32mHomebrew installed.\033[0m"
Expand All @@ -17,32 +21,36 @@ fi
###############################################################################
# Install dotfiles #
###############################################################################
sleep 1
echo
echo -e "\033[1;33m๐Ÿš€ Running dotsync.sh...\033[0m"
sleep 1
./dotsync.sh "${1:-}"

###############################################################################
# Local settings and variables #
###############################################################################
sleep 1
echo
echo -e "\033[1;33m๐Ÿš€ Running local.sh...\033[0m"
sleep 1
./local.sh "${1:-}"

###############################################################################
# macOS preferences #
###############################################################################
# sleep 1
# echo
# echo -e "\033[1;33m๐Ÿš€ Running macos.sh...\033[0m"
# sudo ./macos.sh

###############################################################################
# Install apps and software #
###############################################################################
sleep 1
echo
./install.sh "${1:-}"
echo -e "\033[1;33m๐Ÿš€ Running install.sh...\033[0m"
sleep 1
./install.sh "${1:-}"
echo
echo -e "\033[1;33m๐Ÿš€ Running dock.sh...\033[0m"
sleep 1
./dock.sh

echo
Expand Down

0 comments on commit e9993f4

Please sign in to comment.