Skip to content

Commit

Permalink
Extract escaped_id to a function
Browse files Browse the repository at this point in the history
As this is now used in multiple places.
  • Loading branch information
erikw committed Nov 4, 2021
1 parent 6b6d23a commit b6078d1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cd-bookmark
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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"
}

Expand All @@ -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
}

Expand Down

0 comments on commit b6078d1

Please sign in to comment.