Put no resolve symlinks option back

This commit is contained in:
rupa committed 2013-12-24 23:55:19 -05:00
1 parent b7c36ad4cd
commit 71bedb4297
4 files changed
+31 -11

No files matched your search

+5
View File
@@ -61,6 +61,7 @@ NOTES
Optionally:
Set $_Z_CMD to change the command name (default z).
Set $_Z_DATA to change the datafile (default $HOME/.z).
Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd your-
self.
Set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
@@ -111,6 +112,10 @@ ENVIRONMENT
The environment variable $_Z_DATA can be used to control the datafile
location. If it is not defined, the location defaults to $HOME/.z.
The environment variable $_Z_NO_RESOLVE_SYMLINKS can be set to prevent
resolving of symlinks. If it is not set, symbolic links will be
resolved when added to the datafile.
In bash, z appends a command to the PROMPT_COMMAND environment variable
to maintain its database. In zsh, z appends a function _z_precmd to the
precmd_functions array.
+7
View File
@@ -83,6 +83,9 @@ Set \fB$_Z_CMD\fR to change the command name (default \fBz\fR).
Set \fB$_Z_DATA\fR to change the datafile (default \fB$HOME/.z\fR).
.RE
.RS
Set \fB$_Z_NO_RESOLVE_SYMLINKS\fR to prevent symlink resolution.
.RE
.RS
Set \fB$_Z_NO_PROMPT_COMMAND\fR to handle \fBPROMPT_COMMAND/precmd\fR yourself.
.RE
.RS
@@ -137,6 +140,10 @@ set, \fB$_Z_CMD\fR defaults to \fBz\fR.
The environment variable \fB$_Z_DATA\fR can be used to control the datafile
location. If it is not defined, the location defaults to \fB$HOME/.z\fR.
.P
The environment variable \fB$_Z_NO_RESOLVE_SYMLINKS\fR can be set to prevent
resolving of symlinks. If it is not set, symbolic links will be resolved when
added to the datafile.
.P
In bash, \fBz\fR appends a command to the \fBPROMPT_COMMAND\fR environment
variable to maintain its database. In zsh, \fBz\fR appends a function
\fB_z_precmd\fR to the \fBprecmd_functions\fR array.
+12 -4
View File
@@ -154,13 +154,21 @@ _z() {
alias ${_Z_CMD:-z}='_z 2>&1'
[ "$_Z_NO_RESOLVE_SYMLINKS" ] || _Z_RESOLVE_SYMLINKS="-P"
if compctl >/dev/null 2>&1; then
# zsh
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list, avoid clobbering any other precmds.
_z_precmd() {
/usr/local/bin/_z_prompt_command
}
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
_z_precmd() {
/usr/local/bin/_z_prompt_command "${PWD:a}"
}
else
_z_precmd() {
/usr/local/bin/_z_prompt_command "${PWD:A}"
}
fi
[[ -n "${precmd_functions[(r)_z_precmd]}" ]] || {
precmd_functions[$(($#precmd_functions+1))]=_z_precmd
}
@@ -179,7 +187,7 @@ elif complete >/dev/null 2>&1; then
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list. avoid clobbering other PROMPT_COMMANDs.
grep "_z_prompt_command" <<< "$PROMPT_COMMAND" >/dev/null || {
PROMPT_COMMAND="$PROMPT_COMMAND"$'\n'"/usr/local/bin/_z_prompt_command;"
PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''/usr/local/bin/_z_prompt_command "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)";'
}
}
fi
+7 -7
View File
@@ -7,24 +7,24 @@
#include <time.h>
#include <unistd.h>
int main() {
int main(int argc, char **argv) {
if (argv[1] == NULL) return 0;
char * _Z_DATA;
char datafile[PATH_MAX];
char tmpfile[PATH_MAX];
FILE *read;
FILE *write;
char line[LINE_MAX];
char cwd[PATH_MAX];
char pth[PATH_MAX];
float rank;
int timestamp;
time_t epoch = time(NULL);
int found = 0;
if (getcwd(cwd, sizeof(cwd)) == NULL) return EXIT_FAILURE;
// Don't track $HOME
if (strcmp(cwd, getenv("HOME")) == 0) return EXIT_SUCCESS;
if (strcmp(argv[1], getenv("HOME")) == 0) return EXIT_SUCCESS;
_Z_DATA = getenv("_Z_DATA");
if( _Z_DATA == NULL ) {
@@ -42,12 +42,12 @@ int main() {
while (fgets(line, sizeof line, read) != NULL) {
sscanf(line, "%[^|]|%f|%d\n", pth, &rank, &timestamp);
if (strcmp(pth, cwd) == 0) {
if (strcmp(pth, argv[1]) == 0) {
fprintf(write, "%s|%f|%d\n", pth, rank + 1, (int) epoch);
found = 1;
} else fprintf(write, "%s", line);
}
if (!found) fprintf(write, "%s|1|%d\n", cwd, (int) epoch);
if (!found) fprintf(write, "%s|1|%d\n", argv[1], (int) epoch);
fclose(read);
fclose(write);