mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-19 00:53:42 -05:00
Updated Browse chrome bookmarks (markdown)
@@ -1,58 +1,56 @@
|
|||||||
`
|
`# b- browse chrome bookmarks`
|
||||||
# b- browse chrome bookmarks
|
`b() {`
|
||||||
b() {
|
`local open ruby output`
|
||||||
local open ruby output
|
`open=xdg-open`
|
||||||
open=xdg-open
|
`ruby=$(which ruby)`
|
||||||
ruby=$(which ruby)
|
`output=$($ruby << EORUBY`
|
||||||
output=$($ruby << EORUBY
|
`# encoding: utf-8`
|
||||||
# encoding: utf-8
|
|
||||||
|
|
||||||
require 'json'
|
`require 'json'`
|
||||||
FILE = '~/.config/google-chrome/Default/Bookmarks'
|
`FILE = '~/.config/google-chrome/Default/Bookmarks'`
|
||||||
CJK = /\p{Han}|\p{Katakana}|\p{Hiragana}|\p{Hangul}/
|
`CJK = /\p{Han}|\p{Katakana}|\p{Hiragana}|\p{Hangul}/`
|
||||||
|
|
||||||
def build parent, json
|
`def build parent, json`
|
||||||
name = [parent, json['name']].compact.join('/')
|
`name = [parent, json['name']].compact.join('/') `
|
||||||
if json['type'] == 'folder'
|
`if json['type'] == 'folder'`
|
||||||
json['children'].map { |child| build name, child }
|
`json['children'].map { |child| build name, child }`
|
||||||
else
|
`else`
|
||||||
{ name: name, url: json['url'] }
|
`{ name: name, url: json['url'] }`
|
||||||
end
|
`end`
|
||||||
end
|
`end`
|
||||||
|
|
||||||
def just str, width
|
`def just str, width`
|
||||||
str.ljust(width - str.scan(CJK).length)
|
`str.ljust(width - str.scan(CJK).length)`
|
||||||
end
|
`end`
|
||||||
|
|
||||||
def trim str, width
|
`def trim str, width`
|
||||||
len = 0
|
`len = 0`
|
||||||
str.each_char.each_with_index do |char, idx|
|
`str.each_char.each_with_index do |char, idx|`
|
||||||
len += char =~ CJK ? 2 : 1
|
`len += char =~ CJK ? 2 : 1`
|
||||||
return str[0, idx] if len > width
|
`return str[0, idx] if len > width`
|
||||||
end
|
`end`
|
||||||
str
|
`str`
|
||||||
end
|
`end`
|
||||||
|
|
||||||
width = `tput cols`.to_i / 2
|
`width = `tput cols`.to_i / 2`
|
||||||
json = JSON.load File.read File.expand_path FILE
|
`json = JSON.load File.read File.expand_path FILE`
|
||||||
items = json['roots']
|
`items = json['roots']`
|
||||||
.values_at(*%w(bookmark_bar synced other))
|
`.values_at(*%w(bookmark_bar synced other))`
|
||||||
.compact
|
`.compact`
|
||||||
.map { |e| build nil, e }
|
`.map { |e| build nil, e }`
|
||||||
.flatten
|
`.flatten`
|
||||||
|
|
||||||
items.each do |item|
|
`items.each do |item|`
|
||||||
name = trim item[:name], width
|
`name = trim item[:name], width`
|
||||||
puts [just(name, width),
|
`puts [just(name, width),`
|
||||||
item[:url]].join("\t\x1b[36m") + "\x1b[m"
|
`item[:url]].join("\t\x1b[36m") + "\x1b[m"`
|
||||||
end
|
`end`
|
||||||
EORUBY
|
`EORUBY`
|
||||||
)
|
`)`
|
||||||
|
|
||||||
echo -e "$output" |
|
`echo -e "$output" |`
|
||||||
fzf-tmux -u 30% --ansi --multi --no-hscroll --tiebreak=begin |
|
`fzf-tmux -u 30% --ansi --multi --no-hscroll --tiebreak=begin |`
|
||||||
awk 'BEGIN { FS = "\t" } { print $2 }' |
|
`awk 'BEGIN { FS = "\t" } { print }' |`
|
||||||
xargs $open &>/dev/null
|
`xargs $open &>/dev/null`
|
||||||
|
|
||||||
}
|
`}`
|
||||||
`
|
|
||||||
|
|||||||
Reference in New Issue
Block a user