zshcd: fixed void variables

master
Pierre Neidhardt 2013-07-26 15:33:44 +02:00
parent f73902496e
commit e195c491a2
1 changed files with 24 additions and 14 deletions

View File

@ -1,9 +1,13 @@
#!/bin/sh
## Start zsh in directory specified as first argument.
if [ ! -d "$1" ]; then
zsh
exit
fi
## Default files.
ZDIRS="$HOME/.cache/zsh/dirs"
SHELL_DIR="$HOME/.shell.d"
## Fetch file location dynamically.
if [ ! -f "$ZDIRS" ]; then
@ -12,24 +16,30 @@ if [ ! -f "$ZDIRS" ]; then
exit
fi
SHELL_DIR_GREP="$(grep "SHELL_DIR=" ~/.zshrc | cut -f2 -d=)"
[ -n "$SHELL_DIR_GREP" ] && SHELL_DIR="$(eval echo "$SHELL_DIR_GREP")"
SHELL_DIR="$HOME/.shell.d"
if [ ! -d "$SHELL_DIR" ]; then
SHELL_DIR_GREP="$(grep "SHELL_DIR=" ~/.zshrc | cut -f2 -d=)"
[ -n "$SHELL_DIR_GREP" ] && SHELL_DIR="$(eval echo "$SHELL_DIR_GREP")"
fi
if [ ! -d "$SHELL_DIR" ]; then
echo 'DIRSTACKFILE and SHELL_DIR not found. Exiting.'
exit
fi
ZDIRS_GREP="$(grep -rm1 'DIRSTACKFILE=' "$SHELL_DIR" | cut -f2 -d=)"
[ -n "$ZDIRS_GREP" ] && ZDIRS="$(eval echo "$ZDIRS_GREP")"
fi
if [ ! -f "$ZDIRS" ]; then
echo 'DIRSTACKFILE not found. Exiting.'
exit
fi
if [ ! -d "$1" ]; then
zsh
else
if [ -n "$(grep "$1" "$ZCACHE")" ]; then
BUF="$(grep -v "$1" "$ZCACHE")"
echo "$BUF"
echo "$BUF" > "$ZCACHE"
fi
prepend "$1" "$ZCACHE"
zsh
fi
if [ -n "$(grep "$1" "$ZDIRS")" ]; then
BUF="$(grep -v "$1" "$ZDIRS")"
echo "$BUF"
echo "$BUF" > "$ZDIRS"
fi
prepend "$1" "$ZDIRS"
zsh