Skip to content

Instantly share code, notes, and snippets.

@cholmboe
Last active September 7, 2023 08:12
Show Gist options
  • Save cholmboe/da1ac37f92f4a3e1e5c41a8b25d674a4 to your computer and use it in GitHub Desktop.
Save cholmboe/da1ac37f92f4a3e1e5c41a8b25d674a4 to your computer and use it in GitHub Desktop.
A script to search and open chrome bookmarks from your terminal
#!/bin/sh
#
# Search and open chrome bookmarks from your terminal.
#
# Open interactive search:
# $ b
#
# Open first fuzzy matching bookmark:
# $ b <query string>
#
set -euo pipefail
# This is where chrome bookmarks are stored on OSX, needs adjustment on other platforms.
BOOKMARKS="$HOME/Library/Application Support/Google/Chrome/Default/Bookmarks"
if ! [ -x "$(command -v fzf)" ]; then
echo "fzf is not installed"
exit 1
fi
if ! [ -x "$(command -v jq)" ]; then
echo "jq is not installed"
exit 1
fi
_bookmarks() {
cat "$BOOKMARKS" | jq -r '.roots[] | recurse(.children?[]?) | select(.url!=null) | "\(.name) (\(.url?))"'
}
main() {
local f
[ -n "$*" ] && f="-f $*"
url=$(_bookmarks | fzf --history=$HOME/.goto.history --prompt="Search bookmark > " $f | head -1 | sed -n 's/[^(]*(\(http[^)]*\).*/\1/p')
echo "$url"
[ -n $url ] && open "$url"
}
main $*
@jsegerli
Copy link

Just curious, is there any particular reason why you're using -z and || and not -n and && (which I personally think is easier to read since it doesn't have any negations)?

@cholmboe
Copy link
Author

No reason that I can remember. And I think you're absolutely right :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment