You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.2 KiB
87 lines
2.2 KiB
10 years ago
|
#
|
||
10 years ago
|
# Firefox-Home-Profile (fhp) maintains profile & associated
|
||
|
# cache directory in a tmpfs (or zram backed) filesystem
|
||
10 years ago
|
#
|
||
10 years ago
|
# $Header: firefox-home-profile/init.zsh Exp $
|
||
|
# $Aythor: (c) 2012-2015 -tclover <tokiclover@gmail.com> Exp $
|
||
10 years ago
|
# $License: MIT (or 2-clause/new/simplified BSD) Exp $
|
||
10 years ago
|
# $Version: 4.0 2015/05/05 21:09:26 Exp $
|
||
10 years ago
|
#
|
||
|
|
||
10 years ago
|
#
|
||
10 years ago
|
# Initialize the temporary directory with an anonymous function
|
||
10 years ago
|
#
|
||
10 years ago
|
function {
|
||
10 years ago
|
local compressor profile tmpdir zsh_hook
|
||
|
zstyle -s ':prezto:module:FHP' profile 'profile'
|
||
|
zstyle -s ':prezto:module:FHP' compressor 'compressor'
|
||
|
zstyle -b ':prezto:module:FHP' zsh-hook 'zsh_hook'
|
||
|
zstyle -s ':prezto:module:FHP' tmpdir 'tmpdir'
|
||
10 years ago
|
|
||
|
# Define a little helper to handle fatal errors
|
||
|
function die {
|
||
|
local ret=$?
|
||
|
print -P " %F{red}%2x: %F{yellow}%U%I%u:%f $argv" >&2
|
||
|
return $ret
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
if (( $+compressor )) {
|
||
10 years ago
|
: ${compressor:=lz4 -1 -}
|
||
|
zstyle ':prezto:module:FHP' compressor "$compressor"
|
||
10 years ago
|
}
|
||
|
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
||
|
: ${profile:=$(print $HOME/.mozilla/firefox/*.default(/N:t))}
|
||
|
if [[ -z $profile ]] {
|
||
10 years ago
|
die "Null firefox home profile"
|
||
|
return 1
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
case $profile {
|
||
|
(*.default) ;;
|
||
|
(*) profile+=.default;;
|
||
|
}
|
||
|
zstyle ':prezto:module:FHP' profile "$profile"
|
||
|
local ext=.tar.$compressor[(w)1]
|
||
|
: ${tmpdir:=${TMPDIR:-/tmp/$USER}}
|
||
10 years ago
|
|
||
10 years ago
|
if (( $zsh_hook )) {
|
||
|
autoload -Uz add-zsh-hook
|
||
|
add-zsh-hook zshexit fhp
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
[[ -d "$tmpdir" ]] || mkdir -p -m 1700 "$TMPDIR" ||
|
||
|
{ die "no suitable directory found"; return 2; }
|
||
10 years ago
|
|
||
10 years ago
|
local c dir mktmp=checkpath DIR
|
||
|
for dir ("$HOME"/.{,cache/}mozilla/firefox/$profile) {
|
||
|
grep -q "$dir" /proc/mounts && continue
|
||
|
pushd -q "$dir:h" || continue
|
||
|
if [[ ! -f "$profile$ext" ]] || [[ ! -f "$profile.old$ext" ]] {
|
||
|
tar -Ocp $profile | $=compressor $profile$ext ||
|
||
|
{ die "failed to pack a new tarball"; continue; }
|
||
10 years ago
|
}
|
||
|
popd -q
|
||
|
|
||
10 years ago
|
case "$dir" {
|
||
|
(*.cache/*) c=c;;
|
||
|
(*) c=p;;
|
||
|
}
|
||
|
(( $+commands[mktemp] )) && mktmp=$commands[mktemp]
|
||
|
DIR=$($mktmp -p "$tmpdir" -d fh${c}-XXXXXX)
|
||
|
sudo mount --bind "$DIR" "$dir" ||
|
||
|
{ die "failed to mount $DIR"; continue; }
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
#
|
||
10 years ago
|
# Finaly, start the firefox home profile
|
||
10 years ago
|
#
|
||
10 years ago
|
#(( $+functions[fhp] )) || autoload -Uz fhp
|
||
10 years ago
|
if zstyle -t ':prezto:module:FHP' decompress; then
|
||
10 years ago
|
fhp
|
||
|
fi
|
||
|
}
|
||
10 years ago
|
|
||
|
#
|
||
|
# vim:fenc=utf-8:ft=zsh:ci:pi:sts=2:sw=2:ts=2:
|
||
|
#
|