-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00-script-environment.sh
executable file
·138 lines (113 loc) · 4.59 KB
/
00-script-environment.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
#!/bin/bash
# ----------------------
# 00-script-environment.sh
# ----------------------
#!/bin/bash
set -e
echo "====================================================="
echo "Setting up custom script environment..."
echo "====================================================="
# Create necessary directories
mkdir -p ~/code/scripts
# Change to the scripts directory
cd ~/code/scripts
# Define script files and their permissions
SCRIPT_FILES=("init.sh" "vars.sh" "paths.sh" "aliases.sh" "functions.sh" "cowsay_fortune_lolcat.sh")
TOOL_CONFIG_FILES=("nvm.sh" "conda.sh" "gcloud.sh")
SCRIPT_PERMISSIONS=755
# Create init.sh with dynamic paths and modular structure
cat > init.sh << 'EOF'
#!/bin/bash
## Determine script location regardless of source/execution context
if [ -n "$ZSH_VERSION" ]; then
# For zsh
SCRIPTS_DIR="${0:A:h}"
if [[ "$SCRIPTS_DIR" == "." ]]; then
# When sourced from .zshrc
SCRIPTS_DIR="$HOME/code/scripts"
fi
elif [ -n "$BASH_VERSION" ]; then
# For bash
SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
else
# Fallback to absolute path
SCRIPTS_DIR="$HOME/code/scripts"
fi
## Core environment
[[ ! -f "$SCRIPTS_DIR/vars.sh" ]] || source "$SCRIPTS_DIR/vars.sh"
[[ ! -f "$SCRIPTS_DIR/paths.sh" ]] || source "$SCRIPTS_DIR/paths.sh"
## Tool-specific configs (only loaded if tool is installed)
[[ ! -d "$HOME/.nvm" ]] || [[ ! -f "$SCRIPTS_DIR/nvm.sh" ]] || source "$SCRIPTS_DIR/nvm.sh"
[[ ! -d "$HOME/miniconda3" ]] || [[ ! -f "$SCRIPTS_DIR/conda.sh" ]] || source "$SCRIPTS_DIR/conda.sh"
[[ ! -f "$SCRIPTS_DIR/gcloud.sh" ]] || source "$SCRIPTS_DIR/gcloud.sh"
## Fun terminal additions
[[ ! -f "$SCRIPTS_DIR/cowsay_fortune_lolcat.sh" ]] || source "$SCRIPTS_DIR/cowsay_fortune_lolcat.sh"
## Shell customizations
[[ ! -f "$SCRIPTS_DIR/zsh_plugins.sh" ]] || source "$SCRIPTS_DIR/zsh_plugins.sh"
[[ ! -f "$SCRIPTS_DIR/aliases.sh" ]] || source "$SCRIPTS_DIR/aliases.sh"
[[ ! -f "$SCRIPTS_DIR/functions.sh" ]] || source "$SCRIPTS_DIR/functions.sh"
EOF
# Create vars.sh with core environment variables
if [ ! -f ~/code/scripts/vars.sh ] || ! grep -q "Core environment variables" ~/code/scripts/vars.sh; then
cat > vars.sh << 'EOF'
#!/bin/bash
# Core environment variables
export EDITOR=vim
export VISUAL=vim
EOF
else
echo "vars.sh already exists."
fi
# Create paths.sh for PATH additions
if [ ! -f ~/code/scripts/paths.sh ] || ! grep -q "PATH additions" ~/code/scripts/paths.sh; then
cat > paths.sh << 'EOF'
#!/bin/bash
export PATH="/opt/homebrew/bin:$PATH"
export PATH="$HOME/bin:$PATH"
EOF
else
echo "paths.sh already exists."
fi
# Create empty tool config files
for file in "${TOOL_CONFIG_FILES[@]}"; do
touch "$file"
echo "#!/bin/bash" > "$file"
echo "" >> "$file"
echo "# Configuration for ${file%.sh} will be added here during installation" >> "$file"
done
# Download gist files using curl
if [ ! -f ~/code/scripts/aliases.sh ] || ! grep -q "alias lsd=" ~/code/scripts/aliases.sh; then
echo "Downloading aliases.sh from your GitHub gist..."
curl -s https://gist.githubusercontent.com/skwid138/15041e4c3d4992420ae93b25cfadb828/raw > aliases.sh
else
echo "aliases.sh already exists."
fi
if [ ! -f ~/code/scripts/functions.sh ] || ! grep -q "#!/bin/bash" ~/code/scripts/functions.sh; then
echo "Downloading functions.sh from your GitHub gist..."
curl -s https://gist.githubusercontent.com/skwid138/8b8de484483f092bb917f07dd0ee6fb0/raw > functions.sh
else
echo "functions.sh already exists."
fi
if [ ! -f ~/code/scripts/cowsay_fortune_lolcat.sh ] || ! grep -q "cowsay character" ~/code/scripts/cowsay_fortune_lolcat.sh; then
echo "Downloading cowsay_fortune_lolcat.sh from your GitHub gist..."
curl -s https://gist.githubusercontent.com/skwid138/ff0df971ff1d81b734fb155630f5e499/raw/cowsay_fortune_lolcat.sh > cowsay_fortune_lolcat.sh
else
echo "cowsay_fortune_lolcat.sh already exists."
fi
# Set permissions for all script files
for script in "${SCRIPT_FILES[@]}" "${TOOL_CONFIG_FILES[@]}"; do
chmod ${SCRIPT_PERMISSIONS} "$script"
echo "Set permissions for $script to ${SCRIPT_PERMISSIONS}"
done
# Update .zshrc to source the init.sh file
if ! grep -q "Source custom scripts" ~/.zshrc; then
echo "" >> ~/.zshrc
echo "### Source custom scripts ###" >> ~/.zshrc
echo "[[ ! -f ~/code/scripts/init.sh ]] || source ~/code/scripts/init.sh" >> ~/.zshrc
echo "Updated ~/.zshrc to source your custom scripts"
else
echo "~/.zshrc already contains custom scripts sourcing"
fi
echo "====================================================="
echo "Custom script environment setup complete!"
echo "====================================================="