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'] + )