-
Notifications
You must be signed in to change notification settings - Fork 0
/
asciicover
executable file
·154 lines (142 loc) · 4.2 KB
/
asciicover
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# released under Creative Commons Attribution-ShareAlike 3.0
# http://creativecommons.org/licenses/by-sa/3.0/
# v1.4.1
# 1. 10. 2012
# dependencies: libcaca, mpc, mpd
#setting optional arguments
dflag=
Dflag=
rflag=
while getopts dDr name
do
case $name in
d) dflag=1;;
D) Dflag=1;;
r) rflag=1;;
?) printf "Usage: Resize window: [-r]\nIncrease pixel density (use a smaller font)(only works in iTerm): [-d]\nIncrease pixel density even more: [-D]\n(If both -d and -D are selected, -d is disabled.)\n"
exit 2;;
esac
done
if [ -n "$dflag" -a -n "$Dflag" ]; then
dflag=
fi
#defining functions
function ascii {
if [ -z "$dflag" -a -z "$Dflag" ]; then
faktor="1.87"
elif [ -n "$Dflag" ]; then
faktor="3"
else
faktor="1.55"
fi
path=$(mpc -f %file% current)
lib1=$(grep -a -m 1 music_directory ~/.mpdconf)
lib2=$(echo ${lib1%\"*})
librarypath=$(echo ${lib2#*\"})
dirpath=$(dirname "$path")
folderpath=$(echo $librarypath"/"$dirpath"/folder.jpg")
height=$(tput lines)
width=$(echo "$height*$faktor"|bc)
if [ -f "$folderpath" ]; then
art=$(img2txt -H $height -W $width --dither none "$folderpath")
echo -e "$art""\c"
else
clear
art=
fi
}
#setting terminal window parameters
clear
printf "\033]2;ASCIICover\007"
ARGUMENTS="none"
read -s -t 1 -n 1 ARGUMENTS
terminal=$(echo $TERM_PROGRAM)
#optional resizing
if [ -n "$rflag" ]; then
if [[ "$terminal" == "iTerm.app" && ! -z "$(defaults read com.googlecode.iterm2|grep "\"Disable Window Resizing\" = 1;")" ]]; then
osascript -e 'tell app "iterm" to set the bounds of the first window to {140, 120, 140+400-12, 120+400+6}'
else
printf "\033[4;388;380t"
fi
fi
tput civis
# density stuff
if [ "$terminal" == "iTerm.app" ]; then
if [ -n "$dflag" -o -n "$Dflag" ]; then
dim=$(osascript -e "tell application \"iterm\" to get the bounds of the first window" | sed "s/,/-/2" | sed "s/ //g")
x1=${dim%%,*}
y1=${dim#*,}
y1=${y1%%-*}
x2=${dim#*-}
x2=${x2%%,*}
y2=${dim##*,}
let "dx=$x2-$x1-10"
let "dy=$y2-$y1-20"
if [ -n "$Dflag" ]; then
osascript <<EOF
tell application "iterm"
activate
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
set the bounds of the first window to {$x1, $y1, $x2, $y2}
end tell
EOF
else
osascript <<EOF
tell application "iterm"
activate
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
tell application "System Events" to keystroke "-" using command down
set the bounds of the first window to {$x1, $y1, $x2, $y2}
end tell
EOF
fi
fi
fi
#running the main loop
ascii
cols=$(tput cols)
while [ "$ARGUMENTS" != "q" ]; do
if [[ "$(dirname "$(mpc -f %file% current)")" != "$dirpath" || "$(tput lines)" != "$height" || "$(tput cols)" != "$cols" || "$ARGUMENTS" == "r" ]]; then
ascii
cols=$(tput cols)
ARGUMENTS="none"
elif [ -z "$(mpc current)" ]; then
: #do nothing
else
echo -e "$art""\c"
fi
sleep 1
read -s -t 1 -n 1 ARGUMENTS
done
#resetting terminal window back to normal
# density stuff
if [ "$terminal" == "iTerm.app" ]; then
if [ -n "$dflag" -o -n "$Dflag" ]; then
osascript <<EOF
tell application "iterm"
activate
tell application "System Events" to keystroke "0" using command down
end tell
EOF
sleep 2
printf "\033[4;$dy;$dx""t"
fi
fi
tput cnorm
printf "\033]2;\007"
clear
exit