diff --git a/cd-bookmark b/cd-bookmark index b93c816..efa0dd7 100644 --- a/cd-bookmark +++ b/cd-bookmark @@ -51,6 +51,10 @@ function _cdbookmark_print_error() { echo "Try \`-h' option for more information." 1>&2 } +function _cdbookmark_escape_id() { + echo $1 | sed -e 's/[^a-zA-Z0-9<>]/\\&/g' +} + function _cdbookmark_delete_bookmark() { local bookmark_id="$1" local bookmark_dir="$(_cdbookmark_get_bookmark $bookmark_id)" @@ -60,7 +64,7 @@ function _cdbookmark_delete_bookmark() { return 4 fi - local escaped_id="$(echo $bookmark_id | sed -e 's/[^a-zA-Z0-9<>]/\\&/g')" + local escaped_id="$(_cdbookmark_escape_id $1)" sed -i '' -e "/^${escaped_id}|/d" "$BOOKMARK_FILE" } @@ -82,7 +86,7 @@ function _cdbookmark_list_bookmark_id() { } function _cdbookmark_get_bookmark() { - local escaped_id="$(echo $1 | sed -e 's/[^a-zA-Z0-9<>]/\\&/g')" + local escaped_id="$(_cdbookmark_escape_id $1)" cat "$BOOKMARK_FILE" | grep -E "^${escaped_id}\\|" | cut -d '|' -f 2 | head -n 1 }