From c4f07a8b002b218d19b09f5d2ad06c491b275c98 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Aug 2012 16:20:49 +0200 Subject: support quotes in ~/.local/share/ponysay/quotes (new feature) --- ponysay.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ponysay.py b/ponysay.py index b7b3eb4..e7c671f 100755 --- a/ponysay.py +++ b/ponysay.py @@ -37,6 +37,17 @@ for ponydir in _ponydirs: if os.path.isdir(ponydir): ponydirs.append(ponydir) +''' +The directories where quotes files are stored +''' +quotedirs = [] +_quotedirs = [INSTALLDIR + '/share/ponysay/quotes/', os.environ['HOME'] + '/.local/share/ponysay/quotes/'] +for quotedir in _quotedirs: + if os.path.isdir(quotedir): + quotedirs.append(quotedir) + + + parser = argparse.ArgumentParser(description = 'Ponysay, like cowsay with ponies') parser.add_argument('-v', '--version', action = 'version', version = '%s %s' % ("ponysay", VERSION)) @@ -61,7 +72,9 @@ class ponysay(): def __quoters(self): quotes = [] quoteshash = set() - _quotes = [item[:item.index('.')] for item in os.listdir(INSTALLDIR + '/share/ponysay/quotes/')] + _quotes = [] + for quotedir in quotedirs: + _quotes += [item[:item.index('.')] for item in os.listdir(INSTALLDIR + '/share/ponysay/quotes/')] for quote in _quotes: if not quote == '': if not quote in quoteshash: @@ -85,7 +98,9 @@ class ponysay(): Returns a list with all (pony, quote file) pairs ''' def __quotes(self): - quotes = os.listdir(INSTALLDIR + '/share/ponysay/quotes/') + quotes = [] + for quotedir in quotedirs: + quotes += [quotedir + item for item in os.listdir(quotedir)] rc = [] for ponydir in ponydirs: @@ -93,8 +108,9 @@ class ponysay(): if not pony[0] == '.': p = pony[:-5] # remove .pony for quote in quotes: - if ('+' + p + '+') in ('+' + quote + '+'): - rc.append((p, qoute)) + q = quote[quote.rindex('/') + 1:] + if ('+' + p + '+') in ('+' + q + '+'): + rc.append((p, quote)) return rc -- cgit From dce179f8a3ac7f6a349deda010c9f811b78c17ce Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Aug 2012 16:37:55 +0200 Subject: simplier completion --- completion/bash-completion.sh | 24 +++++++----------------- completion/fish-completion.fish | 31 ++++--------------------------- 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/completion/bash-completion.sh b/completion/bash-completion.sh index 26e1134..11b99ea 100644 --- a/completion/bash-completion.sh +++ b/completion/bash-completion.sh @@ -8,28 +8,18 @@ _ponysay() options='-v -h -l -f -W -q' COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) - if [ $prev = "-f" ]; then - COMPREPLY=() - - sysponies=/usr/share/ponysay/ponies/ - usrponies=~/.local/share/ponysay/ponies/ - if [[ $TERM = "linux" ]]; then - sysponies=/usr/share/ponysay/ttyponies/ - usrponies=~/.local/share/ponysay/ttyponies/ - fi - - [ -d $sysponies ] && COMPREPLY+=( $( compgen -W "$(ls --color=no $sysponies | sed -e 's/.pony//g')" -- "$cur" ) ) - [ -d $usrponies ] && COMPREPLY+=( $( compgen -W "$(ls --color=no $usrponies | sed -e 's/.pony//g')" -- "$cur" ) ) + if [ $prev = "-f" ]; then + ponies=$('/usr/bin/ponysay.py' --onelist) + COMPREPLY=( $( compgen -W "$ponies" -- "$cur" ) ) + + elif [ $prev = "-q" ]; then + quoters=$('/usr/bin/ponysay.py' --quoters) + COMPREPLY=( $( compgen -W "$quoters" -- "$cur" ) ) elif [ $prev = "-W" ]; then cols=$(( `stty size | cut -d ' ' -f 2` - 10 )) COMPREPLY=( $cols $(( $cols / 2 )) 100 60 ) - elif [ $prev = "-q" ]; then - qcmd=/usr/lib/ponysay/pq4ps - quoters=$($qcmd -l) - COMPREPLY=( $( compgen -W "$quoters" -- "$cur" ) ) - fi } diff --git a/completion/fish-completion.fish b/completion/fish-completion.fish index 89f7a19..727460b 100644 --- a/completion/fish-completion.fish +++ b/completion/fish-completion.fish @@ -3,43 +3,20 @@ # # Author: Elis Axelsson -if test $TERM = "linux" - set -g systempath /usr/share/ponysay/ttyponies/ - set -g homepath ~/.local/share/ponysay/ttyponies/ -else - set -g systempath /usr/share/ponysay/ponies/ - set -g homepath ~/.local/share/ponysay/ponies/ -end - -if test -d $systempath - set -g systemponies (ls --color=no $systempath | sed -e 's/\.pony//' -e 's/_.*//' | perl -pe 's/([a-z])([A-Z])/\1\\\ \2/' ) -end - -if test -d $homepath - set -g homeponies (ls --color=no $homepath | sed -e 's/\.pony//' -e 's/_.*//' | perl -pe 's/([a-z])([A-Z])/\1\\\ \2/' ) -end - - -set -g qcmd /usr/lib/ponysay/pq4ps -set -g quoters ($qcmd -l) +set -g ponies ('/usr/bin/ponysay.pl' --onelist) +set -g quoters ('/usr/bin/ponysay.pl' --quoters) complete -c ponysay -s h --description "Help of ponysay" complete -c ponysay -s v --description "Version of ponysay" complete -c ponysay -s l --description "List pony files" complete -c ponysay -s L --description "List pony files with alternatives" -complete -c ponysay -s f -a "$homeponies $systemponies" --description "Select a pony" +complete -c ponysay -s f -a "$ponies" --description "Select a pony" complete -c ponysay -s q -a "$quoters" --description "Select ponies for MLP:FiM quotes" complete -c ponysay -s W -a "Integer" --description "The screen column where the message should be wrapped" -set -e systempath -set -e homepath - -set -e systemponies -set -e homeponies - -set -e qcmd +set -e ponies set -e quoters -- cgit From 9c3499240d7a7fd4569d8af631c1a6068bc5d311 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Aug 2012 16:42:08 +0200 Subject: move clean update --- Makefile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 5d96912..a5929db 100644 --- a/Makefile +++ b/Makefile @@ -136,16 +136,20 @@ uninstall-old: if [ -d "$(INSTALLDIR)/lib/ponysay/pq4ps-list.pl" ]; then unlink "$(INSTALLDIR)/lib/ponysay/pq4ps-list.pl" ; fi clean: - if [ -f "truncater" ]; then rm -f "truncater" ; fi - if [ -f "completion/bash-completion-think.sh" ]; then rm -f "completion/bash-completion-think.sh" ; fi - if [ -f "completion/fish-completion-think.fish" ]; then rm -f "completion/fish-completion-think.fish"; fi - if [ -f "completion/zsh-completion-think.zsh" ]; then rm -f "completion/zsh-completion-think.zsh" ; fi - if [ -f "manuals/manpage.6.gz" ]; then rm -f "manuals/manpage.6.gz" ; fi - if [ -f "manuals/manpage.es.6.gz" ]; then rm -f "manuals/manpage.es.6.gz" ; fi - if [ -f "ponysay.info.gz" ]; then rm -f "ponysay.info.gz" ; fi + if [ -f "truncater" ]; then rm -f "truncater" ; fi + if [ -f "completion/bash-completion-think.sh" ]; then rm -f "completion/bash-completion-think.sh" ; fi + if [ -f "completion/fish-completion-think.fish" ]; then rm -f "completion/fish-completion-think.fish" ; fi + if [ -f "completion/zsh-completion-think.zsh" ]; then rm -f "completion/zsh-completion-think.zsh" ; fi + if [ -f "completion/bash-completion.sh.install" ]; then rm -f "completion/bash-completion.sh.install" ; fi + if [ -f "completion/fish-completion.fish.install" ]; then rm -f "completion/fish-completion.fish.install"; fi + if [ -f "completion/zsh-completion.zsh.install" ]; then rm -f "completion/zsh-completion.zsh.install" ; fi + if [ -f "manuals/manpage.6.gz" ]; then rm -f "manuals/manpage.6.gz" ; fi + if [ -f "manuals/manpage.es.6.gz" ]; then rm -f "manuals/manpage.es.6.gz" ; fi + if [ -f "ponysay.info.gz" ]; then rm -f "ponysay.info.gz" ; fi + if [ -f "ponysay.py.install" ]; then rm -f "ponysay.py.install" ; fi clean-old: - if [ -f "ponysaytruncater" ]; then rm -f "ponysaytruncater" ; fi + if [ -f "ponysaytruncater" ]; then rm -f "ponysaytruncater"; fi ## Scripts for maintainers -- cgit From f9663c7b1bb21922efb775136e6c75dda9ba83ce Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Aug 2012 16:43:22 +0200 Subject: forgot to commit python script --- ponysay.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/ponysay.py b/ponysay.py index e7c671f..f8b7723 100755 --- a/ponysay.py +++ b/ponysay.py @@ -53,6 +53,8 @@ parser = argparse.ArgumentParser(description = 'Ponysay, like cowsay with ponies parser.add_argument('-v', '--version', action = 'version', version = '%s %s' % ("ponysay", VERSION)) parser.add_argument('-l', '--list', action = 'store_true', dest = 'list', help = 'list pony files') parser.add_argument('-L', '--altlist', action = 'store_true', dest = 'linklist', help = 'list pony files with alternatives') +parser.add_argument( '--quoters', action = 'store_true', dest = 'quoters', help = 'list ponies with quotes (visible in -l and -L)') # for shell completions +parser.add_argument( '--onelist', action = 'store_true', dest = 'onelist', help = 'list pony files in one columns') # for shell completions parser.add_argument('-f', '--pony', action = 'append', dest = 'pony', help = 'select a pony (either a file name or a pony name)') parser.add_argument('message', nargs = '?', help = 'message to ponysay') @@ -63,11 +65,13 @@ class ponysay(): def __init__(self, args): if args.list: self.list() elif args.linklist: self.linklist() + elif args.quoters: self.quoters() + elif args.onelist: self.onelist() else: self.print_pony(args) ''' - Returns a set with all ponies that have quotes and is displayable + Returns a set with all ponies that have quotes and are displayable ''' def __quoters(self): quotes = [] @@ -215,6 +219,37 @@ class ponysay(): print("\n"); + ''' + Lists with all ponies that have quotes and are displayable + ''' + def quoters(self): + last = "" + ponies = [] + for pony in self.__quoters(): + ponies.append(pony) + ponies.sort() + for pony in ponies: + if not pony == last: + last = pony + print(pony) + + + ''' + Lists the available ponies one one column without anything bold + ''' + def onelist(self): + last = "" + ponies = [] + for ponydir in ponydirs: # Loop ponydirs + ponies += os.listdir(ponydir) + ponies = [item[:-5] for item in ponies] # remove .pony from file name + ponies.sort() + for pony in ponies: + if not pony == last: + last = pony + print(pony) + + def print_pony(self, args): if args.message == None: msg = sys.stdin.read().strip() -- cgit