rewrite zshrc to use realpath instead of readlink -f

This commit is contained in:
Dmytro Meleshko 2018-02-23 19:15:26 +02:00
parent b7a2066f41
commit 69343ebdd7

28
zshrc
View file

@ -1,28 +1,16 @@
#!/usr/bin/env bash #!/usr/bin/env bash
find_dotfiles_dir() { find_dotfiles_dir() {
local readlink export DOTFILES_DIR
# readlink=$(which greadlink || which readlink)
local script_path"=${(%):-%x}"
if [[ -n "$script_path" && -x "$readlink" ]]; then for prefix in "$HOME/." "/usr/share/" "/usr/local/share/"; do
script_path=$($readlink -f "$script_path") DOTFILES_DIR="${prefix}dotfiles"
DOTFILES_DIR=$(dirname "$script_path") [[ -d "$DOTFILES_DIR" ]] && return
else done
for prefix in "$HOME/" "$HOME/." "/usr/share/" "/usr/local/share/"; do
local dotfiles_dir="${prefix}dotfiles"
if [[ -d "$dotfiles_dir" ]]; then
DOTFILES_DIR="$dotfiles_dir"
break
fi
done
fi
if [[ -d $DOTFILES_DIR ]]; then local script_path
export DOTFILES_DIR script_path=$(realpath "${(%):-%x}")
else DOTFILES_DIR=$(dirname "$script_path")
echo "dotfiles directory not found"
fi
} }
find_dotfiles_dir find_dotfiles_dir