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 {
@ -26,64 +27,56 @@ 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
if [[ ! -f "$fhpdir$ext" ]] || [[ ! -f "$fhpdir.old$ext" ]] { local c dir mktmp=checkpath DIR
pushd -q "$fhpdir:h" || return for dir ("$HOME"/.{,cache/}mozilla/firefox/$profile) {
tar -Ocp $profile | $=compressor $profile$ext grep -q "$dir" /proc/mounts && continue
if (( $? )) { pushd -q "$dir:h" || continue
popd -q if [[ ! -f "$profile$ext" ]] || [[ ! -f "$profile.old$ext" ]] {
die "failed to pack a new tarball" tar -Ocp $profile | $=compressor $profile$ext ||
return { die "failed to pack a new tarball"; continue; }
} }
popd -q popd -q
}
local mktmp=mktmp mntdir case "$dir" {
(*.cache/*) c=c;;
(*) c=p;;
}
(( $+commands[mktemp] )) && mktmp=$commands[mktemp] (( $+commands[mktemp] )) && mktmp=$commands[mktemp]
DIR=$($mktmp -p "$tmpdir" -d fh${c}-XXXXXX)
[[ -n $zramdir ]] && sudo mount --bind "$DIR" "$dir" ||
mntdir=$($mktmp -d "$zramdir"/fhp-XXXXXX) || { die "failed to mount $DIR"; continue; }
mntdir=$($mktmp -d "$TMPDIR"/fhp-XXXXXX)
sudo mount --bind "$mntdir" "$fhpdir"
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