-
-
Save cholmboe/da1ac37f92f4a3e1e5c41a8b25d674a4 to your computer and use it in GitHub Desktop.
A script to search and open chrome bookmarks from your terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $* |
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
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)?