Remove all eval usage

This commit is contained in:
Dylan Araps
2016-11-07 17:54:38 +11:00
parent 12e2a8b03b
commit 174eb66b56
27 changed files with 227 additions and 274 deletions

View File

@@ -2002,25 +2002,28 @@ getascii() {
fi
fi
# Eval colors
print="$(eval printf "$(<"$ascii")")"
# Turn file into variable
while IFS=$'\n' read -r line 2>/dev/null; do
print+="${line} \n"
# Calculate size of ascii file in line length / line count.
line="${line//\$\{??\}}"
line="${line//'\\'/'\'}"
[[ "${#line}" -gt "${ascii_length:-0}" ]] && ascii_length="${#line}"
lines="$((lines+=1))"
done < "$ascii"
# Colors
print="${print//'${c1}'/$c1}"
print="${print//'${c2}'/$c2}"
print="${print//'${c3}'/$c3}"
print="${print//'${c4}'/$c4}"
print="${print//'${c5}'/$c5}"
print="${print//'${c6}'/$c6}"
# Set locale to get correct padding
export LC_ALL="$SYS_LOCALE"
# Turn the file into a variable and strip escape codes.
ascii_strip="$(<"$ascii")"
ascii_strip="${ascii_strip//\$\{??\}}"
ascii_strip="${ascii_strip//'\\'/ }"
ascii_strip="${ascii_strip//'\'}"
# Get lines/columns of the ascii file.
lines=1
while IFS=$'\n' read -r line 2>/dev/null; do
[[ "${#line}" -gt "${ascii_length:-0}" ]] && ascii_length="${#line}"
lines="$((lines+=1))"
done <<< "$ascii_strip"
# Overwrite padding if ascii_length_force is set.
[[ "$ascii_length_force" ]] && ascii_length="$ascii_length_force"
@@ -2086,7 +2089,7 @@ getimage() {
[[ "$image_backend" != "iterm2" ]]; then
current_window="$(xdotool getactivewindow)"
eval "$(xdotool getwindowgeometry --shell "$current_window")"
source <(xdotool getwindowgeometry --shell "$current_window")
term_height="$HEIGHT"
term_width="$WIDTH"
@@ -2518,6 +2521,10 @@ colors() {
setcolors 4 8
;;
"BunsenLabs"*)
setcolors 8 7
;;
*"OS X"* | *"iOS"* | "Mac" | *"macOS"*)
setcolors 2 3 1 1 5 4
ascii_distro="mac"
@@ -3307,7 +3314,7 @@ main() {
displayimage
# Set cursor position next to ascii art
printf "\033[$((${lines:-4} - ${prompt_loc:-4}))A"
printf "\033[$((${lines:-0} - ${prompt_loc:-0}))A"
# Reset horizontal cursor position
printf "\033[9999999D"