Compare commits

...

27 Commits

Author SHA1 Message Date
edd7b5e806 Minor revisions on #244
- When using GFM code fences, strip the last line in addition to the
  first
- Updated `README.md` to mention the new feature
- `minor` version-bump to `2.2.0`.
2017-02-28 18:59:27 -05:00
7abb663bf4 Merge branch 'more_lexers' of git://github.com/cnicolov/cheat into cnicolov-more_lexers 2017-02-28 18:22:58 -05:00
f6f1233b12 Deleted CHANGELOG
Deleted `CHANGELOG`. It was never used.
2017-02-28 17:46:23 -05:00
b9241efab1 CONTRIBUTING.md
Put some useful information in `CONTRIBUTING.md`.
2017-02-28 17:45:53 -05:00
8019325f1e README edit
The sheilds.io badge displaying downloads per month has been broken for
some time now (seemingly across all python projects), so I removed it.
2017-02-28 09:32:00 -05:00
7209f2c929 docopt
Made revisions to the content of the docopt template.
2017-02-27 23:09:51 -05:00
068d117bef patch version bump. 2017-02-27 23:02:23 -05:00
9ead66461d Resolving merge conflict. 2017-02-27 23:01:30 -05:00
d00bd87dd1 Merge pull request #312 from shanahanjrs/feature-cheat-cheat
Added a cheatsheet for cheat itself
2017-02-27 19:36:45 -05:00
dd8b20a17a Merge pull request #317 from shanahanjrs/fix-7z-typo
Fixed typo in 7z cheatsheet
2017-02-27 19:29:58 -05:00
84e42e7f2f Merge pull request #314 from shanahanjrs/pushd-popd
Added cheatsheets for pushd and popd commands
2017-02-27 19:29:12 -05:00
a59e91ead7 Merge pull request #320 from tupaschoal/master
Add cheatsheet for hg, shutdown, su
2017-02-27 19:26:58 -05:00
f495a4dfd9 Add cheatsheet for su
Useful for running commands as another user.
2017-02-16 01:25:24 -02:00
10dd0e9a8b Add cheatsheet for shutdown
Adding help for shutdown, useful for rebooting the system,
2017-02-16 01:22:45 -02:00
d06e5bab6f Add cheatsheet for hg
Mercurial is extensively used as a version control system, as an option to Git, so I'm adding its cheatsheet.
2017-02-16 00:04:18 -02:00
75b2555710 Fixed typo in 7z cheatsheet 2017-01-25 18:52:25 -05:00
632da2024a Added cheatsheets for pushd and popd commands 2017-01-08 17:11:51 -05:00
1baa6d39c0 Added a cheatsheet for cheat itself 2017-01-01 22:44:48 -05:00
8f2912e5da Fix grammar of lsof 2016-11-27 08:43:37 -05:00
3139796524 Update lsof sheet 2016-11-27 08:43:37 -05:00
bcd4563bf3 Add npm cheatsheet 2016-11-27 08:43:37 -05:00
5cd5387a47 Add cheery-pick to git cheat 2016-11-27 08:43:37 -05:00
c8f0e6295b Add revert in git cheat 2016-11-27 08:43:37 -05:00
31e442d7f9 Add git stash cheat 2016-11-27 08:43:37 -05:00
352a760561 README edit
Modified the README with regards to the environment variable changes
made in #294.
2016-10-01 14:08:58 -04:00
6be87e2d42 cheat now honors CHEAT_EDITOR and VISUAL environment variables in
addition to `EDITOR`.
2016-10-01 13:55:50 -04:00
c1fbeffde5 Adds support for more lexers
If you use cheat to save some programming snippets this might be useful.

For example if you have a long list of SQL Query cheats, you can do the
following:

Enter ```sql in the beginning of the file containing the cheats content.

Example file: sql
```sql

SELECT 17 & 16 = 16;
SELECT 2+4+8+16 & 1 = 0;
2015-12-02 14:47:13 +02:00
13 changed files with 119 additions and 31 deletions

View File

@ -1,3 +0,0 @@
Changelog
=========

View File

@ -3,15 +3,23 @@ Contributing
If you would like to contribute cheetsheets or program functionality, please If you would like to contribute cheetsheets or program functionality, please
fork this repository, make your changes, and submit a pull request. fork this repository, make your changes, and submit a pull request.
## Python standards ##
Python code should conform to [PEP 8][]. Python code should conform to [PEP 8][].
Licensing
---------
By contributing to the project, you agree to license your work under the same
licenses as `cheat` itself. `cheat` is currently dual-licensed under the GPL3
and MIT licenses, though that could change without notice in the future.
`cheat`, however, will always remain free software (as in both "free as in ## Cheatsheet Format ##
freedom" and "free as in beer") and shall always be licensed accordingly. Please pattern your cheatsheets after the following:
```sh
# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar
# To create an uncompressed archive:
tar -cvf /path/to/foo.tar /path/to/foo/
# To extract a .gz archive:
tar -xzvf /path/to/foo.tgz
```
[PEP 8]: http://legacy.python.org/dev/peps/pep-0008/ [PEP 8]: http://legacy.python.org/dev/peps/pep-0008/

View File

@ -1,5 +1,4 @@
[![PyPI](https://img.shields.io/pypi/v/cheat.svg)](https://pypi.python.org/pypi/cheat/) [![PyPI](https://img.shields.io/pypi/v/cheat.svg)](https://pypi.python.org/pypi/cheat/)
[![PyPI](https://img.shields.io/pypi/dm/cheat.svg)](https://pypi.python.org/pypi/cheat/)
cheat cheat
===== =====
@ -74,7 +73,7 @@ variable set, you may edit cheatsheets with:
cheat -e foo cheat -e foo
``` ```
If the 'foo' cheatsheet already exists, it will be opened for editing. If the `foo` cheatsheet already exists, it will be opened for editing.
Otherwise, it will be created automatically. Otherwise, it will be created automatically.
After you've customized your cheatsheets, I urge you to track `~/.cheat/` along After you've customized your cheatsheets, I urge you to track `~/.cheat/` along
@ -110,13 +109,32 @@ export CHEATPATH="$CHEATPATH:/path/to/more/cheats"
You may view which directories are on your `CHEATPATH` with `cheat -d`. You may view which directories are on your `CHEATPATH` with `cheat -d`.
### Enabling Syntax Highlighting ### ### Enabling Syntax Highlighting ###
`cheat` can apply syntax highlighting to your cheatsheets if so desired. To `cheat` can optionally apply syntax highlighting to your cheatsheets. To enable
enable this feature, set a `CHEATCOLORS` environment variable: syntax highlighting, export a `CHEATCOLORS` environment variable:
```sh ```sh
export CHEATCOLORS=true export CHEATCOLORS=true
``` ```
#### Specifying a Syntax Highlighter ####
You may manually specify which syntax highlighter to use for each cheatsheet by
wrapping the sheet's contents in a [Github-Flavored Markdown code-fence][gfm].
Example:
<pre>
```sql
-- to select a user by ID
SELECT *
FROM Users
WHERE id = 100
```
</pre>
If no syntax highlighter is specified, the `bash` highlighter will be used by
default.
See Also: See Also:
--------- ---------
- [Enabling Command-line Autocompletion][autocompletion] - [Enabling Command-line Autocompletion][autocompletion]
@ -125,5 +143,6 @@ See Also:
[autocompletion]: https://github.com/chrisallenlane/cheat/wiki/Enabling-Command-line-Autocompletion [autocompletion]: https://github.com/chrisallenlane/cheat/wiki/Enabling-Command-line-Autocompletion
[dotfiles]: http://dotfiles.github.io/ [dotfiles]: http://dotfiles.github.io/
[gfm]: https://help.github.com/articles/creating-and-highlighting-code-blocks/
[installing]: https://github.com/chrisallenlane/cheat/wiki/Installing [installing]: https://github.com/chrisallenlane/cheat/wiki/Installing
[related-projects]: https://github.com/chrisallenlane/cheat/wiki/Related-Projects [related-projects]: https://github.com/chrisallenlane/cheat/wiki/Related-Projects

View File

@ -2,6 +2,8 @@
"""cheat """cheat
Create and view cheatsheets on the command line.
Usage: Usage:
cheat <cheatsheet> cheat <cheatsheet>
cheat -e <cheatsheet> cheat -e <cheatsheet>
@ -10,24 +12,26 @@ Usage:
cheat -d cheat -d
cheat -v cheat -v
cheat allows you to create and view interactive cheatsheets on the
command-line. It was designed to help remind *nix system
administrators of options for commands that they use frequently,
but not frequently enough to remember.
Examples:
To look up 'tar':
cheat tar
To create or edit the cheatsheet for 'foo':
cheat -e foo
Options: Options:
-d --directories List directories on CHEATPATH -d --directories List directories on CHEATPATH
-e --edit Edit cheatsheet -e --edit Edit cheatsheet
-l --list List cheatsheets -l --list List cheatsheets
-s --search Search cheatsheets for <keyword> -s --search Search cheatsheets for <keyword>
-v --version Print the version number -v --version Print the version number
Examples:
To view the `tar` cheatsheet:
cheat tar
To edit (or create) the `foo` cheatsheet:
cheat -e foo
To list all available cheatsheets:
cheat -l
To search for "ssh" among all cheatsheets:
cheat -s ssh
""" """
# require the dependencies # require the dependencies
@ -38,7 +42,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.27') options = docopt(__doc__, version='cheat 2.2.0')
# list directories # list directories
if options['--directories']: if options['--directories']:

View File

@ -11,7 +11,7 @@ u update
x extract with full paths x extract with full paths
Example: Example:
7z a -t7z -m0-lzma -mx=9 -mfb=64 -md=32m -ms=on archive.7z dir1 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on archive.7z dir1
-t7z 7z archive -t7z 7z archive
-m0=lzma lzma method -m0=lzma lzma method

14
cheat/cheatsheets/cheat Normal file
View File

@ -0,0 +1,14 @@
# To see example usage of a program:
cheat <command>
# To edit a cheatsheet
cheat -e <command>
# To list available cheatsheets
cheat -l
# To search available cheatsheets
cheat -s <command>
# To get the current `cheat' version
cheat -v

20
cheat/cheatsheets/hg Normal file
View File

@ -0,0 +1,20 @@
# Clone a directory
hg clone
# Add files to hg tracker
hg add filename
# Add all files in a folder to hg tracker
hg add folder/
# Create a commit with all tracked changes and a message
hg commit -m "message"
# Push commits to source repository
hg push
# Pull changes from source repository
hg pull
# Rebase local commits to disambiguate with remote repository
hg pull --rebase

2
cheat/cheatsheets/popd Normal file
View File

@ -0,0 +1,2 @@
# Returns to the directory at the top of the `pushd' stack
popd

5
cheat/cheatsheets/pushd Normal file
View File

@ -0,0 +1,5 @@
# Pushes your current directory to the top of a stack while changing to the specified directory
pushd <directory>
# To return use popd
popd

View File

@ -0,0 +1,8 @@
# Reboot the system immediately
shutdown -r now
# Shut system down immediately
shutdown -h now
# Reboot system after 5 minutes
shutdown -r +5

2
cheat/cheatsheets/su Normal file
View File

@ -0,0 +1,2 @@
# Switch to another user account
su USERNAME

View File

@ -13,14 +13,23 @@ def colorize(sheet_content):
try: try:
from pygments import highlight from pygments import highlight
from pygments.lexers import BashLexer from pygments.lexers import get_lexer_by_name
from pygments.formatters import TerminalFormatter from pygments.formatters import TerminalFormatter
# if pygments can't load, just return the uncolorized text # if pygments can't load, just return the uncolorized text
except ImportError: except ImportError:
return sheet_content return sheet_content
return highlight(sheet_content, BashLexer(), TerminalFormatter()) first_line = sheet_content.splitlines()[0]
lexer = get_lexer_by_name('bash')
if first_line.startswith('```'):
sheet_content = '\n'.join(sheet_content.split('\n')[1:-2])
try:
lexer = get_lexer_by_name(first_line[3:])
except Exception:
pass
return highlight(sheet_content, lexer, TerminalFormatter())
def die(message): def die(message):

View File

@ -3,7 +3,7 @@ import os
setup( setup(
name = 'cheat', name = 'cheat',
version = '2.1.27', version = '2.2.0',
author = 'Chris Lane', author = 'Chris Lane',
author_email = 'chris@chris-allen-lane.com', author_email = 'chris@chris-allen-lane.com',
license = 'GPL3', license = 'GPL3',