mirror of
https://github.com/cheat/cheat.git
synced 2025-09-04 02:58:29 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
417f47f037 | |||
f39fad1324 | |||
4cf03c5363 | |||
afcd74c8bf | |||
e27ce3f1f9 | |||
e9b8f04c24 | |||
d14c759a48 | |||
c70dc002fa | |||
ff8ba4e717 | |||
718ec4f685 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
MANIFEST
|
MANIFEST
|
||||||
build
|
build
|
||||||
|
cheat.egg-info
|
||||||
dist
|
dist
|
||||||
|
@ -38,7 +38,7 @@ from docopt import docopt
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# parse the command-line options
|
# parse the command-line options
|
||||||
options = docopt(__doc__, version='cheat 2.1.4')
|
options = docopt(__doc__, version='cheat 2.1.8')
|
||||||
|
|
||||||
# list directories
|
# list directories
|
||||||
if options['--directories']:
|
if options['--directories']:
|
||||||
|
15
cheat/cheatsheets/paste
Normal file
15
cheat/cheatsheets/paste
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Concat columns from files
|
||||||
|
paste file1 file2 ...
|
||||||
|
|
||||||
|
# List the files in the current directory in three columns:
|
||||||
|
ls | paste - - -
|
||||||
|
|
||||||
|
# Combine pairs of lines from a file into single lines:
|
||||||
|
paste -s -d '\t\n' myfile
|
||||||
|
|
||||||
|
# Number the lines in a file, similar to nl(1):
|
||||||
|
sed = myfile | paste -s -d '\t\n' - -
|
||||||
|
|
||||||
|
# Create a colon-separated list of directories named bin,
|
||||||
|
# suitable for use in the PATH environment variable:
|
||||||
|
find / -name bin -type d | paste -s -d : -
|
@ -22,6 +22,9 @@ yum info <package name>
|
|||||||
# List currently enabled repositories:
|
# List currently enabled repositories:
|
||||||
yum repolist
|
yum repolist
|
||||||
|
|
||||||
|
# List packages containing a certain keyword:
|
||||||
|
yum list <package_name_or_word_to_search>
|
||||||
|
|
||||||
# To download the source RPM for a package:
|
# To download the source RPM for a package:
|
||||||
yumdownloader --source <package name>
|
yumdownloader --source <package name>
|
||||||
|
|
||||||
|
@ -25,28 +25,16 @@ def create_or_edit(sheet):
|
|||||||
# if the cheatsheet does not exist
|
# if the cheatsheet does not exist
|
||||||
if not exists(sheet):
|
if not exists(sheet):
|
||||||
create(sheet)
|
create(sheet)
|
||||||
|
|
||||||
# if the cheatsheet exists and is writeable...
|
# if the cheatsheet exists but not in the default_path, copy it to the
|
||||||
elif exists(sheet) and is_writable(sheet):
|
# default path before editing
|
||||||
|
elif exists(sheet) and not exists_in_default_path(sheet):
|
||||||
|
copy(path(sheet), os.path.join(sheets.default_path(), sheet))
|
||||||
edit(sheet)
|
edit(sheet)
|
||||||
|
|
||||||
# if the cheatsheet exists but is not writable...
|
# if it exists and is in the default path, then just open it
|
||||||
elif exists(sheet) and not is_writable(sheet):
|
else:
|
||||||
# ... ask the user if we should copy the cheatsheet to her home directory for editing
|
edit(sheet)
|
||||||
yes = prompt_yes_or_no(
|
|
||||||
'The ' + sheet + ' sheet is not editable. Do you want to copy it to '
|
|
||||||
'your user cheatsheets directory before editing? Keep in mind that '
|
|
||||||
'your sheet will always be used before system-wide one.'
|
|
||||||
)
|
|
||||||
|
|
||||||
# if yes, copy the cheatsheet to the home directory before editing
|
|
||||||
if yes:
|
|
||||||
copy(path(sheet), os.path.join(sheets.default_path(), sheet))
|
|
||||||
edit(sheet)
|
|
||||||
|
|
||||||
# if no, just abort
|
|
||||||
else:
|
|
||||||
die('Aborting.')
|
|
||||||
|
|
||||||
|
|
||||||
def create(sheet):
|
def create(sheet):
|
||||||
@ -75,6 +63,12 @@ def exists(sheet):
|
|||||||
return sheet in sheets.get() and os.access(path(sheet), os.R_OK)
|
return sheet in sheets.get() and os.access(path(sheet), os.R_OK)
|
||||||
|
|
||||||
|
|
||||||
|
def exists_in_default_path(sheet):
|
||||||
|
""" Predicate that returns true if the sheet exists in default_path"""
|
||||||
|
default_path_sheet = os.path.join(sheets.default_path(), sheet)
|
||||||
|
return sheet in sheets.get() and os.access(default_path_sheet, os.R_OK)
|
||||||
|
|
||||||
|
|
||||||
def is_writable(sheet):
|
def is_writable(sheet):
|
||||||
""" Predicate that returns true if the sheet is writeable """
|
""" Predicate that returns true if the sheet is writeable """
|
||||||
return sheet in sheets.get() and os.access(path(sheet), os.W_OK)
|
return sheet in sheets.get() and os.access(path(sheet), os.W_OK)
|
||||||
|
@ -2,13 +2,6 @@ from cheat import cheatsheets
|
|||||||
from cheat.utils import *
|
from cheat.utils import *
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# @kludge: it breaks the functional paradigm to a degree, but declaring this
|
|
||||||
# var here (versus within get()) gives us a "poor man's" memoization on the
|
|
||||||
# call to get(). This, in turn, spares us from having to call out to the
|
|
||||||
# filesystem more than once.
|
|
||||||
cheats = {}
|
|
||||||
|
|
||||||
|
|
||||||
def default_path():
|
def default_path():
|
||||||
""" Returns the default cheatsheet path """
|
""" Returns the default cheatsheet path """
|
||||||
|
|
||||||
@ -37,11 +30,7 @@ def default_path():
|
|||||||
|
|
||||||
def get():
|
def get():
|
||||||
""" Assembles a dictionary of cheatsheets as name => file-path """
|
""" Assembles a dictionary of cheatsheets as name => file-path """
|
||||||
|
cheats = {}
|
||||||
# if we've already reached out to the filesystem, just return the result
|
|
||||||
# from memory
|
|
||||||
if cheats:
|
|
||||||
return cheats
|
|
||||||
|
|
||||||
# otherwise, scan the filesystem
|
# otherwise, scan the filesystem
|
||||||
for cheat_dir in reversed(paths()):
|
for cheat_dir in reversed(paths()):
|
||||||
|
2
setup.py
2
setup.py
@ -3,7 +3,7 @@ import os
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = 'cheat',
|
name = 'cheat',
|
||||||
version = '2.1.4',
|
version = '2.1.8',
|
||||||
author = 'Chris Lane',
|
author = 'Chris Lane',
|
||||||
author_email = 'chris@chris-allen-lane.com',
|
author_email = 'chris@chris-allen-lane.com',
|
||||||
license = 'GPL3',
|
license = 'GPL3',
|
||||||
|
Reference in New Issue
Block a user