mirror of
https://github.com/erkin/ponysay
synced 2024-11-27 13:50:52 +00:00
new options, ponysay -L, just like ponysay -l but puts symlinks inside brackets after their targets, I also edited Makefile to preserve symlinks
This commit is contained in:
parent
4b9db7c37f
commit
b667e66071
5 changed files with 114 additions and 15 deletions
4
Makefile
4
Makefile
|
@ -26,8 +26,8 @@ install: all
|
|||
mkdir -p "$(DESTDIR)/usr/share/ponysay/"
|
||||
mkdir -p "$(DESTDIR)/usr/share/ponysay/ponies"
|
||||
mkdir -p "$(DESTDIR)/usr/share/ponysay/ttyponies"
|
||||
cp ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/"
|
||||
cp ttyponies/*.pony "$(DESTDIR)/usr/share/ponysay/ttyponies/"
|
||||
cp -P ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/"
|
||||
cp -P ttyponies/*.pony "$(DESTDIR)/usr/share/ponysay/ttyponies/"
|
||||
|
||||
mkdir -p "$(DESTDIR)/usr/bin/"
|
||||
install "ponysay" "$(DESTDIR)/usr/bin/ponysay"
|
||||
|
|
6
README
6
README
|
@ -25,11 +25,11 @@ Required runtime dependencies
|
|||
|
||||
cowsay : this is a wrapper for cowsay
|
||||
|
||||
coreutils : the main script [file: ponysay] uses stty, cut, ls, cat, sort, head and tail
|
||||
coreutils : the main script [file: ponysay] uses stty, cut, ls, cat, sort, readlink, head and tail
|
||||
|
||||
sed : used to remove .pony from pony named when running ponysay -l
|
||||
sed : used to remove .pony from pony named when running `ponysay -l` and `ponysay -L`
|
||||
|
||||
perl : required to run ponysay -l
|
||||
perl : required to run `ponysay -l` and `ponysay -L`
|
||||
|
||||
|
||||
Optional runtime dependencies
|
||||
|
|
|
@ -70,11 +70,11 @@ Dependencies
|
|||
|
||||
`cowsay`: this is a wrapper for cowsay
|
||||
|
||||
`coreutils`: the main script uses stty, cut, ls, cat, sort, head and tail
|
||||
`coreutils`: the main script uses stty, cut, ls, cat, sort, readlink, head and tail
|
||||
|
||||
`sed`: used to remove .pony from pony named when running `ponysay -l`
|
||||
`sed`: used to remove .pony from pony named when running `ponysay -l` and `ponysay -l`
|
||||
|
||||
`perl`: required to run `ponysay -l`
|
||||
`perl`: required to run `ponysay -l` and `ponysay -L`
|
||||
|
||||
### Package building dependencies
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ Show version of program.
|
|||
.B \-l
|
||||
List pony files.
|
||||
.TP
|
||||
.B \-L
|
||||
List pony files with synonyms inside brackets.
|
||||
.TP
|
||||
.B \-f \fIname\fP
|
||||
Select a pony (either a file name or a pony name), you can use this options multiple times,
|
||||
and one of the will be selected randomly.
|
||||
|
|
110
ponysay
110
ponysay
|
@ -18,17 +18,111 @@ version() {
|
|||
echo "ponysay v$version"
|
||||
}
|
||||
|
||||
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
|
||||
listcmd=$(echo $0 | sed -e 's/\/ponysay$/\//g' -e 's/\/ponythink$/\//g')"ponysaylist.pl"
|
||||
|
||||
list() {
|
||||
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
|
||||
|
||||
listcmd=$(echo $0 | sed -e 's/\/ponysay$/\//g' -e 's/\/ponythink$/\//g')"ponysaylist.pl"
|
||||
|
||||
echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m"
|
||||
perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed "s/.pony//" | sort)
|
||||
perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort)
|
||||
|
||||
if [[ -d $HOMEPONIES ]]; then
|
||||
echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m"
|
||||
perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed "s/.pony//" | sort)
|
||||
perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed -e 's/\.pony$//' | sort)
|
||||
fi
|
||||
}
|
||||
|
||||
_linklist() {
|
||||
echo -e "\\e[01mponyfiles located in $1:\\e[21m"
|
||||
files=$(ls --color=no $1 | sed -e 's/\.pony$//' | sort)
|
||||
|
||||
args=""
|
||||
|
||||
for file in $files; do
|
||||
target=$(readlink $1"/"$file".pony")
|
||||
if [[ $target = "" ]]; then
|
||||
target=$file
|
||||
else
|
||||
target=$(echo $target | sed -e 's/^\.\///g' -e 's/\.pony$//g')
|
||||
fi
|
||||
args=$(echo $args $file $target)
|
||||
done
|
||||
|
||||
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
|
||||
|
||||
#Author: Mattias Andrée (maandree@kth.se)
|
||||
|
||||
%hash = ();
|
||||
\$argc = @ARGV;
|
||||
|
||||
\$i = 0;
|
||||
while (\$i < \$argc)
|
||||
{
|
||||
\$source = \$ARGV[\$i];
|
||||
\$i += 1;
|
||||
\$target = \$ARGV[\$i];
|
||||
\$i += 1;
|
||||
if (\$source eq \$target)
|
||||
{
|
||||
\$hash{\$source} = [ () ];
|
||||
}
|
||||
}
|
||||
|
||||
\$i = 0;
|
||||
while (\$i < \$argc)
|
||||
{
|
||||
\$source = \$ARGV[\$i];
|
||||
\$i += 1;
|
||||
\$target = \$ARGV[\$i];
|
||||
\$i += 1;
|
||||
unless (\$source eq \$target)
|
||||
{
|
||||
push @{ \$hash{\$target} }, \$source;
|
||||
}
|
||||
}
|
||||
|
||||
\$i = 0;
|
||||
while (\$i < \$argc)
|
||||
{
|
||||
\$source = \$ARGV[\$i];
|
||||
\$i += 1;
|
||||
\$target = \$ARGV[\$i];
|
||||
\$i += 1;
|
||||
if (\$source eq \$target)
|
||||
{
|
||||
@list = @{ \$hash{\$source} };
|
||||
\$first = 1;
|
||||
print \$source;
|
||||
foreach \$link (@list)
|
||||
{
|
||||
if (\$first eq 1)
|
||||
{
|
||||
print " (".\$link;
|
||||
\$first = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
print " ".\$link;
|
||||
}
|
||||
}
|
||||
if (\$first eq 0)
|
||||
{
|
||||
print ")";
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
perl $listcmd $scrw $(cat /dev/shm/ponysay~) | sed -e 's/_/ /g'
|
||||
}
|
||||
|
||||
linklist() {
|
||||
_linklist $SYSTEMPONIES
|
||||
if [[ -d $HOMEPONIES ]]; then
|
||||
_linklist $HOMEPONIES
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -45,6 +139,7 @@ Options:
|
|||
-v Show version and exit.
|
||||
-h Show this help and exit.
|
||||
-l List pony files.
|
||||
-L List pony files with synonyms inside brackets.
|
||||
-f[name] Select a pony (either a file name or a pony name.)
|
||||
-W[column] The screen column where the message should be wrapped.
|
||||
|
||||
|
@ -104,13 +199,14 @@ say() {
|
|||
|
||||
ponies=()
|
||||
|
||||
while getopts f:W:lhv OPT
|
||||
while getopts f:W:Llhv OPT
|
||||
do
|
||||
case ${OPT} in
|
||||
v) version; exit ;;
|
||||
h) usage; exit ;;
|
||||
f) ponies+=( "$OPTARG" ) ;;
|
||||
l) list; exit ;;
|
||||
L) linklist; exit ;;
|
||||
W) wrap="$OPTARG" ;;
|
||||
\?) usage >&2; exit 1 ;;
|
||||
esac
|
||||
|
|
Loading…
Reference in a new issue