mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-22 12:27:59 +01:00
Removed some weird echos and reindeted the full file
This commit is contained in:
parent
f404ab48d7
commit
e48e73ef4b
1 changed files with 164 additions and 161 deletions
325
ponysay
325
ponysay
|
@ -8,28 +8,29 @@ pony="*"
|
||||||
wrap=""
|
wrap=""
|
||||||
|
|
||||||
if [ "$TERM" = "linux" ]; then
|
if [ "$TERM" = "linux" ]; then
|
||||||
SYSTEMPONIES="/usr/share/ponysay/ttyponies"
|
SYSTEMPONIES="/usr/share/ponysay/ttyponies"
|
||||||
HOMEPONIES="${HOME}/.local/share/ponysay/ttyponies"
|
HOMEPONIES="${HOME}/.local/share/ponysay/ttyponies"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$PONYSAY_COWSAY" = "" ]]; then
|
if [[ "$PONYSAY_COWSAY" = "" ]]; then
|
||||||
cmd=cowsay
|
cmd=cowsay
|
||||||
customcmd=0
|
customcmd=0
|
||||||
else
|
else
|
||||||
cmd="$PONYSAY_COWSAY"
|
cmd="$PONYSAY_COWSAY"
|
||||||
customcmd=1
|
customcmd=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ ${0} == *ponythink ]] &&
|
[[ ${0} == *ponythink ]] &&
|
||||||
if [[ "$PONYSAY_COWTHINK" = "" ]]; then
|
if [[ "$PONYSAY_COWTHINK" = "" ]]; then
|
||||||
cmd=cowthink
|
cmd=cowthink
|
||||||
customcmd=0
|
customcmd=0
|
||||||
else
|
else
|
||||||
cmd="$PONYSAY_COWTHINK"
|
cmd="$PONYSAY_COWTHINK"
|
||||||
customcmd=1
|
customcmd=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
version() {
|
version() {
|
||||||
echo "ponysay v$version"
|
echo "ponysay v$version"
|
||||||
}
|
}
|
||||||
|
|
||||||
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
|
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
|
||||||
|
@ -38,49 +39,51 @@ truncatercmd="${SCRIPTDIR}/../lib/ponysay/truncater"
|
||||||
|
|
||||||
haspq=1
|
haspq=1
|
||||||
if [[ -f './pq4ps-list' ]]; then
|
if [[ -f './pq4ps-list' ]]; then
|
||||||
function qlist
|
function qlist {
|
||||||
{ ./pq4ps-list
|
./pq4ps-list
|
||||||
}
|
}
|
||||||
elif [[ -f '/usr/bin/pq4ps-list' ]]; then
|
elif [[ -f '/usr/bin/pq4ps-list' ]]; then
|
||||||
function qlist
|
function qlist {
|
||||||
{ /usr/bin/pq4ps-list
|
/usr/bin/pq4ps-list
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
haspq=0
|
haspq=0
|
||||||
function qlist
|
function qlist {
|
||||||
{ cat
|
cat
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
list() {
|
list() {
|
||||||
echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m"
|
echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m"
|
||||||
perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort) | qlist
|
perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort) | qlist
|
||||||
|
|
||||||
if [[ -d $HOMEPONIES ]]; then
|
if [[ -d $HOMEPONIES ]]; then
|
||||||
echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m"
|
echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m"
|
||||||
perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed -e 's/\.pony$//' | sort) | qlist
|
perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed -e 's/\.pony$//' | sort) | qlist
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_linklist() {
|
_linklist() {
|
||||||
echo -e "\\e[01mponyfiles located in $1:\\e[21m"
|
echo -e "\\e[01mponyfiles located in $1:\\e[21m"
|
||||||
files=$(ls --color=no $1 | sed -e 's/\.pony$//' | sort)
|
files=$(ls --color=no $1 | sed -e 's/\.pony$//' | sort)
|
||||||
|
|
||||||
args=""
|
args=""
|
||||||
|
|
||||||
for file in $files; do
|
for file in $files; do
|
||||||
target=$(readlink $1"/"$file".pony")
|
target=$(readlink $1"/"$file".pony")
|
||||||
if [[ $target = "" ]]; then
|
|
||||||
target=$file
|
if [[ $target = "" ]]; then
|
||||||
else
|
target=$file
|
||||||
target=$(echo $target | sed -e 's/^\.\///g' -e 's/\.pony$//g')
|
else
|
||||||
fi
|
target=$(echo $target | sed -e 's/^\.\///g' -e 's/\.pony$//g')
|
||||||
args=$(echo $args $file $target)
|
fi
|
||||||
done
|
|
||||||
|
args=$(echo $args $file $target)
|
||||||
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
|
done
|
||||||
|
|
||||||
perl '/dev/stdin' $(echo $args) <<EOF | sed -e 's/ /_/g' > '/dev/shm/.ponysay~'
|
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
|
||||||
|
|
||||||
|
perl '/dev/stdin' $(echo $args) <<EOF | sed -e 's/ /_/g' > '/dev/shm/.ponysay~'
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
#Author: Mattias Andrée (maandree@kth.se)
|
#Author: Mattias Andrée (maandree@kth.se)
|
||||||
|
@ -146,21 +149,22 @@ while (\$i < \$argc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
perl $listcmd $scrw $(cat "/dev/shm/.ponysay~") | sed -e 's/_/ /g' | qlist
|
perl $listcmd $scrw $(cat "/dev/shm/.ponysay~") | sed -e 's/_/ /g' | qlist
|
||||||
rm '/dev/shm/.ponysay~'
|
rm '/dev/shm/.ponysay~'
|
||||||
}
|
}
|
||||||
|
|
||||||
linklist() {
|
linklist() {
|
||||||
_linklist $SYSTEMPONIES
|
_linklist $SYSTEMPONIES
|
||||||
if [[ -d $HOMEPONIES ]]; then
|
|
||||||
_linklist $HOMEPONIES
|
if [[ -d $HOMEPONIES ]]; then
|
||||||
fi
|
_linklist $HOMEPONIES
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
version
|
version
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
${0##*/} [options] [message]
|
${0##*/} [options] [message]
|
||||||
|
@ -173,12 +177,14 @@ Options:
|
||||||
-l List pony files.
|
-l List pony files.
|
||||||
-L List pony files with synonyms inside brackets.
|
-L List pony files with synonyms inside brackets.
|
||||||
EOF
|
EOF
|
||||||
if [[ $haspq = 1 ]]; then
|
|
||||||
cat <<EOF
|
if [[ $haspq = 1 ]]; then
|
||||||
|
cat <<EOF
|
||||||
-q Use the pony quote feature.
|
-q Use the pony quote feature.
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
cat <<EOF
|
|
||||||
|
cat <<EOF
|
||||||
-f[name] Select a pony (either a file name or a pony name.)
|
-f[name] Select a pony (either a file name or a pony name.)
|
||||||
-W[column] The screen column where the message should be wrapped.
|
-W[column] The screen column where the message should be wrapped.
|
||||||
|
|
||||||
|
@ -188,144 +194,141 @@ EOF
|
||||||
|
|
||||||
# if no stdin and no arguments then print usage and exit
|
# if no stdin and no arguments then print usage and exit
|
||||||
if [[ -t 0 && $# == 0 ]]; then
|
if [[ -t 0 && $# == 0 ]]; then
|
||||||
usage
|
usage
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
say() {
|
say() {
|
||||||
# Ponies use UTF-8 drawing characters. Prevent a Perl warning.
|
# Ponies use UTF-8 drawing characters. Prevent a Perl warning.
|
||||||
export PERL_UNICODE=S
|
export PERL_UNICODE=S
|
||||||
|
|
||||||
if [ "$TERM" = "linux" ]; then
|
if [ "$TERM" = "linux" ]; then
|
||||||
echo -ne '\e[H\e[2J'
|
echo -ne '\e[H\e[2J'
|
||||||
fi
|
|
||||||
|
|
||||||
function wtrunc
|
|
||||||
{
|
|
||||||
if [ "$PONYSAY_FULL_WIDTH" = 'yes' ] || [ "$PONYSAY_FULL_WIDTH" = 'y' ] || [ "$PONYSAY_FULL_WIDTH" = '1' ]; then
|
|
||||||
cat
|
|
||||||
else
|
|
||||||
WIDTH=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
|
|
||||||
$truncatercmd $WIDTH 2>/dev/null || cat
|
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
function wtrunc {
|
||||||
if [ "$PONYSAY_SHELL_LINES" = "" ]; then
|
if [ "$PONYSAY_FULL_WIDTH" = 'yes' ] || [ "$PONYSAY_FULL_WIDTH" = 'y' ] || [ "$PONYSAY_FULL_WIDTH" = '1' ]; then
|
||||||
PONYSAY_SHELL_LINES=2
|
cat
|
||||||
fi
|
else
|
||||||
function htrunchead
|
WIDTH=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
|
||||||
{
|
$truncatercmd $WIDTH 2>/dev/null || cat
|
||||||
head --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES ))
|
fi
|
||||||
}
|
|
||||||
function htrunctail
|
|
||||||
{
|
|
||||||
tail --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES ))
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ $customcmd = 0 ]]; then
|
|
||||||
function cowcmd
|
|
||||||
{
|
|
||||||
echo "standrd $cmd"
|
|
||||||
pcmd='#!/usr/bin/perl\nuse utf8;'
|
|
||||||
ccmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done)
|
|
||||||
echo "is $cmd"
|
|
||||||
if [[ ${0} == *ponythink ]]; then
|
|
||||||
cat <(echo -e $pcmd) $ccmd > "/dev/shm/.ponythink"
|
|
||||||
perl '/dev/shm/.ponythink' "$@"
|
|
||||||
rm '/dev/shm/.ponythink'
|
|
||||||
else
|
|
||||||
perl <(cat <(echo -e $pcmd) $ccmd) "$@"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
function cowcmd
|
if [ "$PONYSAY_SHELL_LINES" = "" ]; then
|
||||||
{
|
PONYSAY_SHELL_LINES=2
|
||||||
echo "custom $cmd"
|
fi
|
||||||
$cmd "$@"
|
|
||||||
}
|
function htrunchead {
|
||||||
fi
|
head --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES ))
|
||||||
|
}
|
||||||
if [ "$TERM" = "linux" ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'yes' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'y' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = '1' ]; then
|
|
||||||
if [ "$PONYSAY_BOTTOM" = 'yes' ] || [ "$PONYSAY_BOTTOM" = 'y' ] || [ "$PONYSAY_BOTTOM" = '1' ]; then
|
function htrunctail {
|
||||||
cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunctail
|
tail --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES ))
|
||||||
else
|
}
|
||||||
cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunchead
|
|
||||||
|
if [[ $customcmd = 0 ]]; then
|
||||||
|
function cowcmd {
|
||||||
|
pcmd='#!/usr/bin/perl\nuse utf8;'
|
||||||
|
ccmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done)
|
||||||
|
|
||||||
|
if [[ ${0} == *ponythink ]]; then
|
||||||
|
cat <(echo -e $pcmd) $ccmd > "/dev/shm/.ponythink"
|
||||||
|
perl '/dev/shm/.ponythink' "$@"
|
||||||
|
rm '/dev/shm/.ponythink'
|
||||||
|
else
|
||||||
|
perl <(cat <(echo -e $pcmd) $ccmd) "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
else
|
||||||
|
function cowcmd {
|
||||||
|
echo "custom $cmd"
|
||||||
|
$cmd "$@"
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TERM" = "linux" ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'yes' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'y' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = '1' ]; then
|
||||||
|
if [ "$PONYSAY_BOTTOM" = 'yes' ] || [ "$PONYSAY_BOTTOM" = 'y' ] || [ "$PONYSAY_BOTTOM" = '1' ]; then
|
||||||
|
cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunctail
|
||||||
|
else
|
||||||
|
cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunchead
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ponies=()
|
ponies=()
|
||||||
|
|
||||||
opts="f:W:Llhv"
|
opts="f:W:Llhv"
|
||||||
if [[ $haspq ]]; then
|
if [[ $haspq ]]; then
|
||||||
opts=$opts"q"
|
opts=$opts"q"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
usepq=0
|
usepq=0
|
||||||
while getopts $opts OPT
|
while getopts $opts OPT; do
|
||||||
do
|
case ${OPT} in
|
||||||
case ${OPT} in
|
v) version; exit ;;
|
||||||
v) version; exit ;;
|
h) usage; exit ;;
|
||||||
h) usage; exit ;;
|
f) ponies+=( "$OPTARG" ) ;;
|
||||||
f) ponies+=( "$OPTARG" ) ;;
|
l) list; exit ;;
|
||||||
l) list; exit ;;
|
L) linklist; exit ;;
|
||||||
L) linklist; exit ;;
|
W) wrap="$OPTARG" ;;
|
||||||
W) wrap="$OPTARG" ;;
|
q) usepq=1 ;;
|
||||||
q) usepq=1 ;;
|
\?) usage >&2; exit 1 ;;
|
||||||
\?) usage >&2; exit 1 ;;
|
esac
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
if [[ $usepq = 1 ]]; then
|
if [[ $usepq = 1 ]]; then
|
||||||
if [[ -f './pq4ps' ]]; then
|
if [[ -f './pq4ps' ]]; then
|
||||||
function q
|
function q {
|
||||||
{ ./pq4ps $@
|
./pq4ps $@
|
||||||
}
|
}
|
||||||
elif [[ -f '/usr/bin/pq4ps' ]]; then
|
elif [[ -f '/usr/bin/pq4ps' ]]; then
|
||||||
function q
|
function q {
|
||||||
{ /usr/bin/pq4ps $@
|
/usr/bin/pq4ps $@
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
$0 ${wrap:+-W$wrap} $(q "$*")
|
$0 ${wrap:+-W$wrap} $(q "$*")
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
hash $cmd &>/dev/null; if [ $? -ne 0 ]; then
|
hash $cmd &>/dev/null; if [ $? -ne 0 ]; then
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
You don't seem to have the $cmd program.
|
You don't seem to have the $cmd program.
|
||||||
Please install it in order to use this wrapper.
|
Please install it in order to use this wrapper.
|
||||||
|
|
||||||
Alternatively, symlink it to '$cmd' in anywhere in \$PATH
|
Alternatively, symlink it to '$cmd' in anywhere in \$PATH
|
||||||
if it actually exists under a different filename.
|
if it actually exists under a different filename.
|
||||||
EOF
|
EOF
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! ${#ponies[@]} == 0 ]]; then
|
if [[ ! ${#ponies[@]} == 0 ]]; then
|
||||||
pony="${ponies[$RANDOM%${#ponies[@]}]}"
|
pony="${ponies[$RANDOM%${#ponies[@]}]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f $pony ]]; then
|
if [[ ! -f $pony ]]; then
|
||||||
# Pony not a file? Search for it
|
# Pony not a file? Search for it
|
||||||
|
|
||||||
ponies=()
|
ponies=()
|
||||||
[[ -d $SYSTEMPONIES ]] && ponies+=( "$SYSTEMPONIES"/$pony.pony )
|
[[ -d $SYSTEMPONIES ]] && ponies+=( "$SYSTEMPONIES"/$pony.pony )
|
||||||
[[ -d $HOMEPONIES ]] && ponies+=( "$HOMEPONIES"/$pony.pony )
|
[[ -d $HOMEPONIES ]] && ponies+=( "$HOMEPONIES"/$pony.pony )
|
||||||
|
|
||||||
if (( ${#ponies} < 1 )); then
|
if (( ${#ponies} < 1 )); then
|
||||||
echo >&2 "All the ponies are missing! Call the Princess!"
|
echo >&2 "All the ponies are missing! Call the Princess!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Choose a random pony
|
# Choose a random pony
|
||||||
pony="${ponies[$RANDOM%${#ponies[@]}]}"
|
pony="${ponies[$RANDOM%${#ponies[@]}]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$*" ]]; then
|
if [[ -n "$*" ]]; then
|
||||||
# Handle a message given via arguments
|
# Handle a message given via arguments
|
||||||
say <<<"$*"
|
say <<<"$*"
|
||||||
else
|
else
|
||||||
say
|
say
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue