-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliascheck.sh
42 lines (34 loc) · 1.24 KB
/
aliascheck.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
#!/bin/bash
# Function to remove aliases
remove_aliases() {
local alias_name="$1"
sed -i "/alias $alias_name=/d" "$HOME/.bashrc"
echo "Alias '$alias_name' removed."
}
# Prompt the user for the path to the alias file
read -p "Enter the path to the file containing aliases: " alias_file
# Expand '~' to the home directory
alias_file=$(eval echo "$alias_file")
# Check if the alias file exists
if [ ! -f "$alias_file" ]; then
echo "Error: Alias file '$alias_file' not found."
exit 1
fi
# Output file
output_file=".aliascheck_output.txt"
echo "Checking for matching aliases..."
# Loop through each alias in the list
while IFS= read -r alias_name; do
if grep -q "alias $alias_name=" "$HOME/.bashrc"; then
echo "Matching alias found: $alias_name"
read -p "Do you want to remove this alias? (y/n): " choice
case "$choice" in
y|Y ) remove_aliases "$alias_name" >> "$output_file";;
n|N ) echo "Alias '$alias_name' not removed." >> "$output_file";;
* ) echo "Invalid choice. Alias '$alias_name' not removed." >> "$output_file";;
esac
else
echo $alias_name >> "$output_file"
fi
done < "$alias_file"
echo "Alias check complete. Output saved to '$output_file'."