From 763445330e00eb8ee4ee08051fd3787fd6703e56 Mon Sep 17 00:00:00 2001 From: rupa Date: Sat, 6 Aug 2011 22:46:15 -0400 Subject: [PATCH] allow datafile location to be overriden --- README | 15 ++++++++------- z.1 | 17 ++++++++++------- z.sh | 3 ++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README b/README index d7da938..7f0ac7d 100644 --- a/README +++ b/README @@ -39,14 +39,15 @@ EXAMPLES NOTES Installation: - optionally: - set $_Z_CMD in .bashrc/.zshrc to change the command (default z). + Optionally: + Set $_Z_CMD in .bashrc/.zshrc to change the command (default z). + Set $_Z_DATA to change the datafile (default $HOME/.z). - put something like this in your $HOME/.bashrc: + Put something like this in your $HOME/.bashrc: . /path/to/z.sh - put something like this in your $HOME/.zshrc: + Put something like this in your $HOME/.zshrc: . /path/to/z.sh function precmd () { @@ -57,8 +58,8 @@ NOTES PROFIT!! - optionally: - install the provided man page z.1 somewhere like /usr/local/man/man1. + Optionally: + Install the provided man page z.1 somewhere like /usr/local/man/man1. Aging: @@ -105,7 +106,7 @@ ENVIRONMENT FILES - data is stored in $HOME/.z + Data is stored in $_Z_DATA. If not set, $_Z_DATA defaults to $HOME/.z A man page (z.1) is provided. diff --git a/z.1 b/z.1 index 1eec179..46f348e 100644 --- a/z.1 +++ b/z.1 @@ -39,14 +39,16 @@ directory that matches ALL of the regexes given on the command line. \fBInstallation:\fR .P -optionally: - set \fB$_Z_CMD\fR in .bashrc/.zshrc to change the command (default \fBz\fR). +Optionally: + Set \fB$_Z_CMD\fR in .bashrc/.zshrc to change the command (default \fBz\fR). +.br + Set \fB$_Z_DATA\fR to change the datafile (default \fB$HOME/.z\fR). .P -put something like this in your \fB$HOME/.bashrc\fR: +Put something like this in your \fB$HOME/.bashrc\fR: .P \fB. /path/to/z.sh\fR .P -put something like this in your \fB$HOME/.zshrc\fR: +Put something like this in your \fB$HOME/.zshrc\fR: .P \fB. /path/to/z.sh function precmd () { @@ -57,8 +59,8 @@ put something like this in your \fB$HOME/.zshrc\fR: .P PROFIT!! .P -optionally: - install the provided man page \fBz.1\fR somewhere like \fB/usr/local/man/man1\fB. +Optionally: + Install the provided man page \fBz.1\fR somewhere like \fB/usr/local/man/man1\fB. .br \fBAging:\fR @@ -109,7 +111,8 @@ An alias \fB$_Z_CMD\fR='_z 2>&1' is defined. If not set, \fB$_Z_CMD\fR defaults to \fBz\fR. .SH FILES -data is stored in \fB$HOME/.z\fR +Data is stored in \fB$_Z_DATA\fR. If not set, \fB$_Z_DATA\fR defaults to +\fB$HOME/.z\fR .P A man page (\fBz.1\fR) is provided. diff --git a/z.sh b/z.sh index c785123..753a416 100755 --- a/z.sh +++ b/z.sh @@ -5,6 +5,7 @@ # INSTALL: # * optionally: # set $_Z_CMD in .bashrc/.zshrc to change the command (default z). +# set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z). # * put something like this in your .bashrc: # . /path/to/z.sh # * put something like this in your .zshrc: @@ -24,7 +25,7 @@ _z() { - local datafile="$HOME/.z" + local datafile="${_Z_DATA:-$HOME/.z}" # bail out if we don't own ~/.z (we're another user but our ENV is still set) [ -f "$datafile" -a ! -O "$datafile" ] && return