-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaliasWizard.sh
More file actions
executable file
·141 lines (115 loc) · 5.09 KB
/
aliasWizard.sh
File metadata and controls
executable file
·141 lines (115 loc) · 5.09 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
#!/usr/bin/env bash
# Ensure this path is correct
source ./common.sh
ALIAS_SOURCE_BLOCK='if [[ -f ~/.aliases ]]; then
. ~/.aliases
fi'
BIN_SOURCE_BLOCK='if [[ -d "$HOME/bin" ]] && [[ ":$PATH:" != *":$HOME/bin:"* ]]; then
export PATH="$HOME/bin:$PATH"
fi'
welcome() {
printf "${YELLOW} ${RESET}\n";
printf "${YELLOW} █████╗ ██╗ ██╗ █████╗ ███████╗ ██╗ ██╗██╗███████╗ █████╗ ██████╗ ██████╗ ${RESET}\n";
printf "${YELLOW}██╔══██╗██║ ██║██╔══██╗██╔════╝ ██║ ██║██║╚══███╔╝██╔══██╗██╔══██╗██╔══██╗${RESET}\n";
printf "${YELLOW}███████║██║ ██║███████║███████╗ ██║ █╗ ██║██║ ███╔╝ ███████║██████╔╝██║ ██║${RESET}\n";
printf "${YELLOW}██╔══██║██║ ██║██╔══██║╚════██║ ██║███╗██║██║ ███╔╝ ██╔══██║██╔══██╗██║ ██║${RESET}\n";
printf "${YELLOW}██║ ██║███████╗██║██║ ██║███████║ ╚███╔███╔╝██║███████╗██║ ██║██║ ██║██████╔╝${RESET}\n";
printf "${YELLOW}╚═╝ ╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ${RESET}\n";
printf "${YELLOW} ${RESET}\n";
sleep 5
return 0
}
config_source() {
dots "Searching for your current shell"
if echo "$SHELL" | grep -q "bash"; then
print_success "bash shell detected"
RC_FILE="$HOME/.bashrc"
elif echo "$SHELL" | grep -q "zsh"; then
print_success "zsh shell detected"
RC_FILE="$HOME/.zshrc"
else
print_error "The $SHELL shell is unsupported"
printf '%s\n' "This script currently supports only bash and zsh shells"
exit 1
fi
# Check if the alias source block already exists in RC_FILE
if grep -qF "if [[ -f ~/.aliases ]]; then" "$RC_FILE" 2>/dev/null; then
print_success "Alias source block already exists in $RC_FILE file"
else
dots "Adding alias source block to $RC_FILE file"
# Append the ALIAS_SOURCE_BLOCK to the RC_FILE
printf '\n%s\n' "$ALIAS_SOURCE_BLOCK" >> "$RC_FILE" || {
print_error "Failed to add alias source block to $RC_FILE file"
exit 1
}
print_success "Alias source block added to $RC_FILE file successfully!"
fi
return 0
}
detect_alias_file() {
ALIAS_FILE="$HOME/.aliases"
if [[ -f "$ALIAS_FILE" ]]; then
print_success "$ALIAS_FILE already exists"
dots "Updating $ALIAS_FILE"
rm -f "$ALIAS_FILE" || {
print_error "Failed to update existing $ALIAS_FILE"
exit 1
}
else
print_warning "$ALIAS_FILE not found, a new one will be created"
fi
return 0
}
setup_aliases() {
dots "Copying .aliases file"
dots "You can see the list of all aliases documented in the README file"
cp scripts/.aliases $HOME/.aliases || {
print_error "Failed to copy aliases to the home directory"
dots "Exiting"
exit 1
}
return 0
}
add_bin(){
mkdir -p ~/bin
cp scripts/mkrun ~/bin/mkrun
cp scripts/run ~/bin/run
cp scripts/autocommit ~/bin/autocommit
cp scripts/autopush ~/bin/autopush
chmod +x ~/bin/mkrun
chmod +x ~/bin/run
chmod +x ~/bin/autocommit
chmod +x ~/bin/autopush
if grep -qF "if [[ -d "$HOME/bin" ]] && [[ ":$PATH:" != *":$HOME/bin:"* ]]; then" "$RC_FILE" 2>/dev/null; then
print_success "~/bin source block already exists in $RC_FILE file"
else
dots "Adding ~/bin source block to $RC_FILE file"
# Append the BIN_SOURCE_BLOCK to the RC_FILE
printf '\n%s\n' "$BIN_SOURCE_BLOCK" >> "$RC_FILE" || {
print_error "Failed to add ~/bin source block to $RC_FILE file"
exit 1
}
print_success "~/bin source block added to $RC_FILE file successfully!"
fi
return 0
}
finish_setup() {
print_success "Aliases configured successfully!"
dots "Reloading $RC_FILE to activate aliases"
source "$RC_FILE"
printf '%s\n' "Please restart your terminal"
printf '%s\n' "Aliases activated successfully with aliasWizard"
return 0
}
# Main function to organize the script flow
main() {
welcome
config_source
detect_alias_file
setup_aliases
add_bin
finish_setup
return 0
}
# Run main
main