Skip to content

Instantly share code, notes, and snippets.

@GeneralD
Last active March 14, 2025 15:15
Show Gist options
  • Save GeneralD/d647c0836c2ba0966cf46e71635cb447 to your computer and use it in GitHub Desktop.
Save GeneralD/d647c0836c2ba0966cf46e71635cb447 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
skim_browser_bookmark_search() {
bookmarks_path=`\ls ~/Library/Application\ Support/*/*/Default/Bookmarks -t1 | head -n 1`
jq_script='
def ancestors: while(. | length >= 2; del(.[-1,-2]));
. as $in | paths(.url?) as $key | $in | getpath($key) | {name,url, path: [$key[0:-2] | ancestors as $a | $in | getpath($a) | .name?] | reverse | join("/") } | .path + "/" + .name + "\t" + .url'
(( $+commands[w3m] )) && local fetch="w3m -dump" || local fetch="curl -sfL"
jq -r "$jq_script" < "$bookmarks_path" \
| sed -E $'s/(.*)\t(.*)/\\1\t\x1b[36m\\2\x1b[m/g' \
| sk --ansi --preview="echo {} | awk '{print \$NF}' | xargs $fetch {} | bat --style=numbers --color=always --language='HTML'"\
| cut -d$'\t' -f2 \
| xargs open
}
zle -N skim_browser_bookmark_search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment