mirror of
https://github.com/erkin/ponysay.git
synced 2025-03-21 19:27:11 +01:00
are there any ponies
This commit is contained in:
parent
f9663c7b1b
commit
fd099535cf
2 changed files with 19 additions and 35 deletions
24
ponysay.py
24
ponysay.py
|
@ -27,21 +27,28 @@ The directory where ponysay is installed, this is modified when building with ma
|
||||||
INSTALLDIR = '/usr'
|
INSTALLDIR = '/usr'
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
The user's home directory
|
||||||
|
'''
|
||||||
|
HOME = os.environ['HOME']
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
The directories where pony files are stored, ttyponies/ are used if the terminal is Linux VT (also known as TTY)
|
The directories where pony files are stored, ttyponies/ are used if the terminal is Linux VT (also known as TTY)
|
||||||
'''
|
'''
|
||||||
ponydirs = []
|
ponydirs = []
|
||||||
if os.environ['TERM'] == 'linux': _ponydirs = [INSTALLDIR + '/share/ponysay/ttyponies/', os.environ['HOME'] + '/.local/share/ponysay/ttyponies/']
|
if os.environ['TERM'] == 'linux': _ponydirs = [INSTALLDIR + '/share/ponysay/ttyponies/', HOME + '/.local/share/ponysay/ttyponies/']
|
||||||
else: _ponydirs = [INSTALLDIR + '/share/ponysay/ponies/', os.environ['HOME'] + '/.local/share/ponysay/ponies/' ]
|
else: _ponydirs = [INSTALLDIR + '/share/ponysay/ponies/', HOME + '/.local/share/ponysay/ponies/' ]
|
||||||
for ponydir in _ponydirs:
|
for ponydir in _ponydirs:
|
||||||
if os.path.isdir(ponydir):
|
if os.path.isdir(ponydir):
|
||||||
ponydirs.append(ponydir)
|
ponydirs.append(ponydir)
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
The directories where quotes files are stored
|
The directories where quotes files are stored
|
||||||
'''
|
'''
|
||||||
quotedirs = []
|
quotedirs = []
|
||||||
_quotedirs = [INSTALLDIR + '/share/ponysay/quotes/', os.environ['HOME'] + '/.local/share/ponysay/quotes/']
|
_quotedirs = [INSTALLDIR + '/share/ponysay/quotes/', HOME + '/.local/share/ponysay/quotes/']
|
||||||
for quotedir in _quotedirs:
|
for quotedir in _quotedirs:
|
||||||
if os.path.isdir(quotedir):
|
if os.path.isdir(quotedir):
|
||||||
quotedirs.append(quotedir)
|
quotedirs.append(quotedir)
|
||||||
|
@ -251,12 +258,18 @@ class ponysay():
|
||||||
|
|
||||||
|
|
||||||
def print_pony(self, args):
|
def print_pony(self, args):
|
||||||
|
ponycount = 0
|
||||||
|
for ponydir in ponydirs:
|
||||||
|
ponycount = len(os.listdir(ponydir))
|
||||||
|
if ponycount == 0:
|
||||||
|
sys.stderr.write('All the ponies are missing! Call the Princess!')
|
||||||
|
exit(1);
|
||||||
|
|
||||||
if args.message == None:
|
if args.message == None:
|
||||||
msg = sys.stdin.read().strip()
|
msg = sys.stdin.read()
|
||||||
else:
|
else:
|
||||||
msg = args.message
|
msg = args.message
|
||||||
|
|
||||||
|
|
||||||
if args.pony == None:
|
if args.pony == None:
|
||||||
ponies = [] # Make array with direct paths to all ponies
|
ponies = [] # Make array with direct paths to all ponies
|
||||||
for ponydir in ponydirs:
|
for ponydir in ponydirs:
|
||||||
|
@ -264,7 +277,6 @@ class ponysay():
|
||||||
ponies.append(ponydir + ponyfile)
|
ponies.append(ponydir + ponyfile)
|
||||||
|
|
||||||
pony = ponies[random.randrange(0, len(ponies) - 1)] # Select random pony
|
pony = ponies[random.randrange(0, len(ponies) - 1)] # Select random pony
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for ponydir in ponydirs:
|
for ponydir in ponydirs:
|
||||||
if os.path.isfile(ponydir + args.pony[0]):
|
if os.path.isfile(ponydir + args.pony[0]):
|
||||||
|
|
28
ponysay.sh
28
ponysay.sh
|
@ -60,40 +60,12 @@ fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Marks ponies in lists that have quotes
|
|
||||||
qoutelist() {
|
|
||||||
bash -c "$("$qlistcmd" $("$quotecmd" --list))"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pony quotes
|
# Pony quotes
|
||||||
ponyquotes() {
|
ponyquotes() {
|
||||||
[ "$TERM" = "-linux-" ] && TERM="linux"
|
[ "$TERM" = "-linux-" ] && TERM="linux"
|
||||||
"$0" ${wrap:+-W$wrap} $("$quotecmd" $@)
|
"$0" ${wrap:+-W$wrap} $("$quotecmd" $@)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Usage help print function
|
|
||||||
usage() {
|
|
||||||
version
|
|
||||||
cat <<EOF
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
${0##*/} [options] [message]
|
|
||||||
|
|
||||||
If [message] is not provided, reads the message from STDIN.
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-v Show version and exit.
|
|
||||||
-h Show this help and exit.
|
|
||||||
-l List pony files.
|
|
||||||
-L List pony files with synonyms inside brackets.
|
|
||||||
-q Use the pony quote feature.
|
|
||||||
-f[name] Select a pony (either a file name or a pony name.)
|
|
||||||
-W[column] The screen column where the message should be wrapped.
|
|
||||||
|
|
||||||
See man ponysay(6) for more information.
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function for printing the ponies and the message
|
# Function for printing the ponies and the message
|
||||||
say() {
|
say() {
|
||||||
# Ponies use UTF-8 drawing characters. Prevent a Perl warning.
|
# Ponies use UTF-8 drawing characters. Prevent a Perl warning.
|
||||||
|
|
Loading…
Add table
Reference in a new issue