├── README.md ├── rofi_firefox_bookmarks.sh └── rofi_firefox_tree.sh /README.md: -------------------------------------------------------------------------------- 1 | # rofi-firefox-bookmarks 2 | 3 | ## Setup 4 | 5 | - `wget https://raw.githubusercontent.com/milosz/rofi-firefox-bookmarks/main/rofi_firefox_bookmarks.sh` 6 | - `chmod +x rofi_firefox_bookmarks.sh` 7 | - `rofi -show firefox_bookmarks -modi "firefox_bookmarks:/path/to/rofi_firefox_bookmarks.sh"` 8 | -------------------------------------------------------------------------------- /rofi_firefox_bookmarks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # rofi - search bookmarks 3 | # rofi -show firefox_bookmarks -modi "firefox_bookmarks:/path/to/rofi_firefox_bookmarks.sh" 4 | 5 | # places.sqlite location 6 | places_file="$(find ~/.mozilla/firefox/*.default*/ -name "places.sqlite" -print -quit)" 7 | 8 | # places.sqlite copy 9 | places_backup="$(dirname "${places_file}")/places.rofi.sqlite" 10 | 11 | # path to the sqlite3 binary 12 | sqlite_path="$(which sqlite3)" 13 | 14 | # sqlite3 parameters (define separator character) 15 | sqlite_params="-separator ^" 16 | 17 | # browser path 18 | browser_path="$(which firefox)" 19 | 20 | # functions 21 | 22 | # create a backup file 23 | create_backup() { 24 | if [ "$#" -eq 2 ] && [ -n "$1" ] && [ -n "$2" ]; then 25 | if [ ! -f "$2" ] || [ "$1" -nt "$2" ]; then 26 | cp "$1" "$2" 27 | fi 28 | fi 29 | } 30 | 31 | # process bookmarks 32 | process_bookmarks() { 33 | query="select b.title, p.url, b.id, SUBSTR(SUBSTR(p.url, INSTR(url, '//') + 2), 0, INSTR(SUBSTR(p.url, INSTR(p.url, '//') + 2), '/')) as domain from moz_bookmarks as b left outer join moz_places as p on b.fk=p.id where b.type = 1 and p.hidden=0 and b.title not null" # and parent=$1 34 | $sqlite_path $sqlite_params "$places_backup" "$query" | while IFS=^ read title url id domain; do 35 | if [ -z "$title" ]; then 36 | title="$url" 37 | fi 38 | printf "%-500s {id:%s}\n" "$title [$domain]" "$id" 39 | done 40 | } 41 | 42 | # process bookmark 43 | process_bookmark() { 44 | if [ "$#" = 1 ] && [ -n "$1" ]; then 45 | id="$(echo $1 | sed "s|.*{id:\(.*\)}$|\1|")" 46 | query="select p.url from moz_bookmarks as b left outer join moz_places as p on b.fk=p.id where b.type = 1 and p.hidden=0 and b.title not null and b.id=$id" 47 | url="$($sqlite_path $sqlite_params "$places_backup" "$query")" 48 | nohup $browser_path "$url" >/dev/null 2>&1 & 49 | fi 50 | } 51 | 52 | # application 53 | 54 | parameter="$1" 55 | 56 | # create a backup, as we cannot operate on a places.sqlite file directly due to exclusive lock 57 | create_backup "$places_file" "$places_backup" 58 | 59 | # open a bookmark when there is a param sety 60 | if [ -n "$parameter" ]; then 61 | process_bookmark "$parameter" 62 | exit 63 | fi 64 | 65 | # process bookmarks 66 | process_bookmarks 67 | -------------------------------------------------------------------------------- /rofi_firefox_tree.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # rofi - list bookmarks tree 3 | # rofi -show firefox_tree -modi "firefox_tree:/path/to/rofi_firefox_tree.sh" 4 | 5 | # places.sqlite location 6 | places_file="$(find ~/.mozilla/firefox/*.default*/ -name "places.sqlite" -print -quit)" 7 | 8 | # places.sqlite copy 9 | places_backup="$(dirname "${places_file}")/places.rofi.sqlite" 10 | 11 | # path to the sqlite3 binary 12 | sqlite_path="$(which sqlite3)" 13 | 14 | # sqlite3 parameters (define separator character) 15 | sqlite_params="-separator ^" 16 | 17 | # browser path 18 | browser_path="$(which firefox)" 19 | 20 | # functions 21 | 22 | # create a backup file 23 | create_backup() { 24 | if [ "$#" -eq 2 ] && [ -n "$1" ] && [ -n "$2" ]; then 25 | if [ ! -f "$2" ] || [ "$1" -nt "$2" ]; then 26 | cp "$1" "$2" 27 | fi 28 | fi 29 | } 30 | 31 | # get current folder id 32 | get_current_folder_id() { 33 | if [ "$#" -eq 1 ]; then 34 | if [ -z "$1" ]; then 35 | query="select id from moz_bookmarks where parent=0 and position=0 and type=2" 36 | else 37 | id="$(echo "$1" | sed "s|.*{id:\(.*\)}$|\1|")" 38 | query="select id from moz_bookmarks where type=2 and id='$id'" 39 | fi 40 | echo "$($sqlite_path $sqlite_params "$places_backup" "$query")" 41 | fi 42 | } 43 | 44 | # display parent 45 | display_parent() { 46 | if [ "$#" = 1 ] && [ -n "$1" ]; then 47 | query="select parent from moz_bookmarks where id=$1 and type=2" 48 | result="$($sqlite_path $sqlite_params "$places_backup" "$query")" 49 | if [ -n "$result" ] && [ "$result" -ne "0" ]; then 50 | printf "%-500s {id:%s}\n" ".." "$result" 51 | fi 52 | fi 53 | } 54 | 55 | # process folder 56 | process_folder() { 57 | if [ "$#" = 1 ] && [ -n "$1" ]; then 58 | 59 | display_parent "$1" 60 | 61 | query="select id, title from moz_bookmarks where parent=$1 and type=2 and (select count(*) from moz_bookmarks as b2 where b2.parent=moz_bookmarks.id)>0" 62 | $sqlite_path $sqlite_params "$places_backup" "$query" | while IFS=^ read id title; do 63 | if [ "$title" == "tags" ]; then 64 | continue 65 | fi 66 | 67 | if [ -z "$title" ]; then 68 | title="(no title)" 69 | fi 70 | 71 | printf "%-500s {id:%s}\n" "$title" "$id" 72 | done 73 | fi 74 | } 75 | 76 | # process bookmarks 77 | process_bookmarks() { 78 | if [ "$#" = 1 ] && [ -n "$1" ]; then 79 | query="select b.title, p.url, b.id, SUBSTR(SUBSTR(p.url, INSTR(url, '//') + 2), 0, INSTR(SUBSTR(p.url, INSTR(p.url, '//') + 2), '/')) from moz_bookmarks as b left outer join moz_places as p on b.fk=p.id where b.type = 1 and p.hidden=0 and b.title not null and parent=$1" 80 | $sqlite_path $sqlite_params "$places_backup" "$query" | while IFS=^ read title url id domain; do 81 | if [ -z "$title" ]; then 82 | title="$url" 83 | fi 84 | printf "%-500s {id:%s}\n" "$title [$domain]" "$id" 85 | done 86 | fi 87 | } 88 | 89 | # process bookmark 90 | process_bookmark() { 91 | if [ "$#" = 1 ] && [ -n "$1" ]; then 92 | id="$(echo $1 | sed "s|.*{id:\(.*\)}$|\1|")" 93 | query="select p.url from moz_bookmarks as b left outer join moz_places as p on b.fk=p.id where b.type = 1 and p.hidden=0 and b.title not null and b.id=$id" 94 | url="$($sqlite_path $sqlite_params "$places_backup" "$query")" 95 | nohup $browser_path "$url" >/dev/null 2>&1 & 96 | fi 97 | } 98 | 99 | # application 100 | 101 | parameter="$1" 102 | 103 | # create a backup, as we cannot operate on a places.sqlite file directly due to exclusive lock 104 | create_backup "$places_file" "$places_backup" 105 | 106 | # determine current folder 107 | folder_id=$(get_current_folder_id "$parameter") 108 | 109 | # open a bookmark when id is not a folder 110 | if [ -z "$folder_id" ]; then 111 | process_bookmark "$parameter" 112 | exit 113 | fi 114 | 115 | # process current folder 116 | process_folder "$folder_id" 117 | 118 | # process bookmarks 119 | process_bookmarks "$folder_id" 120 | --------------------------------------------------------------------------------