Merge pull request #623 from dylanaraps/full_path

General: Neofetch now understands relative paths
This commit is contained in:
Dylan Araps 2017-01-18 19:54:35 +11:00 committed by GitHub
commit e05cf162ac

View file

@ -2013,8 +2013,8 @@ get_ascii() {
ascii_dir="/data/data/com.termux/files/usr/share/neofetch/ascii/distro" ascii_dir="/data/data/com.termux/files/usr/share/neofetch/ascii/distro"
else else
get_script_dir 2>/dev/null [[ -z "$script_dir" ]] && script_dir="$(get_full_path "$0")"
ascii_dir="${script_dir}/ascii/distro" ascii_dir="${script_dir%/*}/ascii/distro"
fi fi
image_source="${ascii_dir}/${ascii_file}" image_source="${ascii_dir}/${ascii_file}"
@ -2056,11 +2056,14 @@ get_ascii() {
get_image_source() { get_image_source() {
case "$image_source" in case "$image_source" in
"auto" | "wall"*) "auto" | "wallpaper")
get_wallpaper 2>/dev/null get_wallpaper 2>/dev/null
;; ;;
*) *)
# Get the absolute path.
image_source="$(get_full_path "$image_source")"
if [[ -d "$image_source" ]]; then if [[ -d "$image_source" ]]; then
shopt -s nullglob shopt -s nullglob
files=("${image_source%/}"/*.{png,jpg,jpeg,jpe,gif}) files=("${image_source%/}"/*.{png,jpg,jpeg,jpe,gif})
@ -3247,22 +3250,32 @@ err() {
err+="$(color 1)[!]\033[0m $1\n" err+="$(color 1)[!]\033[0m $1\n"
} }
get_script_dir() { get_full_path() {
[[ "$script_dir" ]] && return # This function finds the absolute path from a relative one.
# For example "Pictures/Wallpapers" --> "/home/dylan/Pictures/Wallpapers"
# Use $0 to get the script's physical path. # If the file exists in the current directory, stop here.
cd "${0%/*}" || exit [[ -f "${PWD}/${1%/*}" ]] && { printf "%s\n" "${PWD}/${1%/*}"; return; }
script_dir="${0##*/}"
if ! cd "${1%/*}"; then
err "Error: Directory '${1%/*}' doesn't exist or is inaccessible"
err " Check that the directory exists or try another directory."
exit 1
fi
local full_dir="${1##*/}"
# Iterate down a (possible) chain of symlinks. # Iterate down a (possible) chain of symlinks.
while [[ -L "$script_dir" ]]; do while [[ -L "$full_dir" ]]; do
script_dir="$(readlink "$script_dir")" full_dir="$(readlink "$full_dir")"
cd "${script_dir%/*}" || exit cd "${full_dir%/*}" || exit
script_dir="${script_dir##*/}" full_dir="${full_dir##*/}"
done done
# Final directory. # Final directory.
script_dir="$(pwd -P)" full_dir="$(pwd -P)/${1/*\/}"
[[ -e "$full_dir" ]] && printf "%s\n" "$full_dir"
} }
get_default_config() { get_default_config() {
@ -3273,9 +3286,9 @@ get_default_config() {
default_config="/data/data/com.termux/files/etc/neofetch/config" default_config="/data/data/com.termux/files/etc/neofetch/config"
else else
get_script_dir [[ -z "$script_dir" ]] && script_dir="$(get_full_path "$0")"
default_config="${script_dir}/config/config" default_config="${script_dir%/*}/config/config"
travis_config="${script_dir}/config/travis" travis_config="${script_dir%/*}/config/travis"
fi fi
if source "$default_config"; then if source "$default_config"; then
@ -3315,9 +3328,9 @@ get_user_config() {
config_file="${XDG_CONFIG_HOME}/neofetch/config" config_file="${XDG_CONFIG_HOME}/neofetch/config"
else else
get_script_dir [[ -z "$script_dir" ]] && script_dir="$(get_full_path "$0")"
cp "${script_dir}/config/config" "${XDG_CONFIG_HOME}/neofetch" cp "${script_dir%/*}/config/config" "${XDG_CONFIG_HOME}/neofetch"
config_file="${XDG_CONFIG_HOME}/neofetch/config" config_file="${XDG_CONFIG_HOME}/neofetch/config"
fi fi
@ -3984,7 +3997,10 @@ get_args() {
"--config") "--config")
case "$2" in case "$2" in
"none" | "off" | "") ;; "none" | "off" | "") ;;
*) config_file="$2"; get_user_config 2>/dev/null ;; *)
config_file="$(get_full_path "$2")"
get_user_config 2>/dev/null
;;
esac esac
;; ;;
"-v") verbose="on" ;; "-v") verbose="on" ;;