forked from RomaniukVadim/hack_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimg2sf
More file actions
33 lines (27 loc) · 721 Bytes
/
Copy pathimg2sf
File metadata and controls
33 lines (27 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
if [ $# -eq 0 ]; then
echo -e " \n \t ERROR: No arguments provided"
echo -e " \t USAGE: img2sf <path/to/image> <path/to/output>\n"
exit 1
fi
imgw=$(convert -print "%w\n" "$1" /dev/null)
# generate the image
TMPFILE="tmp"
img2xterm "$1" > $TMPFILE
# form the output file
echo 'startline="0"' > $2
echo 'fulloutput=(' >> $2
IFS=''
cat $TMPFILE |
while read line
do
nspaces=$(grep -o " " <<< "$line" | wc -l)
nup=$(grep -o "▀" <<< "$line" | wc -l)
ndown=$(grep -o "▄" <<< "$line" | wc -l)
spaces=$(expr "$imgw" - "$nspaces" - "$nup" - "$ndown")
printf "\"%s%${spaces}s %%s\"\n" "$line" "" >> $2
done
echo ")" >> $2
sed -i "0,/%s/{s/%s/ %s/}" "$2"
# clean up
rm $TMPFILE