-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·56 lines (40 loc) · 1.53 KB
/
install.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
#!/bin/bash
# Color codes for output messages
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Function to display error messages
display_error() {
echo -e "${RED}[Error]: $1${NC}"
exit 1
}
# Function to display success messages
display_success() {
echo -e "${GREEN}[Success]: $1${NC}"
}
# Build the tool
make || display_error "Failed to build the tool."
mkdir -p ~/.local/bin || display_error "Failed to created ~/.local/bin directory"
# Copy the binary to a directory in the PATH
cp aliasmanager ~/.local/bin/ || display_error "Failed to copy the binary to ~/.local/bin"
# Determine the user's shell
user_shell=$(basename "$SHELL")"rc"
# Check if the source command already exists in the appropriate shell rc file
if grep -q ".my_aliases.txt" "$HOME/.$user_shell"; then
display_success ".my_aliases.txt already sourced in .$user_shell"
else
# Append a source command to the appropriate shell rc file for .my_aliases.txt
touch $HOME/.my_aliases.txt || display_error "Failed to create .my_aliases.txt"
echo "" >> "$HOME/.$user_shell"
echo "# Alias Management Tool" >> "$HOME/.$user_shell"
echo "source \$HOME/.my_aliases.txt" >> "$HOME/.$user_shell"
display_success "Added source command to $HOME/.$user_shell"
echo "PATH=\$PATH:\$HOME/.local/bin" >> "$HOME/.$user_shell"
echo "
am (){
aliasmanager \$@;
source \$HOME/.my_aliases.txt
}" >> "$HOME/.$user_shell" || display_error "Couldn't write in $user_shell"
fi
# Print installation success message
display_success "Installation complete!\n"