portability: [[ is not recongised by dash

This commit is contained in:
Mattias Andrée 2012-08-16 18:27:20 +02:00
parent e3c9cdfc95
commit 23d84d1b55
3 changed files with 28 additions and 28 deletions

View file

@ -150,10 +150,10 @@ ttyponies:
mkdir -p "ttyponies" mkdir -p "ttyponies"
for pony in $$(ls --color=no "ponies/"); do \ for pony in $$(ls --color=no "ponies/"); do \
echo "building ttypony: $$pony" ;\ echo "building ttypony: $$pony" ;\
if [[ `readlink "ponies/$$pony"` = "" ]]; then \ if [ `readlink "ponies/$$pony"` = "" ]; then \
ponysay2ttyponysay < "ponies/$$pony" | tty2colourfultty -c 1 -e > "ttyponies/$$pony" ;\ ponysay2ttyponysay < "ponies/$$pony" | tty2colourfultty -c 1 -e > "ttyponies/$$pony" ;\
git add "ttyponies/$$pony" ;\ git add "ttyponies/$$pony" ;\
elif [[ ! -f "ttyponies/$$pony" ]]; then \ elif [ ! -f "ttyponies/$$pony" ]; then \
ln -s `readlink "ponies/$$pony"` "ttyponies/$$pony" ;\ ln -s `readlink "ponies/$$pony"` "ttyponies/$$pony" ;\
git add "ttyponies/$$pony" ;\ git add "ttyponies/$$pony" ;\
fi \ fi \
@ -163,9 +163,9 @@ pdfmanual:
texi2pdf "manuals/ponysay.texinfo" texi2pdf "manuals/ponysay.texinfo"
git add "manuals/ponysay.texinfo" "ponysay.pdf" git add "manuals/ponysay.texinfo" "ponysay.pdf"
for ext in `echo aux cp cps fn ky log pg toc tp vr`; do \ for ext in `echo aux cp cps fn ky log pg toc tp vr`; do \
(if [[ -f "ponysay.$$ext" ]]; then unlink "ponysay.$$ext"; fi); \ (if [ -f "ponysay.$$ext" ]; then unlink "ponysay.$$ext"; fi); \
done done
if [[ -d "ponysay.t2d" ]]; then rm -r "ponysay.t2d"; fi if [ -d "ponysay.t2d" ]; then rm -r "ponysay.t2d"; fi
submodules: clean submodules: clean
(cd "ponyquotes4ponysay/"; make clean) (cd "ponyquotes4ponysay/"; make clean)
@ -174,7 +174,7 @@ submodules: clean
quotes: submodules quotes: submodules
(cd "ponyquotes4ponysay/"; make -B) (cd "ponyquotes4ponysay/"; make -B)
if [[ -d quotes ]]; then git rm "quotes/"*.*; fi if [ -d quotes ]; then git rm "quotes/"*.*; fi
mkdir -p "quotes" mkdir -p "quotes"
cp "ponyquotes4ponysay/ponyquotes/"*.* "quotes" cp "ponyquotes4ponysay/ponyquotes/"*.* "quotes"
git add "quotes/"*.* git add "quotes/"*.*

44
ponysay
View file

@ -27,8 +27,8 @@ scrh=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 1` # Screen height
# KMS ponies extension # KMS ponies extension
kmscmd="" kmscmd=""
[[ "$TERM" = "linux" ]] && kmscmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/ponysay2kmsponysay /g'); do if [[ -f $c ]]; then echo $c; break; fi done) [ "$TERM" = "linux" ] && kmscmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/ponysay2kmsponysay /g'); do if [ -f $c ]; then echo $c; break; fi done)
[[ ! "$kmscmd" = "" ]] && TERM="-linux-" [ ! "$kmscmd" = "" ] && TERM="-linux-"
# Directories for installed ponies files # Directories for installed ponies files
if [ "$TERM" = "linux" ]; then if [ "$TERM" = "linux" ]; then
@ -40,8 +40,8 @@ else
fi fi
# Cowsay script # Cowsay script
if [[ ${0} == *ponythink ]]; then if [ ${0} == *ponythink ]; then
if [[ "$PONYSAY_COWTHINK" = "" ]]; then if [ "$PONYSAY_COWTHINK" = "" ]; then
cmd=cowthink cmd=cowthink
customcmd=0 customcmd=0
else else
@ -49,7 +49,7 @@ if [[ ${0} == *ponythink ]]; then
customcmd=1 customcmd=1
fi fi
else else
if [[ "$PONYSAY_COWSAY" = "" ]]; then if [ "$PONYSAY_COWSAY" = "" ]; then
cmd=cowsay cmd=cowsay
customcmd=0 customcmd=0
else else
@ -67,15 +67,15 @@ version() {
# Pony list function # Pony list function
list() { list() {
if [[ -d $SYSTEMPONIES ]]; then if [ -d $SYSTEMPONIES ]; then
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) | $qlistcmd perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort) | $qlistcmd
fi fi
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) | $qlistcmd perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed -e 's/\.pony$//' | sort) | $qlistcmd
fi fi
if [[ ! -d $SYSTEMPONIES ]] && [[ ! -d $HOMEPONIES ]]; then if [ ! -d $SYSTEMPONIES ] && [ ! -d $HOMEPONIES ]; then
echo >&2 "All the ponies are missing! Call the Princess!" echo >&2 "All the ponies are missing! Call the Princess!"
fi fi
} }
@ -106,14 +106,14 @@ _linklist() {
linklist() { linklist() {
_linklist $SYSTEMPONIES _linklist $SYSTEMPONIES
if [[ -d $HOMEPONIES ]]; then if [ -d $HOMEPONIES ]; then
_linklist $HOMEPONIES _linklist $HOMEPONIES
fi fi
} }
# Pony quotes # Pony quotes
ponyquotes() { ponyquotes() {
[[ "$TERM" = "-linux-" ]] && TERM="linux" [ "$TERM" = "-linux-" ] && TERM="linux"
"$0" ${wrap:+-W$wrap} $("$quotecmd" "$*") "$0" ${wrap:+-W$wrap} $("$quotecmd" "$*")
} }
@ -146,10 +146,10 @@ say() {
export PERL_UNICODE=S export PERL_UNICODE=S
# Clear screen in TTY # Clear screen in TTY
( [[ "$TERM" = "linux" ]] || [[ "$TERM" = "-linux-" ]]) && echo -ne '\e[H\e[2J' ( [ "$TERM" = "linux" ] || [ "$TERM" = "-linux-" ]) && echo -ne '\e[H\e[2J'
# Set PONYSAY_SHELL_LINES to default if not specified # Set PONYSAY_SHELL_LINES to default if not specified
[[ "$PONYSAY_SHELL_LINES" = "" ]] && PONYSAY_SHELL_LINES=2 [ "$PONYSAY_SHELL_LINES" = "" ] && PONYSAY_SHELL_LINES=2
# Width trunction # Width trunction
function wtrunc { function wtrunc {
@ -175,12 +175,12 @@ say() {
} }
# Simplification of customisation of cowsay # Simplification of customisation of cowsay
if [[ $customcmd = 0 ]]; then if [ $customcmd = 0 ]; then
function cowcmd { function cowcmd {
pcmd='#!/usr/bin/perl\nuse utf8;' 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) 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 if [ ${0} == *ponythink ]; then
cat <(echo -e $pcmd) $ccmd > "/tmp/ponythink" cat <(echo -e $pcmd) $ccmd > "/tmp/ponythink"
perl '/tmp/ponythink' "$@" perl '/tmp/ponythink' "$@"
rm '/tmp/ponythink' rm '/tmp/ponythink'
@ -195,7 +195,7 @@ say() {
fi fi
# KMS ponies support # KMS ponies support
if [[ "$kmscmd" = "" ]]; then if [ "$kmscmd" = "" ]; then
function runcmd { function runcmd {
cowcmd -f "$pony" "$@" cowcmd -f "$pony" "$@"
} }
@ -220,7 +220,7 @@ say() {
# 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
@ -257,16 +257,16 @@ fi
# Select random pony for the set of -f arguments # Select random pony for the set of -f arguments
if [[ ! ${#ponies[@]} == 0 ]]; then if [ ! ${#ponies[@]} == 0 ]; then
pony="${ponies[$RANDOM%${#ponies[@]}]}" pony="${ponies[$RANDOM%${#ponies[@]}]}"
fi fi
# Pony not a file? Search for it # Pony not a file? Search for it
if [[ ! -f $pony ]]; then if [ ! -f $pony ]; then
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!"
@ -279,7 +279,7 @@ fi
# Print pony with message # Print pony with message
if [[ -n "$*" ]]; then if [ -n "$*" ]; then
# Handle a message given via arguments # Handle a message given via arguments
say <<<"$*" say <<<"$*"
else else

2
pq4ps
View file

@ -2,7 +2,7 @@
INSTALLDIR="$(dirname "$(dirname "$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )")")" # Get main bash script directory's parent INSTALLDIR="$(dirname "$(dirname "$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )")")" # Get main bash script directory's parent
if [[ $# == 1 ]] && [[ "$1" == '-l' || "$1" == '--list' ]]; then if [ $# == 1 ] && [ "$1" == '-l' || "$1" == '--list' ]; then
perl "$0.pl" "$INSTALLDIR" | cut -d @ -f 1 | uniq perl "$0.pl" "$INSTALLDIR" | cut -d @ -f 1 | uniq
else else
_ponies="$(perl "$0.pl" "$INSTALLDIR")" _ponies="$(perl "$0.pl" "$INSTALLDIR")"