Skip to content

Commit 8ed07f8

Browse files
committed
Fixed issue with sed call to replace an alias, where characters were not being escaped correctly. Updates to help display, some of the messages when using the tool, and documentation in README.md.
1 parent faede7e commit 8ed07f8

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,17 @@ Running `aliaser help` displays the following:
5353

5454
add <alias_name> <command>
5555
Creates/replaces an alias for the specified command in the aliases file
56+
5657
The alias name must not contain any spaces, and can only consist of alphanumeric characters
5758

59+
In the event that you need to add an alias for a more complex command or an alias that contains several,
60+
you can wrap with double quotes, i.e. $ aliaser add print_temp "cd temp && ls"
61+
62+
If you need to escape a character in the command, use a preceding \
63+
5864
rm <alias_name>
5965
Removes the alias permanently from the aliases file
66+
6067
The alias name must not contain any spaces
6168

6269
help

aliaser

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
version="1.3.2"
3+
version="1.3.3"
44

55
function print_version {
66
echo $version
@@ -27,10 +27,17 @@ function print_help {
2727
echo
2828
echo " add <alias_name> <command>"
2929
echo " Creates/replaces an alias for the specified command in the aliases file"
30+
echo
3031
echo " The alias name must not contain any spaces, and can only consist of the following characters: a-z A-Z 0-9 _ -"
3132
echo
33+
echo " In the event that you need to add an alias for a more complex command or an alias that contains several,"
34+
echo " you can wrap with double quotes, i.e. \$ aliaser add print_temp \"cd temp && ls\""
35+
echo
36+
echo " If you need to escape a character in the command, use a preceding \\"
37+
echo
3238
echo " rm <alias_name>"
3339
echo " Removes the alias permanently from the aliases file"
40+
echo
3441
echo " The alias name must not contain any spaces"
3542
echo
3643
echo " help"
@@ -63,14 +70,16 @@ function add_alias {
6370
if [[ $response != "y" ]]; then
6471
exit
6572
else
66-
sed -i.bak "s/^alias $alias=.*$/alias $alias='$command'/g" $alias_file
67-
rm "$alias_file.bak"
73+
sed -i.bak "s|^alias $alias=.*$|alias $alias='$command'|g" $alias_file
74+
if [[ -f "$alias_file.bak" ]]; then
75+
rm "$alias_file.bak"
76+
fi
77+
echo "Replaced alias '$alias'"
6878
fi
6979
else
7080
echo "alias $alias='$command'" >> $alias_file
81+
echo "Added alias '$alias'"
7182
fi
72-
73-
echo "Added alias '$alias' for command '$command'"
7483
}
7584

7685
function remove_alias {
@@ -81,7 +90,9 @@ function remove_alias {
8190
fi
8291

8392
sed -i.bak "/^alias $alias=/d" $alias_file
84-
rm "$alias_file.bak"
93+
if [[ -f "$alias_file.bak" ]]; then
94+
rm "$alias_file.bak"
95+
fi
8596

8697
echo "Removed alias '$alias'"
8798
}

0 commit comments

Comments
 (0)