From 5c3f1d33f5cc5e389ab90dcce5d29062e0bd1e87 Mon Sep 17 00:00:00 2001 From: Andrew <001x@mail.ru> Date: Thu, 25 Jul 2019 04:27:27 +0300 Subject: [PATCH] Updated Browse chrome bookmarks (markdown) --- Browse-chrome-bookmarks.md | 96 +++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/Browse-chrome-bookmarks.md b/Browse-chrome-bookmarks.md index 9c0004d..81606c5 100644 --- a/Browse-chrome-bookmarks.md +++ b/Browse-chrome-bookmarks.md @@ -1,56 +1,56 @@ -`# b- browse chrome bookmarks` -`b() {` - `local open ruby output` - `open=xdg-open` - `ruby=$(which ruby)` - `output=$($ruby << EORUBY` -`# encoding: utf-8` +```## b- browse chrome bookmarks +b() { + local open ruby output + open=xdg-open + ruby=$(which ruby) + output=$($ruby << EORUBY +# encoding: utf-8 -`require 'json'` -`FILE = '~/.config/google-chrome/Default/Bookmarks'` -`CJK = /\p{Han}|\p{Katakana}|\p{Hiragana}|\p{Hangul}/` +require 'json' +FILE = '~/.config/google-chrome/Default/Bookmarks' +CJK = /\p{Han}|\p{Katakana}|\p{Hiragana}|\p{Hangul}/ -`def build parent, json` - `name = [parent, json['name']].compact.join('/') ` - `if json['type'] == 'folder'` - `json['children'].map { |child| build name, child }` - `else` - `{ name: name, url: json['url'] }` - `end` -`end` +def build parent, json + name = [parent, json['name']].compact.join('/') + if json['type'] == 'folder' + json['children'].map { |child| build name, child } + else + { name: name, url: json['url'] } + end +end -`def just str, width` - `str.ljust(width - str.scan(CJK).length)` -`end` +def just str, width + str.ljust(width - str.scan(CJK).length) +end -`def trim str, width` - `len = 0` - `str.each_char.each_with_index do |char, idx|` - `len += char =~ CJK ? 2 : 1` - `return str[0, idx] if len > width` - `end` - `str` -`end` +def trim str, width + len = 0 + str.each_char.each_with_index do |char, idx| + len += char =~ CJK ? 2 : 1 + return str[0, idx] if len > width + end + str +end -`width = `tput cols`.to_i / 2` -`json = JSON.load File.read File.expand_path FILE` -`items = json['roots']` - `.values_at(*%w(bookmark_bar synced other))` - `.compact` - `.map { |e| build nil, e }` - `.flatten` +width = `tput cols`.to_i / 2 +json = JSON.load File.read File.expand_path FILE +items = json['roots'] + .values_at(*%w(bookmark_bar synced other)) + .compact + .map { |e| build nil, e } + .flatten -`items.each do |item|` - `name = trim item[:name], width` - `puts [just(name, width),` - `item[:url]].join("\t\x1b[36m") + "\x1b[m"` -`end` -`EORUBY` -`)` +items.each do |item| + name = trim item[:name], width + puts [just(name, width), + item[:url]].join("\t\x1b[36m") + "\x1b[m" +end +EORUBY +) - `echo -e "$output" |` - `fzf-tmux -u 30% --ansi --multi --no-hscroll --tiebreak=begin |` - `awk 'BEGIN { FS = "\t" } { print }' |` - `xargs $open &>/dev/null` + echo -e "$output" | + fzf-tmux -u 30% --ansi --multi --no-hscroll --tiebreak=begin | + awk 'BEGIN { FS = "\t" } { print $2 }' | + xargs $open &>/dev/null -`}` +}``` \ No newline at end of file