Skip to content

Instantly share code, notes, and snippets.

@dmitryrck
Last active October 5, 2019 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitryrck/458b08b041074ebf6ea053a1a193e3e3 to your computer and use it in GitHub Desktop.
Save dmitryrck/458b08b041074ebf6ea053a1a193e3e3 to your computer and use it in GitHub Desktop.
Script to copy Google Chrome profile to ram and after it closes copy back to disk. It does not sync often. Be aware: you can lose your work, login and also sync your profile with a Google account.

google-chrome-ram.sh

How to run

Download google-chrome-ram.sh make it executable and call it with or without a profile name.

If you call it like this:

$ ./google-chrome-ram.sh

It will use default as the name of the profile.

If you call like this:

$ ./google-chrome-ram.sh work

It will use work as the name of the profile.

You can open as many profiles as you want at the same time. One does not change the other.

How it works

  1. Copy your profile to /dev/shm/google-chrome-XXX (/dev/shm is a RAM disk)
  2. Open google-chrome-stable pointing to that directory
  3. After closing Google Chrome copy back to ~/.local/google-chrome/XXX

WARNING

This script does not sync often, you can and will lose your work if you close without waiting it to sync back.

Be aware.

Also, sync your profile with a Google account.

#!/bin/bash
set -ex
basename=google-chrome-${1-default}
basedir=/dev/shm/$basename
backupdir=/home/dmitry/.local/google-chrome
function copy_to_ram_or_create() {
if [ ! -d $basedir ]
then
if [ -d $backupdir ]
then
copy_to_ram
else
mkdir -p $basedir
fi
fi
}
function copy_to_ram() {
set +x
total=$(find $backupdir | wc -l)
current=0
cp -Rv $backupdir/$basename $basedir | while read line
do
current=$(( $current + 1 ))
echo $(( $current * 100 / $total ))
done | zenity \
--progress \
--auto-close \
--title="$basename" \
--text="Copying profile $basename to ram.\n\nThis might take a while." \
--no-cancel
set -x
}
function copy_to_disk {
set +x
total=$(find $basedir | wc -l)
rsync -vv \
--delete --delete-excluded --delete-after \
--recursive \
"$basedir" ${backupdir}/ | while read line
do
current=$(( $current + 1 ))
echo $(( $current * 100 / $total ))
done | zenity \
--progress \
--auto-close \
--title="$basename" \
--text="Saving profile $basename to disk.\n\nThis might take a while." \
--no-cancel
set -x
}
copy_to_ram_or_create
google-chrome-stable \
--disk-cache-dir=/dev/shm/$basename/cache \
--user-data-dir=/dev/shm/$basename/data
copy_to_disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment