1
0
Fork 0

modules: firefox-profile: init.zsh clean up

Cleaned up init.zsh, so the whole initialization code is handled by
an anonymous function. This is make variable clean up much easier.
FIx the version string (bumped to 3.0, 2.x is standalone script
that can be sourced in ~/.zshrc (see my dotfiles repo for that).)

Minor fix for mktmp() for non GNU/Linux users.
pull/683/head
tokiclover 10 years ago
parent ca75bfef45
commit f5740922e8

@ -28,7 +28,7 @@ return
test $# -ge 1 -a -n "$1" || return test $# -ge 1 -a -n "$1" || return
local type temp=-XXXXXX tmpdir=${TMPDIR:-/tmp} local type temp=XXXXXX tmpdir=${TMPDIR:-/tmp}
for (( ; $# > 1; )) for (( ; $# > 1; ))
case $1 { case $1 {
(-d|--dir) (-d|--dir)
@ -53,13 +53,13 @@ for (( ; $# > 1; ))
return;; return;;
} }
test -n "$1" -a "${1%$temp}" != "$1" test -n "$1" -a "${1%-$temp}" != "$1"
if (( $? )) { if (( $? )) {
die "invalid/null TEMPLATE" die "invalid/null TEMPLATE"
return return
} }
(( $+commands[uuidgen] )) && temp=$($commands[uuidgen] --random) (( $+commands[uuidgen] )) && temp=$($commands[uuidgen] --random)
local tmp="$tmpdir/${1%$temp}-$temp[1,6]" local tmp="$tmpdir/${1%$temp}$temp[1,6]"
if [[ $type == "dir" ]] { if [[ $type == "dir" ]] {
mkdir -p ${mode:+-m$mode} "$tmp" mkdir -p ${mode:+-m$mode} "$tmp"

@ -1,48 +1,50 @@
# #
# firefox home profile (fhp) module to maintain the profile # firefox home profile (fhp) maintains the profile
# in a tmpfs or zram backed filesystem # in a tmpfs or zram backed filesystem
# #
# $Header: firefox-profile/init.zsh Exp $ # $Header: firefox-profile/init.zsh Exp $
# $Aythor: (c) 2011-2014 -tclover <tokiclover@gmail.com> Exp $ # $Aythor: (c) 2011-2014 -tclover <tokiclover@gmail.com> Exp $
# $License: MIT (or 2-clause/new/simplified BSD) Exp $ # $License: MIT (or 2-clause/new/simplified BSD) Exp $
# $Version: 2.0 2014/09/25 21:09:26 Exp $ # $Version: 3.0 2014/09/26 21:09:26 Exp $
# #
function die { # Initialize the temporary directory with an anonymous function
local ret=$? function {
print -P " %F{red}%1x: %F{yellow}%U%I%u:%f $argv" >&2 local compressor profile zramdir zsh_hook
return $ret
}
setopt EXTENDED_GLOB zstyle -s ':prezto:module:firefox-profile' profile 'profile'
zstyle -s ':prezto:module:firefox-profile' compressor 'compressor'
zstyle -b ':prezto:module:firefox-profile' zsh-hook 'zsh_hook'
zstyle -s ':prezto:module:firefox-profile' zramdir 'zramdir'
zstyle -s ':prezto:module:firefox-profile' profile 'profile' # Define a little helper to handle fatal errors
zstyle -s ':prezto:module:firefox-profile' compressor 'compressor' function die {
zstyle -b ':prezto:module:firefox-profile' zsh-hook 'zsh_hook' local ret=$?
zstyle -s ':prezto:module:firefox-profile' zramdir 'zramdir' print -P " %F{red}%2x: %F{yellow}%U%I%u:%f $argv" >&2
return $ret
}
if [[ -z "$compressor" ]] { if (( $+compressor )) {
: ${compressor:=lz4 -1 -} : ${compressor:=lz4 -1 -}
zstyle ':prezto:module:firefox-profile' compressor "$compressor" zstyle ':prezto:module:firefox-profile' compressor "$compressor"
} }
: ${profile:=${$(print $HOME/.mozilla/firefox/*.default(/N)):t}} setopt LOCAL_OPTIONS EXTENDED_GLOB
if [[ -z $profile ]] {
unset compressor profile zramdir zsh_hook : ${profile:=$(print $HOME/.mozilla/firefox/*.default(/N:t))}
if [[ -z $profile ]] {
die "null firefox home profile" die "null firefox home profile"
return return
} }
[[ ${profile%.default} == $profile ]] && profile+=.default [[ ${profile%.default} == $profile ]] && profile+=.default
zstyle ':prezto:module:firefox-profile' profile "$profile" zstyle ':prezto:module:firefox-profile' profile "$profile"
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
} }
# Initialize the temporary directory with an anonymous function
function {
local ext=.tar.$compressor[(w)1] local ext=.tar.$compressor[(w)1]
local fhpdir="$HOME"/.mozilla/firefox/$profile local fhpdir="$HOME"/.mozilla/firefox/$profile
: ${TMPDIR:=/tmp/$USER} : ${TMPDIR:=/tmp/$USER}
@ -77,15 +79,13 @@ function {
die "failed to mount $mntdir" die "failed to mount $mntdir"
return 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:firefox-profile' start-profile; then
fhp fhp
fi fi
}
unset compressor profile zramdir zsh_hook
# #
# vim:fenc=utf-8:ft=zsh:ci:pi:sts=2:sw=2:ts=2: # vim:fenc=utf-8:ft=zsh:ci:pi:sts=2:sw=2:ts=2:

Loading…
Cancel
Save