Merge pull request #289 from dump247/master

Fix infinite loop when parent directory does not exist
This commit is contained in:
Wilhelmina Drengwitz
2019-05-16 13:31:14 -04:00
committed by GitHub

View File

@@ -118,6 +118,8 @@ git_status_shortcuts() {
} }
# Template function for 'git_status_shortcuts'. # Template function for 'git_status_shortcuts'.
_gs_output_file_group() { _gs_output_file_group() {
local relative
for i in ${stat_grp[$1]}; do for i in ${stat_grp[$1]}; do
# Print colored hashes & files based on modification groups # Print colored hashes & files based on modification groups
local c_group="\033[0;$(eval echo -e \$c_grp_$1)" local c_group="\033[0;$(eval echo -e \$c_grp_$1)"
@@ -126,9 +128,10 @@ _gs_output_file_group() {
if [ -z "$project_root" ]; then if [ -z "$project_root" ]; then
relative="${stat_file[$i]}" relative="${stat_file[$i]}"
else else
dest=$(readlink -f "$project_root/${stat_file[$i]}") local absolute="$project_root/${stat_file[$i]}"
local dest=$(readlink -f "$absolute")
local pwd=$(readlink -f "$PWD") local pwd=$(readlink -f "$PWD")
relative="$(_gs_relative_path "$pwd" "$dest" )" relative="$(_gs_relative_path "$pwd" "${dest:-$absolute}" )"
fi fi
if [[ $f -gt 10 && $e -lt 10 ]]; then local pad=" "; else local pad=""; fi # (padding) if [[ $f -gt 10 && $e -lt 10 ]]; then local pad=" "; else local pad=""; fi # (padding)
@@ -149,7 +152,7 @@ _gs_relative_path(){
# Credit to 'pini' for the following script. # Credit to 'pini' for the following script.
# (http://stackoverflow.com/questions/2564634/bash-convert-absolute-path-into-relative-path-given-a-current-directory) # (http://stackoverflow.com/questions/2564634/bash-convert-absolute-path-into-relative-path-given-a-current-directory)
target=$2; common_part=$1; back="" target=$2; common_part=$1; back=""
while [[ "${target#$common_part}" == "${target}" ]]; do while [[ -n "${common_part}" && "${target#$common_part}" == "${target}" ]]; do
common_part="${common_part%/*}" common_part="${common_part%/*}"
back="../${back}" back="../${back}"
done done