From 8dda6a9241a20cc6e36ff6efd01e0ac84a7883db Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Tue, 13 Aug 2013 11:01:06 +0100 Subject: [PATCH] Package with distutils Created cheatsheets package to store the default sheets. --- cheat | 13 +++++++------ cheatsheets/__init__.py | 3 +++ {.cheat => cheatsheets}/apt-cache | 0 {.cheat => cheatsheets}/bash | 0 {.cheat => cheatsheets}/convert | 0 {.cheat => cheatsheets}/cut | 0 {.cheat => cheatsheets}/dhclient | 0 {.cheat => cheatsheets}/find | 0 {.cheat => cheatsheets}/git | 0 {.cheat => cheatsheets}/ln | 0 {.cheat => cheatsheets}/mysqldump | 0 {.cheat => cheatsheets}/netstat | 0 {.cheat => cheatsheets}/notify-send | 0 {.cheat => cheatsheets}/sed | 0 {.cheat => cheatsheets}/shred | 0 {.cheat => cheatsheets}/sockstat | 0 {.cheat => cheatsheets}/split | 0 {.cheat => cheatsheets}/ssh | 0 {.cheat => cheatsheets}/ssh-copy-id | 0 {.cheat => cheatsheets}/ssh-keygen | 0 {.cheat => cheatsheets}/stdout | 0 {.cheat => cheatsheets}/tar | 0 setup.py | 16 ++++++++++++++++ 23 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 cheatsheets/__init__.py rename {.cheat => cheatsheets}/apt-cache (100%) rename {.cheat => cheatsheets}/bash (100%) rename {.cheat => cheatsheets}/convert (100%) rename {.cheat => cheatsheets}/cut (100%) rename {.cheat => cheatsheets}/dhclient (100%) rename {.cheat => cheatsheets}/find (100%) rename {.cheat => cheatsheets}/git (100%) rename {.cheat => cheatsheets}/ln (100%) rename {.cheat => cheatsheets}/mysqldump (100%) rename {.cheat => cheatsheets}/netstat (100%) rename {.cheat => cheatsheets}/notify-send (100%) rename {.cheat => cheatsheets}/sed (100%) rename {.cheat => cheatsheets}/shred (100%) rename {.cheat => cheatsheets}/sockstat (100%) rename {.cheat => cheatsheets}/split (100%) rename {.cheat => cheatsheets}/ssh (100%) rename {.cheat => cheatsheets}/ssh-copy-id (100%) rename {.cheat => cheatsheets}/ssh-keygen (100%) rename {.cheat => cheatsheets}/stdout (100%) rename {.cheat => cheatsheets}/tar (100%) create mode 100644 setup.py diff --git a/cheat b/cheat index ad69b44..5cd91d4 100755 --- a/cheat +++ b/cheat @@ -1,18 +1,18 @@ #!/usr/bin/env python import os import sys +from cheatsheets import cheat_dir # assemble a keyphrase out of all params passed to the script keyphrase = ' '.join(sys.argv[1:]) -cheat_dir = os.path.expanduser('~') + '/.cheat/' -# verify that the ~/.cheat directory exists +# verify that the cheat directory exists if not os.path.isdir(cheat_dir): - print >> sys.stderr, 'The ~/.cheat directory does not exist.' + print >> sys.stderr, 'The cheat directory does not exist.' exit() -# list the files in the ~/.cheat directory -cheatsheets = os.listdir(cheat_dir) +# list the files in the cheat directory +cheatsheets = [f for f in os.listdir(cheat_dir) if '.' not in f] cheatsheets.sort() # print help if requested @@ -24,7 +24,8 @@ if keyphrase in ['', 'help', '--help', '-h']: # print the cheatsheet if it exists if keyphrase in cheatsheets: - with open (cheat_dir + keyphrase, 'r') as cheatsheet: + cheatsheet_filename = os.path.join(cheat_dir, keyphrase) + with open(cheatsheet_filename, 'r') as cheatsheet: print cheatsheet.read() # if it does not, say so diff --git a/cheatsheets/__init__.py b/cheatsheets/__init__.py new file mode 100644 index 0000000..8a9b797 --- /dev/null +++ b/cheatsheets/__init__.py @@ -0,0 +1,3 @@ +import os + +cheat_dir, __init = os.path.split(__file__) diff --git a/.cheat/apt-cache b/cheatsheets/apt-cache similarity index 100% rename from .cheat/apt-cache rename to cheatsheets/apt-cache diff --git a/.cheat/bash b/cheatsheets/bash similarity index 100% rename from .cheat/bash rename to cheatsheets/bash diff --git a/.cheat/convert b/cheatsheets/convert similarity index 100% rename from .cheat/convert rename to cheatsheets/convert diff --git a/.cheat/cut b/cheatsheets/cut similarity index 100% rename from .cheat/cut rename to cheatsheets/cut diff --git a/.cheat/dhclient b/cheatsheets/dhclient similarity index 100% rename from .cheat/dhclient rename to cheatsheets/dhclient diff --git a/.cheat/find b/cheatsheets/find similarity index 100% rename from .cheat/find rename to cheatsheets/find diff --git a/.cheat/git b/cheatsheets/git similarity index 100% rename from .cheat/git rename to cheatsheets/git diff --git a/.cheat/ln b/cheatsheets/ln similarity index 100% rename from .cheat/ln rename to cheatsheets/ln diff --git a/.cheat/mysqldump b/cheatsheets/mysqldump similarity index 100% rename from .cheat/mysqldump rename to cheatsheets/mysqldump diff --git a/.cheat/netstat b/cheatsheets/netstat similarity index 100% rename from .cheat/netstat rename to cheatsheets/netstat diff --git a/.cheat/notify-send b/cheatsheets/notify-send similarity index 100% rename from .cheat/notify-send rename to cheatsheets/notify-send diff --git a/.cheat/sed b/cheatsheets/sed similarity index 100% rename from .cheat/sed rename to cheatsheets/sed diff --git a/.cheat/shred b/cheatsheets/shred similarity index 100% rename from .cheat/shred rename to cheatsheets/shred diff --git a/.cheat/sockstat b/cheatsheets/sockstat similarity index 100% rename from .cheat/sockstat rename to cheatsheets/sockstat diff --git a/.cheat/split b/cheatsheets/split similarity index 100% rename from .cheat/split rename to cheatsheets/split diff --git a/.cheat/ssh b/cheatsheets/ssh similarity index 100% rename from .cheat/ssh rename to cheatsheets/ssh diff --git a/.cheat/ssh-copy-id b/cheatsheets/ssh-copy-id similarity index 100% rename from .cheat/ssh-copy-id rename to cheatsheets/ssh-copy-id diff --git a/.cheat/ssh-keygen b/cheatsheets/ssh-keygen similarity index 100% rename from .cheat/ssh-keygen rename to cheatsheets/ssh-keygen diff --git a/.cheat/stdout b/cheatsheets/stdout similarity index 100% rename from .cheat/stdout rename to cheatsheets/stdout diff --git a/.cheat/tar b/cheatsheets/tar similarity index 100% rename from .cheat/tar rename to cheatsheets/tar diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..af240f9 --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +from distutils.core import setup +import os + +setup(name='cheat', + version='1.0', + description='Create and view interactive cheatsheets on the command-line', + author='Chris Lane', + author_email='chris@chris-allen-lane.com', + url='https://github.com/chrisallenlane/cheat', + packages=['cheatsheets'], + package_data={'cheatsheets': [f for f in os.listdir('cheatsheets') + if '.' not in f]}, + scripts=['cheat'] + )