Posted on ::

I often look for some concept out of curiority, and end up with tens of browser tabs opened on the subject, and realize that I have no time now to pursue this rabbit into his hole, end up with tons of Firefox windows with tens of tabs gathering dust (and eating RAM) on my desktop. Up to now I just created Foswiki pages or Trello tasks as reminders to tackle these projects later on, but it required enough manual work to often postpone doing it and either losing the info or be swamped in thousands of tabs. And saving them as Firefox bookmarks was cumbersome and required lots of manual management.

What I decided to do is a simple way to save all these tabs offline, and be able to re-open the window simply. I bundle them into what I call .ffst files (for FireFox Saved Tabs), simple text files of one url per line, into a ~/firefox-savedtabs/ directory.

  • Saving a set of tabs:

    • Select the tabs (click on the first one, shift-click on the last one)
    • Open the right-mouse-button menu on a tab, and select Copy URLs
    • Create a new file (e.g: some-name.ffst) in the ~/firefox-savedtabs/ directory with your favorite editor,
    • Paste the tabs into it,
    • Save.
  • Restoring the tabs into a new window: either by:

    • running the script below firefox-savedtabs-restore without arguments, and choosing which file to restore.
    • running the script with the ffst file as argument:
      firefox-savedtabs-restore some-name.ffst
    • Browsing the directory ~/firefox-savedtabs/ in a file explorer window, and choosing to open the .ffst file with Firefox SavedTabs restore once you have created the ~/.local/share/applications/firefox-savedtabs.desktop file below

I can thus just mention the .ffstr file in my various "todo" places (TODO lists, TODO files, pinboard, wikis, trello, ...)

Note that you can adapt this to any browser, and choose whatever directory name and file extension you want.

Updating the tabs is just re-copying the urls and re-pasting in the file.

The two scripts are:🔗

/usr/local/bin/firefox-savedtabs-restore🔗

Note that you can modify in it the restore function to use with another browser.

#!/bin/bash
# shellcheck disable=SC1090,SC2155,SC2046 # source files, declare&assign

# restore saved tabs bundles (text files of urls, one per line)

dir="$HOME/firefox-savedtabs/"

restore(){
    mapfile -t urls <"$1"
    firefox --new-window "${urls[@]}"
    exit 0
}

if [[ $# == 0 ]]; then
    # Without args, list the saves, most recent first, and prompt to restore
    echo "In ~/.firefox-savedtabs/"
    cd "$dir" || exit 1
    select i in $(find . -type f -name \*.ffst \
                    -printf '%TY-%Tm-%Td.%THh%TM:%TS %h/%f\n' | \
                   sed -e 's| [.]/|_|' | sort -r | \
                   sed -re 's/:[0-9]{2}[.][0-9]*//'); do
        restore "${i#*_}"
    done            
else
    # with a file name or path, restore the window
    file="$1"
    if [[ -e "$file" ]]; then
        restore "$file"
    elif ! [[ -e "$file" ]] && [[ -e "$dir/$file" ]]; then
        file="$dir/$file"
        restore "$file"
    else
        echo "***Error: file not found: \"$file\" in $dir"
        exit 1
    fi
fi

~/.local/share/applications/firefox-savedtabs.desktop🔗

[Desktop Entry]
Name=Firefox SavedTabs restore
# update-desktop-database ~/.local/share/applications/
Exec=/usr/local/bin/firefox-savedtabs-restore %u
Type=Application
Terminal=false
MimeType=x-scheme-handler/x-firefox-savedtabs;
Table of Contents