Skip to content

Instantly share code, notes, and snippets.

@astarasikov
Created June 22, 2015 03:06
Show Gist options
  • Save astarasikov/5041a3ff0c9eee8ac217 to your computer and use it in GitHub Desktop.
Save astarasikov/5041a3ff0c9eee8ac217 to your computer and use it in GitHub Desktop.
A script to sort my Chrome bookmarks
#!/bin/bash
set -e
set -u
BOOKMARKS_TXT="bookmarks.txt"
if [[ -z "$1" ]]; then
echo "Usage: $0 $BOOKMARKS_TXT"
exit -1
fi
rm *.txt
cat "$1" | grep 'HREF.*ADD' -o | cut -d= -f2 | awk '{print $1}' | sort -u > $BOOKMARKS_TXT
function sort_inplace_file() {
cat $1 | sort -u > $1.sort
mv $1.sort $1
}
function remove_lines_in_first_that_are_present_in_second() {
#comm requires the input files to be sorted
sort_inplace_file $1
sort_inplace_file $2
comm -23 $1 $2 > $1.new
mv $1.new $1
}
function simple_tag() {
echo "simple_tag $1"
cat $BOOKMARKS_TXT | grep -i "$1" | tee $1.txt > /dev/null
remove_lines_in_first_that_are_present_in_second $BOOKMARKS_TXT $1.txt
}
function append_tag_to_file() {
echo "append_tag_to_file: $1 => $2"
#XXX: for some reasone ">>" here crashed occasionally
cat $BOOKMARKS_TXT | grep -i "$1" | tee -a $2.txt > /dev/null
remove_lines_in_first_that_are_present_in_second $BOOKMARKS_TXT $2.txt
}
SIMPLE_TAGS=(
'habrahabr'
'wikipedia'
'vk.com'
'algo'
'android'
'blogspot'
'blog'
'book'
'dsp'
'erlang'
'emacs'
'fpga'
'github'
'gpu'
'gsoc'
'haskell'
'livejournal'
'linux'
'math'
'microsoft'
'music'
'ocaml'
'opencv'
'piano'
'radio'
'slideshare'
'speakerdeck'
'sport'
'stackexchange'
'wordpress'
)
for tag in ${SIMPLE_TAGS[@]}; do
simple_tag "$tag"
done
append_tag_to_file "~" "personal_academia"
append_tag_to_file "qrz" "radio"
append_tag_to_file "stackoverflow" "stackexchange"
append_tag_to_file "fantlab" "fiction"
append_tag_to_file "opengl" "opengl"
append_tag_to_file "webgl" "opengl"
append_tag_to_file "glsl" "opengl"
append_tag_to_file "itep\.ru" "dsp"
append_tag_to_file "gamedev" "gamedev"
append_tag_to_file "gamerendering" "gamedev"
append_tag_to_file "gamasutra" "gamedev"
append_tag_to_file "geeks3d" "gamedev"
append_tag_to_file "render" "gamedev"
append_tag_to_file "electron" "electronics"
append_tag_to_file "ee" "electronics"
append_tag_to_file "eda" "electronics"
append_tag_to_file "asic" "fpga"
append_tag_to_file "verilog" "fpga"
append_tag_to_file "vhdl" "fpga"
append_tag_to_file "yosys" "fpga"
append_tag_to_file "uvm" "fpga"
append_tag_to_file "ovm" "fpga"
append_tag_to_file "courses" "courses"
append_tag_to_file "lectures" "courses"
append_tag_to_file "\.ac\.at" "edu"
append_tag_to_file "\.ac\.jp" "edu"
append_tag_to_file "\.ac\.kr" "edu"
append_tag_to_file "\.ac\.ru" "edu"
append_tag_to_file "\.ac\.uk" "edu"
append_tag_to_file "\.au\.dk" "edu"
append_tag_to_file "\.edu" "edu"
append_tag_to_file "\.ens\.fr" "edu"
append_tag_to_file "\.ethz\.ch" "edu"
append_tag_to_file "\.kuleven\.be" "edu"
append_tag_to_file "\.lmu\.de" "edu"
append_tag_to_file "\.thm\.de" "edu"
append_tag_to_file "\.dtu\.dk" "edu"
append_tag_to_file "\.ku\.dk" "edu"
append_tag_to_file "\.kth\.se" "edu"
append_tag_to_file "\.lth\.se" "edu"
append_tag_to_file "\.mipt\.ru" "edu"
append_tag_to_file "\.msu\.ru" "edu"
append_tag_to_file "\.ru\.nl" "edu"
append_tag_to_file "\.tue\.nl" "edu"
append_tag_to_file "\.ualberta\.ca" "edu"
append_tag_to_file "\.ubi\.pt" "edu"
append_tag_to_file "\.ufpe\.br" "edu"
append_tag_to_file "\.unibo\.it" "edu"
append_tag_to_file "\.uregina\.ca" "edu"
append_tag_to_file "\.uu\.nl" "edu"
append_tag_to_file "\.uu\.se" "edu"
append_tag_to_file "\.vu\.nl" "edu"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment