From df34a871cbcf7a7943cf0b1935caa5ad66ce4ed4 Mon Sep 17 00:00:00 2001 From: rupa Date: Thu, 28 Mar 2013 23:30:55 -0400 Subject: [PATCH 1/2] Warn user if z's datafile path is a directory. Cause this means z will fill up the directory with temp files, and not work. --- README | 3 ++- z.1 | 3 ++- z.sh | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README b/README index 6225b2d..ec5abc6 100644 --- a/README +++ b/README @@ -120,7 +120,8 @@ ENVIRONMENT FILES Data is stored in $HOME/.z. This can be overridden by setting the - $_Z_DATA environment variable. + $_Z_DATA environment variable. When initialized, z will raise an error + if this path is a directory, and not function correctly. A man page (z.1) is provided. diff --git a/z.1 b/z.1 index 2ba6de7..022a4b3 100644 --- a/z.1 +++ b/z.1 @@ -144,7 +144,8 @@ Directories must be full paths without trailing slashes. .SH FILES Data is stored in \fB$HOME/.z\fR. This can be overridden by setting the -\fB$_Z_DATA\fR environment variable. +\fB$_Z_DATA\fR environment variable. When initialized, \fBz\fR will raise an +error if this path is a directory, and not function correctly. .P A man page (\fBz.1\fR) is provided. .SH diff --git a/z.sh b/z.sh index 555b3b6..7e444ef 100644 --- a/z.sh +++ b/z.sh @@ -27,6 +27,10 @@ case $- in *) echo 'ERROR: z.sh is meant to be sourced, not directly executed.' esac +[ -d "${_Z_DATA:-$HOME/.z}" ] && { + echo "ERROR: z.sh's datafile (${_Z_DATA:-$HOME/.z}) is a directory." +} + _z() { local datafile="${_Z_DATA:-$HOME/.z}" From b9afd5faaddd62067a5f37084c35476e8b2e4cc8 Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Sat, 11 May 2013 19:38:37 +0200 Subject: [PATCH 2/2] New option: -x Removes the current directory from the data file. Use case: sometimes `z tmp` lead me to `/tmp` whereas I was expecting to be in `~/tmp`, with the new option I can do `z -x tmp`: it removes `/tmp` from the data file and jumps to `~/tmp`. --- z.1 | 5 ++++- z.sh | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/z.1 b/z.1 index 022a4b3..6525bf1 100644 --- a/z.1 +++ b/z.1 @@ -4,7 +4,7 @@ NAME z \- jump around .SH SYNOPSIS -z [\-chlrt] [regex1 regex2 ... regexn] +z [\-chlrtx] [regex1 regex2 ... regexn] .SH AVAILABILITY bash, zsh @@ -31,6 +31,9 @@ match by rank only .TP \fB\-t\fR match by recent access only +.TP +\fB\-x\fR +remove the current directory from the datafile .SH EXAMPLES .TP 14 \fBz foo\fR diff --git a/z.sh b/z.sh index 7e444ef..20539c5 100644 --- a/z.sh +++ b/z.sh @@ -108,7 +108,8 @@ _z() { --) while [ "$1" ]; do shift; local fnd="$fnd $1";done;; -*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in c) local fnd="^$PWD $fnd";; - h) echo "${_Z_CMD:-z} [-chlrt] args" >&2; return;; + h) echo "${_Z_CMD:-z} [-chlrtx] args" >&2; return;; + x) sed -i "\:^${PWD}|.*:d" "$datafile";; l) local list=1;; r) local typ="rank";; t) local typ="recent";;