Linux Mint7是基于Ubuntu的一个发行版,对Ubuntu做了些改动,有一个小改动也挺有意思,就是调出终端时,会调用fortune显示一些俏皮话、俚语之类的,并会显示一个字符图片。给平淡的终端命令行窗口增加了点趣味。
不过它显示的内容都是些英文句子,不是很能引起偶的共鸣。好在还有个fortune-zh,会显示唐诗。先装上它吧:
sudo apt-get install fortune-zh
装好后,调用一下fortune-zh,就可以看到唐诗了。
但是在启动终端时还是会显示一些英文的内容。其实也好办,有两种方法可以解决这个问题。
第一种:删除英文的数据文件
因为这些句子都存在一些文件中,文件在/usr/share/games/fortunes
这个目录下,我们到这个目录下看一下,会有好多文件。我们要的中文的内容包含在这六个文件中:
tang300 tang300.dat tang300.u8
song100 song100.dat song100.u8
其它文件我们都可以删除掉,或移到别的目录中去。
然后再运行终端,出来的句子就都是中文诗词了。
第二种:用sudo gedit /usr/bin/mint-fortune修改脚本将最后一行的
/usr/bin/fortune | $command -f $cow
改为
/usr/bin/fortune-zh | $command -f $cow
就可以在终端中只显示中文的诗词了。
但新问题还是存在,显示英文时,动物上方的气泡挺整齐,但显示中文诗句时,气泡就乱掉了,而且中文诗句换行也有问题。
这时我们就需要再改一下另一个脚本文件了,把显示的气泡边框去掉。调用命令:
gedit /usr/games/cowsay &
将其中的内容换成:
#!/usr/bin/perl
##
## Cowsay 3.03
##
## This file is part of cowsay. (c) 1999-2000 Tony Monroe.
##
use Text::Tabs qw(expand);
use Text::Wrap qw(wrap fill $columns);
use File::Basename;
use Getopt::Std;
use Cwd;
$version = “3.03”;
$progname = basename($0);
$eyes = “oo”;
$tongue = ” “;
$cowpath = $ENV{‘COWPATH’} || ‘/usr/share/cowsay/cows’;
@message = ();
$thoughts = “”;
## Yeah, this is rude, I know. But hopefully it gets around a nasty
## little version dependency.
$Text::Wrap::initial_tab = 8;
$Text::Wrap::subsequent_tab = 8;
$Text::Wrap::tabstop = 8;
## One of these days, we’ll get it ported to Windows. Yeah, right.
if (($^O eq “MSWin32”) or ($^O eq “Windows_NT”)) { ## Many perls, eek!
$pathsep = ‘;’;
} else {
$pathsep = ‘:’;
}
%opts = (
‘e’ => ‘oo’,
‘f’ => ‘default.cow’,
‘n’ => 0,
‘T’ => ‘ ‘,
‘W’ => 40,
);
getopts(‘bde:f:ghlLnNpstT:wW:y’, \%opts);
&display_usage if $opts{‘h’};
&list_cowfiles if $opts{‘l’};
$borg = $opts{‘b’};
$dead = $opts{‘d’};
$greedy = $opts{‘g’};
$paranoid = $opts{‘p’};
$stoned = $opts{‘s’};
$tired = $opts{‘t’};
$wired = $opts{‘w’};
$young = $opts{‘y’};
$eyes = substr($opts{‘e’}, 0, 2);
$tongue = substr($opts{‘T’}, 0, 2);
$the_cow = “”;
&slurp_input;
$Text::Wrap::columns = $opts{‘W’};
#@message = ($opts{‘n’} ? expand(@message) :
# split(“\n”, fill(“”, “”, @message)));
&construct_balloon;
&construct_face;
&get_cow;
print @balloon_lines;
print $the_cow;
sub list_cowfiles {
my $basedir;
my @dirfiles;
chop($basedir = cwd);
for my $d (split(/$pathsep/, $cowpath)) {
print “Cow files in $d:\n”;
opendir(COWDIR, $d) || die “$0: Cannot open $d\n”;
for my $file (readdir COWDIR) {
if ($file =~ s/\.cow$//) {
push(@dirfiles, $file);
}
}
closedir(COWDIR);
print wrap(“”, “”, sort @dirfiles), “\n”;
@dirfiles = ();
chdir($basedir);
}
exit(0);
}
sub slurp_input {
unless ($ARGV[0]) {
chomp(@message = <STDIN>);
} else {
&display_usage if $opts{‘n’};
@message = join(‘ ‘, @ARGV);
}
}
sub maxlength {
my ($l, $m);
$m = -1;
for my $i (@_) {
$l = length $i;
$m = $l if ($l > $m);
}
## maxlength patch from Jeronimo Pellegrini (Closes: #165218)
if ($m == -1) {
$m = 0;
}
return $m ;
}
sub construct_balloon {
my $max = &maxlength(@message);
my $max2 = $max + 2; ## border space fudge.
#my $format = “%s %-${max}s %s\n”;
my $format = “%s %-${max}s %s\n”;
my @border; ## up-left, up-right, down-left, down-right, left, right
if ($0 =~ /think/i) {
$thoughts = ‘o’;
#@border = qw[ ( ) ( ) ( ) ];
@border = qw[ ];
} elsif (@message < 2) {
$thoughts = ‘\\’;
#@border = qw[ < > ];
@border = qw[ ];
} else {
$thoughts = ‘\\’;
if ($V and $V gt v5.6.0) { # Thanks, perldelta.
#@border = qw[ / \\ \\ / | | ];
@border = qw[ ];
} else {
#@border = qw[ / \ \ / | | ];
@border = qw[ ];
}
}
## no trailing spaces (#276144)
push(@balloon_lines,
” ” . (” ” x $max2) . “\n” ,
sprintf($format, $border[0], $message[0], $border[1]),
(@message < 2 ? “” :
map { sprintf($format, $border[4], $_, $border[5]) }
@message[1 .. $#message – 1]),
(@message < 2 ? “” :
sprintf($format, $border[2], $message[$#message], $border[3])),
” ” . (” ” x $max2) . “\n”
);
}
sub construct_face {
if ($borg) { $eyes = “==”; }
if ($dead) { $eyes = “xx”; $tongue = “U “; }
if ($greedy) { $eyes = “\$\$”; }
if ($paranoid) { $eyes = “@@”; }
if ($stoned) { $eyes = “**”; $tongue = “U “; }
if ($tired) { $eyes = “–“; }
if ($wired) { $eyes = “OO”; }
if ($young) { $eyes = “..”; }
}
sub get_cow {
##
## Get a cow from the specified cowfile; otherwise use the default cow
## which was defined above in $the_cow.
##
my $f = $opts{‘f’};
my $full = “”;
if ($opts{‘f’} =~ m,/,) {
$full = $opts{‘f’};
} else {
for my $d (split(/:/, $cowpath)) {
if (-f “$d/$f”) {
$full = “$d/$f”;
last;
} elsif (-f “$d/$f.cow”) {
$full = “$d/$f.cow”;
last;
}
}
if ($full eq “”) {
die “$progname: Could not find $f cowfile!\n”;
}
}
do $full;
die “$progname: $@\n” if $@;
}
sub display_usage {
die <<EOF;
cow{say,think} version $version, (c) 1999 Tony Monroe
Usage: $progname [-bdgpstwy] [-h] [-e eyes] [-f cowfile]
[-l] [-n] [-T tongue] [-W wrapcolumn] [message]
EOF
}
保存、退出。再调用“终端”看看,虽然没有气泡边框了,但诗句显示是工整的。