groff insert images from url, still crashes sometimes :(
This commit is contained in:
parent
29a716d844
commit
79363d5619
3 changed files with 1955 additions and 5 deletions
|
@ -35,18 +35,32 @@ auto_pdfpic() {
|
||||||
echo "$LINE" | sed 's|^.IMG|.PDFPIC|' | sed "s|$IMAGE|${IMAGE%%.*}.pdf|"
|
echo "$LINE" | sed 's|^.IMG|.PDFPIC|' | sed "s|$IMAGE|${IMAGE%%.*}.pdf|"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Downloads image
|
||||||
|
get_image() {
|
||||||
|
LINE="$1"
|
||||||
|
URL="$(echo "$LINE" | cut -d '"' -f 2)"
|
||||||
|
UID="$(echo "$URL" | sha1sum | head -c 8)"
|
||||||
|
EXT="${URL##*.}"
|
||||||
|
mkdir -p "_img"
|
||||||
|
! [ -e "_img/$UID.$EXT" ] && wget -qO "_img/$UID.$EXT" "$URL"
|
||||||
|
URL="$(echo "$URL" | sed -e 's`[][\\/.*^$]`\\&`g')"
|
||||||
|
echo "$LINE" | sed "s|$URL|_img/$UID\.$EXT|"
|
||||||
|
}
|
||||||
|
|
||||||
# If there is any .IMG command, replace with
|
# If there is any .IMG command, replace with
|
||||||
# auto_pdfpic output in a temp file.
|
# auto_pdfpic output in a temp file.
|
||||||
if [ "$(grep '^.IMG\s' "$FILE")" ] ; then
|
if [ "$(grep '^.IMG\s' "$FILE")" ] ; then
|
||||||
TEMP="${FILE%%.*}.tmp"
|
TEMP="${FILE%%.*}.tmp"
|
||||||
echo $TEMP
|
|
||||||
cp "$FILE" "$TEMP"
|
cp "$FILE" "$TEMP"
|
||||||
while true ; do
|
while true ; do
|
||||||
LINE="$(grep -m 1 '^.IMG\s' "$TEMP")"
|
LINE="$(grep -m 1 '^.IMG\s' "$TEMP")"
|
||||||
[ -n "$LINE" ] &&
|
[ -z "$LINE" ] && break
|
||||||
NEW_LINE="$(auto_pdfpic "$LINE")" &&
|
echo "$LINE" | grep -q '.*"http.*://.*' &&
|
||||||
sed -i "s@$LINE@$NEW_LINE@g" "$TEMP" ||
|
PREV="$(echo "$LINE" | sed -e 's`[][\\/.*^$]`\\&`g')" &&
|
||||||
break
|
LINE="$(get_image "$LINE")" &&
|
||||||
|
sed -i "s@$PREV@$LINE@g" "$TEMP"
|
||||||
|
NEW_LINE="$(auto_pdfpic "$LINE")"
|
||||||
|
sed -i "s@$LINE@$NEW_LINE@g" "$TEMP"
|
||||||
done
|
done
|
||||||
FILE="$TEMP"
|
FILE="$TEMP"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -20,6 +20,7 @@ shopt -s autocd # cd into dir by typing the name
|
||||||
set -o vi # vi mode
|
set -o vi # vi mode
|
||||||
|
|
||||||
# External configs
|
# External configs
|
||||||
|
[ -e "$HOME/.config/shell/posix-kit" ] && source ~/.config/shell/posix-kit
|
||||||
[ -e "$HOME/.config/shell/functions" ] && source ~/.config/shell/functions
|
[ -e "$HOME/.config/shell/functions" ] && source ~/.config/shell/functions
|
||||||
[ -e "$HOME/.config/shell/keybinds" ] && source ~/.config/shell/keybinds
|
[ -e "$HOME/.config/shell/keybinds" ] && source ~/.config/shell/keybinds
|
||||||
[ -e "$HOME/.config/shell/xdgspec" ] && source ~/.config/shell/xdgspec
|
[ -e "$HOME/.config/shell/xdgspec" ] && source ~/.config/shell/xdgspec
|
||||||
|
|
1935
shell/posix-kit
Normal file
1935
shell/posix-kit
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue