1
0
Fork 0

firefox-home-profile/init.zsh: Added cache-directory support

pull/890/head
tokiclover 10 years ago
parent f0cfb685ff
commit 16d3b2ce6a

@ -1,21 +1,22 @@
# #
# firefox home profile (fhp) maintains the profile # Firefox-Home-Profile (fhp) maintains profile & associated
# in a tmpfs or zram backed filesystem # cache directory in a tmpfs (or zram backed) filesystem
# #
# $Header: firefox-profile/init.zsh Exp $ # $Header: firefox-home-profile/init.zsh Exp $
# $Aythor: (c) 2011-2014 -tclover <tokiclover@gmail.com> Exp $ # $Aythor: (c) 2012-2015 -tclover <tokiclover@gmail.com> Exp $
# $License: MIT (or 2-clause/new/simplified BSD) Exp $ # $License: MIT (or 2-clause/new/simplified BSD) Exp $
# $Version: 3.0 2014/09/26 21:09:26 Exp $ # $Version: 4.0 2015/05/05 21:09:26 Exp $
# #
#
# Initialize the temporary directory with an anonymous function # Initialize the temporary directory with an anonymous function
#
function { function {
local compressor profile zramdir zsh_hook local compressor profile tmpdir zsh_hook
zstyle -s ':prezto:module:FHP' profile 'profile'
zstyle -s ':prezto:module:firefox-profile' profile 'profile' zstyle -s ':prezto:module:FHP' compressor 'compressor'
zstyle -s ':prezto:module:firefox-profile' compressor 'compressor' zstyle -b ':prezto:module:FHP' zsh-hook 'zsh_hook'
zstyle -b ':prezto:module:firefox-profile' zsh-hook 'zsh_hook' zstyle -s ':prezto:module:FHP' tmpdir 'tmpdir'
zstyle -s ':prezto:module:firefox-profile' zramdir 'zramdir'
# Define a little helper to handle fatal errors # Define a little helper to handle fatal errors
function die { function die {
@ -25,65 +26,57 @@ function {
} }
if (( $+compressor )) { if (( $+compressor )) {
: ${compressor:=lz4 -1 -} : ${compressor:=lz4 -1 -}
zstyle ':prezto:module:firefox-profile' compressor "$compressor" zstyle ':prezto:module:FHP' compressor "$compressor"
} }
setopt LOCAL_OPTIONS EXTENDED_GLOB setopt LOCAL_OPTIONS EXTENDED_GLOB
: ${profile:=$(print $HOME/.mozilla/firefox/*.default(/N:t))} : ${profile:=$(print $HOME/.mozilla/firefox/*.default(/N:t))}
if [[ -z $profile ]] { if [[ -z $profile ]] {
die "null firefox home profile" die "Null firefox home profile"
return return 1
} }
[[ ${profile%.default} == $profile ]] && profile+=.default case $profile {
zstyle ':prezto:module:firefox-profile' profile "$profile" (*.default) ;;
(*) profile+=.default;;
}
zstyle ':prezto:module:FHP' profile "$profile"
local ext=.tar.$compressor[(w)1]
: ${tmpdir:=${TMPDIR:-/tmp/$USER}}
if (( $zsh_hook )) { if (( $zsh_hook )) {
autoload -Uz add-zsh-hook autoload -Uz add-zsh-hook
add-zsh-hook zshexit fhp add-zsh-hook zshexit fhp
} }
local ext=.tar.$compressor[(w)1] [[ -d "$tmpdir" ]] || mkdir -p -m 1700 "$TMPDIR" ||
local fhpdir="$HOME"/.mozilla/firefox/$profile { die "no suitable directory found"; return 2; }
: ${TMPDIR:=/tmp/$USER}
[[ -n $zramdir ]] || [[ -d "$TMPDIR" ]] || mkdir -p -m1700 "$TMPDIR"
if (( $? )) {
die "no suitable directory found"
return
}
mount | grep -q "$fhpdir" && return local c dir mktmp=checkpath DIR
for dir ("$HOME"/.{,cache/}mozilla/firefox/$profile) {
if [[ ! -f "$fhpdir$ext" ]] || [[ ! -f "$fhpdir.old$ext" ]] { grep -q "$dir" /proc/mounts && continue
pushd -q "$fhpdir:h" || return pushd -q "$dir:h" || continue
tar -Ocp $profile | $=compressor $profile$ext if [[ ! -f "$profile$ext" ]] || [[ ! -f "$profile.old$ext" ]] {
if (( $? )) { tar -Ocp $profile | $=compressor $profile$ext ||
popd -q { die "failed to pack a new tarball"; continue; }
die "failed to pack a new tarball"
return
} }
popd -q popd -q
}
local mktmp=mktmp mntdir case "$dir" {
(( $+commands[mktemp] )) && mktmp=$commands[mktemp] (*.cache/*) c=c;;
(*) c=p;;
[[ -n $zramdir ]] && }
mntdir=$($mktmp -d "$zramdir"/fhp-XXXXXX) || (( $+commands[mktemp] )) && mktmp=$commands[mktemp]
mntdir=$($mktmp -d "$TMPDIR"/fhp-XXXXXX) DIR=$($mktmp -p "$tmpdir" -d fh${c}-XXXXXX)
sudo mount --bind "$DIR" "$dir" ||
sudo mount --bind "$mntdir" "$fhpdir" { die "failed to mount $DIR"; continue; }
if (( $? )) {
die "failed to mount $mntdir"
return
} }
#
# Finaly, start the firefox home profile # Finaly, start the firefox home profile
#
#(( $+functions[fhp] )) || autoload -Uz fhp #(( $+functions[fhp] )) || autoload -Uz fhp
if zstyle -t ':prezto:module:firefox-profile' start-profile; then if zstyle -t ':prezto:module:FHP' decompress; then
fhp fhp
fi fi
} }

Loading…
Cancel
Save