Added duplicate note

This commit is contained in:
Omri 2018-03-11 12:49:33 +02:00
parent 6cfe42eda3
commit 3bb1dc79de

View File

@ -26,7 +26,7 @@
function goto() function goto()
{ {
local target local target
readonly GOTO_DB="$HOME/.goto" GOTO_DB="$HOME/.goto"
if [ -z "$1" ]; then if [ -z "$1" ]; then
# display usage and exit when no args # display usage and exit when no args
@ -109,6 +109,12 @@ function _goto_list_aliases()
fi fi
} }
function _goto_find_duplicate()
{
local duplicates=$(sed -n 's:[^ ]* '"$1"'$:&:p' "$GOTO_DB" 2>/dev/null)
echo "$duplicates"
}
# Registers and alias. # Registers and alias.
function _goto_register_alias() function _goto_register_alias()
{ {
@ -137,9 +143,16 @@ function _goto_register_alias()
return return
fi fi
local duplicate=$(_goto_find_duplicate "$directory")
# Append entry to file. # Append entry to file.
echo "$1 $directory" >> "$GOTO_DB" echo "$1 $directory" >> "$GOTO_DB"
echo "Alias '$1' registered successfully." echo "Alias '$1' registered successfully."
if [ -n "$duplicate" ]; then
echo -e "note: duplicate alias found:\n$duplicate"
return
fi
} }
# Unregisters the given alias. # Unregisters the given alias.