-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcowsay.as
More file actions
executable file
·50 lines (43 loc) · 1.11 KB
/
cowsay.as
File metadata and controls
executable file
·50 lines (43 loc) · 1.11 KB
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
#!/usr/bin/env agfs
# Cowsay Script
#
# Usage:
# source cowsay.as
# cowsay "Your message here"
#
# This script registers a cowsay function in the shell.
# The function displays a cow saying the provided message.
cowsay() {
if [ -z "$1" ]; then
local msg="Moo!"
else
local msg="$*"
fi
# Calculate message length using wc -c
local len=$(echo "$msg" | wc -c)
len=$((len - 1))
# Build the speech bubble top border
local border=""
local i=0
while [ $i -lt $((len + 2)) ]; do
border="${border}_"
i=$((i + 1))
done
# Build the speech bubble bottom border
local border_bottom=""
i=0
while [ $i -lt $((len + 2)) ]; do
border_bottom="${border_bottom}-"
i=$((i + 1))
done
# Print the speech bubble
echo " $border"
echo "< $msg >"
echo " $border_bottom"
# Print the cow body - using single quotes to preserve literal characters
echo ' \ ^__^'
echo ' \ (oo)\_______'
echo ' (__)\ )\/\'
echo ' ||----w |'
echo ' || ||'
}