-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell-setup.sh
More file actions
executable file
·543 lines (393 loc) · 15.2 KB
/
shell-setup.sh
File metadata and controls
executable file
·543 lines (393 loc) · 15.2 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#!/bin/bash
# Script set up the shell (zsh)
# Author: Troels Lund
# =============================
# Configure Zsh
# =============================
echo Setting up shell...
# Source the functions from utils.sh
source "$(dirname "$0")/utils.sh"
# Define the path to the .zshrc file
ZSHRC_PATH="$HOME/.zshrc"
# Define ZSH_PATH if not set by Oh-My-Zsh
ZSH_PATH="${ZSH_PATH:-$HOME/.oh-my-zsh}"
# Check if the ZSHRC_PATH exists
if [ ! -f "$ZSHRC_PATH" ]; then
echo "Creating $ZSHRC_PATH..."
touch "$ZSHRC_PATH"
else
echo "$ZSHRC_PATH already exists."
backup_zshrc
fi
# Define ZSH_CUSTOM if not set by Oh-My-Zsh
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
# Make sure the script is run with bash
if [ -z "$BASH_VERSION" ]; then
echo "Please run this script with Bash."
exit 1
fi
# Install Oh-My-Zsh
if [ ! -d "$HOME/.oh-my-zsh" ]; then
echo "Installing Oh-My-Zsh..."
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
else
echo "Oh-My-Zsh already installed."
fi
# Reset Oh-My-Zsh to default settings
reset_ohmyzsh
# Configuration to be added to .zshrc
config_lines=(
'# Set the default user to the current user'
'export DEFAULT_USER=$USER'
)
# Add the configuration lines to .zshrc
add_lines_to_zshrc "${config_lines[@]}"
# Setup Powerlevel10k theme
add_to_zshrc "# Load Powerlevel10k Theme"
echo "ZSH_CUSTOM set to $ZSH_CUSTOM"
# Install Powerlevel10k theme
if [ ! -d "$ZSH_CUSTOM/themes/powerlevel10k" ]; then
echo "Installing Powerlevel10k..."
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
else
echo "Powerlevel10k is already installed."
fi
# Add Powerlevel10k theme to .zshrc
add_lines_to_zshrc \
'# Load Powerlevel10k Theme' \
'ZSH_THEME="powerlevel10k/powerlevel10k"' \
"source $ZSH_CUSTOM/themes/powerlevel10k/powerlevel10k.zsh-theme"
add_to_zshrc "POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true"
# Copy the p10k config file (always override)
P10K_CONFIG="$ZSH_CUSTOM/.p10k.zsh"
echo "📄 Overwriting Powerlevel10k configuration at $P10K_CONFIG..."
cp "$(dirname "$0")/.p10k.zsh" "$P10K_CONFIG"
# Load Powerlevel10k configuration if it exists
add_to_zshrc "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh"
add_to_zshrc "# Add plugins"
# Add fzf
add_to_zshrc "source <(fzf --zsh)"
# Install standalone zsh plugins repositories
PLUGINS=(
"zsh-users/zsh-autosuggestions"
"zsh-users/zsh-syntax-highlighting"
"zdharma-continuum/fast-syntax-highlighting"
"marlonrichert/zsh-autocomplete"
"zsh-users/zsh-completions"
"zsh-users/zsh-history-substring-search"
)
# list with standalone plugin names
PLUGINS_EXSTRA=()
for plugin in "${PLUGINS[@]}"; do
repository_name="${plugin##*/}"
PLUGINS_EXSTRA+=("$repository_name")
done
for plugin in "${PLUGINS[@]}"; do
plugin_name=$(basename "$plugin")
if [ ! -d "$ZSH_CUSTOM/plugins/$plugin_name" ]; then
echo "Installing $plugin_name..."
echo "Clone from https://github.com/$plugin.git"
git clone https://github.com/"$plugin".git "$ZSH_CUSTOM/plugins/$plugin_name"
else
echo "$plugin_name already installed."
# Add the plugin source line to .zshrc
add_to_zshrc "source $ZSH_CUSTOM/plugins/$plugin_name/$plugin_name.plugin.zsh"
fi
done
## Add standard plugins to .zshrc
# Add plugins to .zshrc
# Define plugins to add to the .zshrc file
PLUGINS_TO_ADD=(
"dotnet"
"docker-compose"
"history"
"iterm2"
"macos"
"npm"
"aliases"
"cp"
"z"
"fzf"
)
# list with all plugin names
ALL_PLUGINS=("${PLUGINS_TO_ADD[@]}" "${PLUGINS_EXSTRA[@]}")
# Function to update plugins in .zshrc
update_zshrc_plugins() {
for plugin in "${PLUGINS_TO_ADD[@]}"; do
# Add the plugin source line to .zshrc
plugin_name=$(basename "$plugin")
add_to_zshrc "source $ZSH_PATH/plugins/$plugin_name/$plugin_name.plugin.zsh"
done
# Check if plugins line exists and update it
if grep -q "^plugins=" "$ZSHRC_PATH"; then
echo "Updating plugins line in $ZSHRC_PATH..."
sed -i '' "s/^plugins=(.*)$/plugins=(${ALL_PLUGINS[*]})/" "$ZSHRC_PATH"
else
echo "Adding plugins to $ZSHRC_PATH..."
echo "plugins=(${ALL_PLUGINS[*]})" >>"$ZSHRC_PATH"
fi
}
# Call the function to update .zshrc
update_zshrc_plugins
# configure aliases
add_to_zshrc "# Add custom aliases"
# Add aliases to .zshrc
add_to_zshrc "alias zshconfig='code ~/.zshrc'"
add_to_zshrc "alias ohmyzsh='code ~/.oh-my-zsh'"
add_to_zshrc "alias zshreload='source ~/.zshrc'"
add_to_zshrc "alias zshupdate='upgrade_ohmyzsh'"
add_to_zshrc "alias zshplugins='code $ZSH_CUSTOM/plugins'"
add_to_zshrc "alias zshthemes='code $ZSH_CUSTOM/themes'"
# Add custom aliases
# JavaScript
add_to_zshrc "alias nfresh='rm -rf node_modules/ package-lock.json && npm install'"
add_to_zshrc "alias watch='npm run dev'"
# Search for files and open them in Neovim
add_to_zshrc 'alias sn='\''nvim $(fzf -m --preview '\"'bat --color=always {}'\"')'\'
# Search for files and open them in Vscode
add_to_zshrc 'alias sc='\''code $(fzf -m --preview '\"'bat --color=always {}'\"')'\'
# Go to code folder
add_to_zshrc "alias cf='cd $HOME/Documents/Code'"
# Clear the terminal screen
add_to_zshrc "alias c='clear'"
# Show detailed directory listing
add_to_zshrc "alias ll='ls -la'"
# List files with human-readable sizes
add_to_zshrc "alias lh='ls -lh'"
# Show hidden files
add_to_zshrc "alias la='ls -A'"
# Shortcut to navigate to the home directory
add_to_zshrc "alias home='cd ~'"
# Change to parent directory
add_to_zshrc "alias b='cd ..'"
add_to_zshrc "alias bb='cd ../..'"
add_to_zshrc "alias bbb='cd ../../..'"
# Go back to the previous directory
add_to_zshrc "alias back='cd ..'"
# Open current directory in Finder
add_to_zshrc "alias finder='open .'"
# Open the current directory in VSCode
add_to_zshrc "alias code='code .'"
# List all open ports
add_to_zshrc "alias ports='sudo lsof -i -P -n | grep LISTEN'"
# View disk usage in human-readable format
add_to_zshrc "alias duh='du -h -d 1 | sort -hr'"
# Show all available disk space
add_to_zshrc "alias dfh='df -h'"
# Show the top 10 largest files in the current directory
add_to_zshrc "alias largest='find . -type f -exec du -h {} + | sort -rh | head -n 10'"
# Show current IP address
add_to_zshrc "alias myip=\"curl -s http://ipinfo.io/ip\""
# Flush DNS cache
add_to_zshrc "alias flushdns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'"
# Get current Wi-Fi network name
add_to_zshrc "alias wifi='networksetup -getairportnetwork en0'"
# Display macOS version
add_to_zshrc "alias macversion='sw_vers'"
# Sleep Mac
add_to_zshrc "alias sleepmac='pmset sleepnow'"
# Fast shutdown
add_to_zshrc "alias shutdown='sudo shutdown -h now'"
# Restart Mac
add_to_zshrc "alias restart='sudo shutdown -r now'"
# Show battery status
add_to_zshrc "alias battery='pmset -g batt'"
# Show temperature sensors data
add_to_zshrc "alias temp=\"sudo powermetrics --samplers smc | grep -i 'CPU die temperature'\""
# Open Activity Monitor
add_to_zshrc "alias activity='open -a \"Activity Monitor\"'"
# Show memory usage
add_to_zshrc "alias meminfo='vm_stat'"
# Show current date and time
add_to_zshrc "alias now='date \"+%Y-%m-%d %H:%M:%S\"'"
# Copy last command to clipboard
add_to_zshrc "alias clast='fc -ln -1 | pbcopy'"
# Make a directory and navigate into it
add_to_zshrc "alias mkcd='foo() { mkdir -p \"\$1\" && cd \"\$1\"; }; foo'"
# Copy to clipboard
add_to_zshrc "alias copy='pbcopy'"
# Paste from clipboard
add_to_zshrc "alias paste='pbpaste'"
# Quick HTTP server (Python 3.x)
add_to_zshrc "alias serve='python3 -m http.server 8000'"
# Finder alias to open a specific directory
add_to_zshrc "alias desktop='cd ~/Desktop && open .'"
# Open a file with the default application
add_to_zshrc "alias openf='open'"
# Open system preferences
add_to_zshrc "alias prefs='open /System/Library/PreferencePanes/'"
# View detailed process information
add_to_zshrc "alias psaux='ps aux | less'"
# System profiler for hardware info
add_to_zshrc "alias hwinfo='system_profiler SPHardwareDataType'"
# Show list of installed applications
add_to_zshrc "alias apps='ls /Applications/'"
# Open system logs
add_to_zshrc "alias syslogs='open /var/log/system.log'"
# List all running services
add_to_zshrc "alias services='launchctl list'"
# Display calendar for current month
add_to_zshrc "alias cal='cal -h'"
# Show public IP
add_to_zshrc "alias pubip='dig +short myip.opendns.com @resolver1.opendns.com'"
# Enable AirDrop over Ethernet and on unsupported Macs
add_to_zshrc "alias airdrop='defaults write com.apple.NetworkBrowser BrowseAllInterfaces 1'"
# Show network statistics
add_to_zshrc "alias netstat='netstat -s'"
# Flush RAM (requires sudo password)
add_to_zshrc "alias flushram='sudo purge'"
# Rebuild Spotlight index
add_to_zshrc "alias reindex='sudo mdutil -E /'"
# Disable system sleep
add_to_zshrc "alias nosleep='caffeinate'"
# Open iTerm
add_to_zshrc "alias iterm='open -a iTerm'"
# Open Terminal
add_to_zshrc "alias term='open -a Terminal'"
# Clipboard history
add_to_zshrc "alias cliphist='pbpaste > ~/clipboard-history.txt'"
# Change audio output to internal speakers
add_to_zshrc "alias audiomode='SwitchAudioSource -s \"Internal Speakers\"'"
# Check Bluetooth status
add_to_zshrc "alias btstatus='system_profiler SPBluetoothDataType | grep \"State\"'"
# Enable dark mode
add_to_zshrc "alias darkmode='osascript -e \"tell application \\\"System Events\\\" to tell appearance preferences to set dark mode to not dark mode\"'"
# Show CPU usage
add_to_zshrc "alias cpuinfo='top -l 1 -s 0 | grep \"CPU usage\"'"
# Show top processes by CPU usage
add_to_zshrc "alias topcpu='ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10'"
# Show top processes by memory usage
add_to_zshrc "alias topmem='ps -eo pmem,pid,user,args | sort -k 1 -r | head -10'"
# Network speed test
add_to_zshrc "alias speedtest='curl -o /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip'"
# Download file with progress bar
add_to_zshrc "alias wget='curl -O'"
# Count files in directory
add_to_zshrc "alias count='ls | wc -l'"
# Copy SSH key to clipboard
add_to_zshrc "alias copyssh='pbcopy < ~/.ssh/id_rsa.pub'"
# Open the Trash folder
add_to_zshrc "alias trash='open ~/.Trash'"
# Empty the Trash
add_to_zshrc "alias emptytrash='rm -rf ~/.Trash/*'"
# Show all files in Finder
add_to_zshrc "alias showfiles='defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder'"
# Hide hidden files in Finder
add_to_zshrc "alias hidefiles='defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder'"
# Toggle Finder hidden files visibility
add_to_zshrc "alias togglehidden='defaults write com.apple.finder AppleShowAllFiles -bool !\$(defaults read com.apple.finder AppleShowAllFiles) && killall Finder'"
# Quick curl request to check headers
add_to_zshrc "alias curlh='curl -I'"
# Check disk space usage
add_to_zshrc "alias diskspace='df -h'"
# Restart Finder
add_to_zshrc "alias restartfinder='killall Finder'"
# Restart Dock
add_to_zshrc "alias restartdock='killall Dock'"
# Restart Touch Bar
add_to_zshrc "alias restarttouchbar='pkill \"Touch Bar agent\"'"
# Launch Console
add_to_zshrc "alias console='open -a Console'"
# Force quit Finder
add_to_zshrc "alias quitfinder='osascript -e \"tell application \\\"Finder\\\" to quit\"'"
# Restart Spotlight
add_to_zshrc "alias restartspotlight='killall mds'"
# Launch Disk Utility
add_to_zshrc "alias diskutility='open -a \"Disk Utility\"'"
# Show recent kernel logs
add_to_zshrc "alias kernellogs='dmesg | tail -50'"
# Clear DNS cache
add_to_zshrc "alias cleardns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'"
# Show all currently running applications
add_to_zshrc "alias runningapps='ps -eo comm | grep -vE \"^\\[\" | sort | uniq'"
# Open Launchpad
add_to_zshrc "alias launchpad='open -a Launchpad'"
# Force refresh of Launchpad icons
add_to_zshrc "alias refreshlaunchpad='defaults write com.apple.dock ResetLaunchPad -bool true; killall Dock'"
# Launch Safari
add_to_zshrc "alias safari='open -a Safari'"
# Launch Chrome
add_to_zshrc "alias chrome='open -a \"Google Chrome\"'"
# Launch Firefox
add_to_zshrc "alias firefox='open -a Firefox'"
# Show all available audio input devices
add_to_zshrc "alias audioin='SwitchAudioSource -a -t input'"
# Show all available audio output devices
add_to_zshrc "alias audioout='SwitchAudioSource -a -t output'"
# Force eject all mounted drives
add_to_zshrc "alias ejectall='drutil eject'"
# Restart audio services
add_to_zshrc "alias restartaudio='sudo killall coreaudiod'"
# Open TextEdit
add_to_zshrc "alias textedit='open -a TextEdit'"
# Open Contacts
add_to_zshrc "alias contacts='open -a Contacts'"
# Open Calendar
add_to_zshrc "alias calendar='open -a Calendar'"
# Open Messages
add_to_zshrc "alias messages='open -a Messages'"
# Show external IP address
add_to_zshrc "alias extip='curl ipinfo.io/ip'"
# Check DNS records for a domain
add_to_zshrc "alias dnslookup='dig +short'"
# Network interface statistics
add_to_zshrc "alias netinfo='ifconfig -a'"
# System information overview
add_to_zshrc "alias sysinfo='system_profiler SPSoftwareDataType'"
# Watch system logs in real-time
add_to_zshrc "alias syswatch='tail -f /var/log/system.log'"
# open Rider
add_to_zshrc "alias rider='open -a /Applications/Rider.app'"
### add to path
add_to_zshrc "# Add .NET Core SDK tools"
add_to_zshrc "PATH='$PATH:/Users/troelslund/.dotnet/tools'"
echo "Zsh installed and configured successfully."
# =============================
# Config terminal app
# =============================
# Standard config location for dotfiles
PROFILE_NAME="Custom"
DOTFILES_TERMINAL="Custom.terminal"
# Path to the terminal config destination used by Terminal.app
TARGET_TERMINAL="$HOME/Library/Application Support/com.apple.Terminal/Custom.terminal"
# Backup current terminal config if it exists
if [ -f "$TARGET_TERMINAL" ]; then
echo "📦 Backing up existing Terminal config to Custom.backup.terminal"
cp "$TARGET_TERMINAL" "$TARGET_TERMINAL.backup"
fi
# Replace the terminal config
echo "📦 Copying Terminal config from $DOTFILES_TERMINAL"
cp "$DOTFILES_TERMINAL" "$TARGET_TERMINAL"
# Open the .terminal profile to trigger import
open "$DOTFILES_TERMINAL"
# Wait a moment for Terminal to register the profile
sleep 1
# Set the default and startup profile
defaults write com.apple.Terminal "Default Window Settings" -string "$PROFILE_NAME"
defaults write com.apple.Terminal "Startup Window Settings" -string "$PROFILE_NAME"
echo "✅ Terminal profile '$PROFILE_NAME' set as default and startup profile."
# =============================
# Configure tmux
# =============================
# Path to your custom config file
CUSTOM_CONFIG="./.tmux.conf"
# Path to tmux config destination
TARGET="$HOME/.tmux.conf"
# Backup current config if it exists
if [ -f "$TARGET" ]; then
echo "Backing up existing ~/.tmux.conf to ~/.tmux.conf.backup"
cp "$TARGET" "$TARGET.backup"
fi
# Replace the config
echo "Replacing ~/.tmux.conf with $CUSTOM_CONFIG"
cp "$CUSTOM_CONFIG" "$TARGET"
# Optional: reload tmux config if tmux is running
if tmux info &>/dev/null; then
echo "Reloading tmux config"
tmux source-file "$TARGET"
else
echo "tmux is not running. Config will be loaded next time you start tmux."
fi
exit 0
# =============================
# restart zsh and run 'p10k configure'