mirror of
https://github.com/cheat/cheat.git
synced 2025-09-04 11:08:29 +02:00
Compare commits
86 Commits
Author | SHA1 | Date | |
---|---|---|---|
edd7b5e806 | |||
7abb663bf4 | |||
f6f1233b12 | |||
b9241efab1 | |||
8019325f1e | |||
7209f2c929 | |||
068d117bef | |||
9ead66461d | |||
d00bd87dd1 | |||
dd8b20a17a | |||
84e42e7f2f | |||
a59e91ead7 | |||
f495a4dfd9 | |||
10dd0e9a8b | |||
d06e5bab6f | |||
75b2555710 | |||
632da2024a | |||
1baa6d39c0 | |||
8cad76943a | |||
a6ec02c296 | |||
7392787e31 | |||
208dd24a0c | |||
df34774a7a | |||
8d65424ffb | |||
597acec6ac | |||
7d4150b937 | |||
5df5b1ab49 | |||
f1c8017342 | |||
8f2912e5da | |||
3139796524 | |||
bcd4563bf3 | |||
5cd5387a47 | |||
c8f0e6295b | |||
31e442d7f9 | |||
05400a92ed | |||
034c1a2415 | |||
dab8645394 | |||
352a760561 | |||
6be87e2d42 | |||
403d715127 | |||
0edd1450dc | |||
d87a26ce4f | |||
cdf240b70e | |||
809c6d77bc | |||
be543450c7 | |||
9889d77adb | |||
354376340f | |||
d82eee726c | |||
9a23458a2d | |||
32802c2907 | |||
2a6d34de35 | |||
f1253031f2 | |||
76fa9cfc23 | |||
0a54b2a2ff | |||
6a1742984c | |||
80d2a09456 | |||
5121fece91 | |||
e8d32102cb | |||
eff042d50b | |||
f000756f2c | |||
ef1dfb2168 | |||
3c1b5c5860 | |||
3494827403 | |||
f0879831c5 | |||
8c056d09e9 | |||
dd8d0ae58b | |||
6cc99a2b6a | |||
70ad22c12e | |||
b28e6a84ac | |||
bf4f1c80ca | |||
9cf1a5761d | |||
13fdcec332 | |||
b2feeab4e8 | |||
c4b7fd507f | |||
b77aa0974b | |||
3be95142ed | |||
bb324e94a4 | |||
7084ce2f45 | |||
905006f09c | |||
06a368fb1f | |||
6a9422502a | |||
41332f1d8a | |||
b6d54b135c | |||
a3c682729e | |||
f38da23741 | |||
c1fbeffde5 |
@ -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/
|
||||||
|
6
MANIFEST.in
Normal file
6
MANIFEST.in
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include CHANGELOG
|
||||||
|
include CONTRIBUTING.md
|
||||||
|
include LICENSE
|
||||||
|
include README.md
|
||||||
|
include licenses/gpl-3.txt
|
||||||
|
include licenses/mit.txt
|
31
README.md
31
README.md
@ -1,5 +1,4 @@
|
|||||||
[](https://pypi.python.org/pypi/cheat/)
|
[](https://pypi.python.org/pypi/cheat/)
|
||||||
[](https://pypi.python.org/pypi/cheat/)
|
|
||||||
|
|
||||||
cheat
|
cheat
|
||||||
=====
|
=====
|
||||||
@ -67,14 +66,14 @@ Cheatsheets are stored in the `~/.cheat/` directory, and are named on a
|
|||||||
per-keyphrase basis. In other words, the content for the `tar` cheatsheet lives
|
per-keyphrase basis. In other words, the content for the `tar` cheatsheet lives
|
||||||
in the `~/.cheat/tar` file.
|
in the `~/.cheat/tar` file.
|
||||||
|
|
||||||
Provided that you have an `EDITOR` environment variable set, you may edit
|
Provided that you have a `CHEAT_EDITOR`, `VISUAL`, or `EDITOR` environment
|
||||||
cheatsheets with:
|
variable set, you may edit cheatsheets with:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
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
|
||||||
|
34
bin/cheat
34
bin/cheat
@ -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,35 +12,37 @@ 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
|
||||||
from cheat import *
|
from cheat import sheets, sheet
|
||||||
from cheat.utils import *
|
from cheat.utils import colorize
|
||||||
from docopt import docopt
|
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.24')
|
options = docopt(__doc__, version='cheat 2.2.0')
|
||||||
|
|
||||||
# list directories
|
# list directories
|
||||||
if options['--directories']:
|
if options['--directories']:
|
||||||
|
@ -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
|
||||||
|
72
cheat/cheatsheets/ansi
Normal file
72
cheat/cheatsheets/ansi
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
# Reset
|
||||||
|
Color_Off='\e[0m' # Text Reset
|
||||||
|
|
||||||
|
# Regular Colors
|
||||||
|
Black='\e[0;30m' # Black
|
||||||
|
Red='\e[0;31m' # Red
|
||||||
|
Green='\e[0;32m' # Green
|
||||||
|
Yellow='\e[0;33m' # Yellow
|
||||||
|
Blue='\e[0;34m' # Blue
|
||||||
|
Purple='\e[0;35m' # Purple
|
||||||
|
Cyan='\e[0;36m' # Cyan
|
||||||
|
White='\e[0;37m' # White
|
||||||
|
|
||||||
|
# Bold
|
||||||
|
BBlack='\e[1;30m' # Black
|
||||||
|
BRed='\e[1;31m' # Red
|
||||||
|
BGreen='\e[1;32m' # Green
|
||||||
|
BYellow='\e[1;33m' # Yellow
|
||||||
|
BBlue='\e[1;34m' # Blue
|
||||||
|
BPurple='\e[1;35m' # Purple
|
||||||
|
BCyan='\e[1;36m' # Cyan
|
||||||
|
BWhite='\e[1;37m' # White
|
||||||
|
|
||||||
|
# Underline
|
||||||
|
UBlack='\e[4;30m' # Black
|
||||||
|
URed='\e[4;31m' # Red
|
||||||
|
UGreen='\e[4;32m' # Green
|
||||||
|
UYellow='\e[4;33m' # Yellow
|
||||||
|
UBlue='\e[4;34m' # Blue
|
||||||
|
UPurple='\e[4;35m' # Purple
|
||||||
|
UCyan='\e[4;36m' # Cyan
|
||||||
|
UWhite='\e[4;37m' # White
|
||||||
|
|
||||||
|
# Background
|
||||||
|
On_Black='\e[40m' # Black
|
||||||
|
On_Red='\e[41m' # Red
|
||||||
|
On_Green='\e[42m' # Green
|
||||||
|
On_Yellow='\e[43m' # Yellow
|
||||||
|
On_Blue='\e[44m' # Blue
|
||||||
|
On_Purple='\e[45m' # Purple
|
||||||
|
On_Cyan='\e[46m' # Cyan
|
||||||
|
On_White='\e[47m' # White
|
||||||
|
|
||||||
|
# High Intensity
|
||||||
|
IBlack='\e[0;90m' # Black
|
||||||
|
IRed='\e[0;91m' # Red
|
||||||
|
IGreen='\e[0;92m' # Green
|
||||||
|
IYellow='\e[0;93m' # Yellow
|
||||||
|
IBlue='\e[0;94m' # Blue
|
||||||
|
IPurple='\e[0;95m' # Purple
|
||||||
|
ICyan='\e[0;96m' # Cyan
|
||||||
|
IWhite='\e[0;97m' # White
|
||||||
|
|
||||||
|
# Bold High Intensity
|
||||||
|
BIBlack='\e[1;90m' # Black
|
||||||
|
BIRed='\e[1;91m' # Red
|
||||||
|
BIGreen='\e[1;92m' # Green
|
||||||
|
BIYellow='\e[1;93m' # Yellow
|
||||||
|
BIBlue='\e[1;94m' # Blue
|
||||||
|
BIPurple='\e[1;95m' # Purple
|
||||||
|
BICyan='\e[1;96m' # Cyan
|
||||||
|
BIWhite='\e[1;97m' # White
|
||||||
|
|
||||||
|
# High Intensity backgrounds
|
||||||
|
On_IBlack='\e[0;100m' # Black
|
||||||
|
On_IRed='\e[0;101m' # Red
|
||||||
|
On_IGreen='\e[0;102m' # Green
|
||||||
|
On_IYellow='\e[0;103m' # Yellow
|
||||||
|
On_IBlue='\e[0;104m' # Blue
|
||||||
|
On_IPurple='\e[0;105m' # Purple
|
||||||
|
On_ICyan='\e[0;106m' # Cyan
|
||||||
|
On_IWhite='\e[0;107m' # White
|
12
cheat/cheatsheets/aria2c
Normal file
12
cheat/cheatsheets/aria2c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Just download a file
|
||||||
|
# The url can be a http(s), ftp, .torrent file or even a magnet link
|
||||||
|
aria2c <url>
|
||||||
|
|
||||||
|
# To prevent downloading the .torrent file
|
||||||
|
aria2c --follow-torrent=mem <url>
|
||||||
|
|
||||||
|
# Download 1 file at a time (-j)
|
||||||
|
# continuing (-c) any partially downloaded ones
|
||||||
|
# to the directory specified (-d)
|
||||||
|
# reading urls from the file (-i)
|
||||||
|
aria2c -j 1 -c -d ~/Downloads -i /path/to/file
|
11
cheat/cheatsheets/bzip2
Normal file
11
cheat/cheatsheets/bzip2
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# compress foo -> foo.bz2
|
||||||
|
bzip2 -z foo
|
||||||
|
|
||||||
|
# decompress foo.bz2 -> foo
|
||||||
|
bzip2 -d foo.bz2
|
||||||
|
|
||||||
|
# compress foo to stdout
|
||||||
|
bzip2 -zc foo > foo.bz2
|
||||||
|
|
||||||
|
# decompress foo.bz2 to stdout
|
||||||
|
bzip2 -dc foo.bz2
|
14
cheat/cheatsheets/cheat
Normal file
14
cheat/cheatsheets/cheat
Normal 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
|
132
cheat/cheatsheets/cpdf
Normal file
132
cheat/cheatsheets/cpdf
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
# Read in.pdf, select pages 1, 2, 3 and 6, and write those pages to
|
||||||
|
# out.pdf
|
||||||
|
cpdf in.pdf 1-3,6 -o out.pdf
|
||||||
|
|
||||||
|
# Select the even pages (2, 4, 6...) from in.pdf and write those pages
|
||||||
|
# to out.pdf
|
||||||
|
cpdf in.pdf even -o out.pdf
|
||||||
|
|
||||||
|
# Using AND to perform several operations in order, here merging two
|
||||||
|
# files together and adding a copyright stamp to every page.
|
||||||
|
cpdf -merge in.pdf in2.pdf AND -add-text "Copyright 2014" -o out.pdf
|
||||||
|
|
||||||
|
# Read control.txt and use its contents as the command line arguments
|
||||||
|
# for cpdf.
|
||||||
|
cpdf -control control.txt
|
||||||
|
|
||||||
|
# Merge in.pdf and in2.pdf into one document, writing to out.pdf.
|
||||||
|
cpdf -merge in.pdf in2.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Split in.pdf into ten-page chunks, writing them to Chunk001.pdf,
|
||||||
|
# Chunk002.pdf etc
|
||||||
|
cpdf -split in.pdf -o Chunk%%%.pdf -chunk 10
|
||||||
|
|
||||||
|
# Split in.pdf on bookmark boundaries, writing each to a file whose
|
||||||
|
# name is the bookmark label
|
||||||
|
cpdf -split-bookmarks 0 in.pdf -o @N.pdf
|
||||||
|
|
||||||
|
# Scale both the dimensions and contents of in.pdf by a factor of two
|
||||||
|
# in x and y directions.
|
||||||
|
cpdf -scale-page "2 2" in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Scale the pages in in.pdf to fit the US Letter page size, writing to
|
||||||
|
# out.pdf
|
||||||
|
cpdf -scale-to-fit usletterportrait in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Shift the contents of the page by 26 pts in the x direction, and 18
|
||||||
|
# millimetres in the y direction, writing to out.pdf
|
||||||
|
cpdf -shift "26pt 18mm" in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Rotate the contents of the pages in in.pdf by ninety degrees and
|
||||||
|
# write to out.pdf.
|
||||||
|
cpdf -rotate-contents 90 in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Crop the pages in in.pdf to a 600 pts by 400 pts rectangle.
|
||||||
|
cpdf -crop "0 0 600pt 400pt" in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Encrypt using 128bit PDF encryption using the owner password 'fred'
|
||||||
|
# and the user password 'joe'
|
||||||
|
cpdf -encrypt 128bit fred joe in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Decrypt using the owner password, writing to out.pdf.
|
||||||
|
cpdf -decrypt in.pdf owner=fred -o out.pdf
|
||||||
|
|
||||||
|
# Compress the data streams in in.pdf, writing the result to out.pdf.
|
||||||
|
cpdf -compress in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Decompress the data streams in in.pdf, writing to out.pdf.
|
||||||
|
cpdf -decompress in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# List the bookmarks in in.pdf. This would produce:
|
||||||
|
cpdf -list-bookmarks in.pdf
|
||||||
|
|
||||||
|
# Outputs:
|
||||||
|
|
||||||
|
# Add bookmarks in the same form from a prepared file bookmarks.txt to
|
||||||
|
# in.pdf, writing to out.pdf.
|
||||||
|
cpdf -add-bookmarks bookmarks.txt in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Use the Split style to build a presentation from the PDF in.pdf,
|
||||||
|
# each slide staying 10 seconds on screen unless manually advanced.
|
||||||
|
# The first page, being a title does not move on automatically, and
|
||||||
|
# has no transition effect.
|
||||||
|
cpdf -presentation in.pdf 2-end -trans Split -duration 10 -o out.pdf
|
||||||
|
|
||||||
|
# Stamp the file watermark.pdf on to each page of in.pdf, writing the
|
||||||
|
# result to out.pdf.
|
||||||
|
cpdf -stamp-on watermark.pdf in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Add a page number and date to all the pages in in.pdf using the
|
||||||
|
# Courier font, writing to out.pdf
|
||||||
|
cpdf -topleft 10 -font Courier -add-text "Page %Page\nDate %d-%m-%Y" in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Two up impose the file in.pdf, writing to out.pdf
|
||||||
|
cpdf -twoup-stack in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Add extra blank pages after pages one, three and four of a document.
|
||||||
|
cpdf -pad-after 1,3,4 in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# List the annotations in a file in.pdf to standard output.
|
||||||
|
cpdf -list-annotations in.pdf
|
||||||
|
|
||||||
|
# Might Produce:
|
||||||
|
|
||||||
|
# -- # Annotation text content 1 # -- # -- # Annotation text content 2
|
||||||
|
# --
|
||||||
|
|
||||||
|
# Copy the annotations from from.pdf to in.pdf, writing to out.pdf.
|
||||||
|
cpdf -copy-annotations from.pdf in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Set the document title of in.pdf. writing to out.pdf.
|
||||||
|
cpdf -set-title "The New Title" in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Set the document in.pdf to open with the Acrobat Viewer's toolbar
|
||||||
|
# hidden, writing to out.pdf.
|
||||||
|
cpdf -hide-toolbar true in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Set the metadata in a PDF in.pdf to the contents of the file
|
||||||
|
# metadata.xml, and write the output to out.pdf.
|
||||||
|
cpdf -set-metadata metadata.xml in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Set the document in.pdf to open in Acrobat Viewer showing two
|
||||||
|
# columns of pages, starting on the right, putting the result in
|
||||||
|
# out.pdf.
|
||||||
|
cpdf -set-page-layout TwoColumnRight in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Set the document in.pdf to open in Acrobat Viewer in full screen
|
||||||
|
# mode, putting the result in out.pdf.
|
||||||
|
cpdf -set-page-mode FullScreen in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Attach the file sheet.xls to in.pdf, writing to out.pdf.
|
||||||
|
cpdf -attach-file sheet.xls in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Remove any attachments from in.pdf, writing to out.pdf.
|
||||||
|
cpdf -remove-files in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Blacken all the text in in.pdf, writing to out.pdf.
|
||||||
|
cpdf -blacktext in.pdf -o out.pdf
|
||||||
|
|
||||||
|
# Make sure all lines in in.pdf are at least 2 pts wide, writing to
|
||||||
|
# out.pdf.
|
||||||
|
cpdf -thinlines 2pt in.pdf -o out.pdf
|
||||||
|
|
@ -14,7 +14,9 @@ SHELL=/bin/bash
|
|||||||
# example entries
|
# example entries
|
||||||
# every 15 min
|
# every 15 min
|
||||||
*/15 * * * * /home/user/command.sh
|
*/15 * * * * /home/user/command.sh
|
||||||
|
|
||||||
# every midnight
|
# every midnight
|
||||||
0 * * * * /home/user/command.sh
|
* 0 * * * /home/user/command.sh
|
||||||
|
|
||||||
# every Saturday at 8:05 AM
|
# every Saturday at 8:05 AM
|
||||||
5 8 * * 6 /home/user/command.sh
|
5 8 * * 6 /home/user/command.sh
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
# Print date in format suitable for affixing to file names
|
# Print date in format suitable for affixing to file names
|
||||||
date +"%Y%m%d_%H%M%S"
|
date +"%Y%m%d_%H%M%S"
|
||||||
|
|
||||||
# Convert Unix timestamp to Date
|
# Convert Unix timestamp to Date(Linux)
|
||||||
date -d @1440359821
|
date -d @1440359821
|
||||||
|
|
||||||
|
# Convert Unix timestamp to Date(Mac)
|
||||||
|
date -r 1440359821
|
||||||
|
@ -17,3 +17,6 @@ dd if=/dev/zero of=/dev/null bs=128M status=progress
|
|||||||
|
|
||||||
# DD with "graphical" return
|
# DD with "graphical" return
|
||||||
dcfldd if=/dev/zero of=/dev/null bs=500K
|
dcfldd if=/dev/zero of=/dev/null bs=500K
|
||||||
|
|
||||||
|
# This will output the sound from your microphone port to the ssh target computer's speaker port. The sound quality is very bad, so you will hear a lot of hissing.
|
||||||
|
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
|
||||||
|
3
cheat/cheatsheets/deb
Normal file
3
cheat/cheatsheets/deb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Extract contents of a .deb file
|
||||||
|
$ ar vx foo.deb # -> data.tar.gz
|
||||||
|
$ tar xf data.tar.gz
|
@ -21,3 +21,6 @@ diff -s version1 version2
|
|||||||
|
|
||||||
# To diff the output of two commands or scripts:
|
# To diff the output of two commands or scripts:
|
||||||
diff <(command1) <(command2)
|
diff <(command1) <(command2)
|
||||||
|
|
||||||
|
# Generate a patch file from two files
|
||||||
|
diff -Naur version1 version2 > version.patch
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
Indent Select text then press TAB
|
Indent Select text then press TAB
|
||||||
Cut CTRL-w
|
Cut CTRL-w
|
||||||
Copy ALT-w
|
Copy ALT-w
|
||||||
Paste CTRL-y
|
Paste ("yank") CTRL-y
|
||||||
Search/Find CTRL-s
|
Search/Find CTRL-s
|
||||||
Replace ALT-% (ALT-SHIFT-5)
|
Replace ALT-% (ALT-SHIFT-5)
|
||||||
Save CTRL-x CTRL-s
|
Save CTRL-x CTRL-s
|
||||||
@ -11,7 +11,7 @@
|
|||||||
Undo CTRL-x u
|
Undo CTRL-x u
|
||||||
Highlight all text CTRL-x h
|
Highlight all text CTRL-x h
|
||||||
Directory listing CTRL-x d
|
Directory listing CTRL-x d
|
||||||
Cancel a command ESC ESC ESC
|
Cancel a command CTRL-g
|
||||||
Font size bigger CTRL-x CTRL-+
|
Font size bigger CTRL-x CTRL-+
|
||||||
Font size smaller CTRL-x CTRL--
|
Font size smaller CTRL-x CTRL--
|
||||||
|
|
||||||
@ -39,32 +39,9 @@
|
|||||||
Compile some code ALT-x compile
|
Compile some code ALT-x compile
|
||||||
List packages ALT-x package-list-packages
|
List packages ALT-x package-list-packages
|
||||||
|
|
||||||
# Sudoing within eshell
|
|
||||||
|
|
||||||
By default when using the sudo command within eshell you'll just
|
|
||||||
get "permission denied" messages. To overcome that type:
|
|
||||||
|
|
||||||
alias sudo '*sudo $*'
|
|
||||||
|
|
||||||
# Line numbers
|
# Line numbers
|
||||||
|
|
||||||
To add line numbers and enable moving to a line with CTRL-l:
|
To add line numbers and enable moving to a line with CTRL-l:
|
||||||
|
|
||||||
(global-set-key "\C-l" 'goto-line)
|
(global-set-key "\C-l" 'goto-line)
|
||||||
(add-hook 'find-file-hook (lambda () (linum-mode 1)))
|
(add-hook 'find-file-hook (lambda () (linum-mode 1)))
|
||||||
|
|
||||||
# Org-mode
|
|
||||||
|
|
||||||
To begin org-mode ALT-x org-mode
|
|
||||||
Table column separator Vertical/pipe character
|
|
||||||
Reorganize table TAB
|
|
||||||
Section heading *
|
|
||||||
Open/collapse section TAB
|
|
||||||
Open/collapse All CTRL-TAB
|
|
||||||
Export in other file formats (eg HTML,PDF) CTRL-c CTRL-e
|
|
||||||
|
|
||||||
To make org-mode automatically wrap lines:
|
|
||||||
|
|
||||||
(add-hook 'org-mode-hook
|
|
||||||
'(lambda ()
|
|
||||||
(visual-line-mode 1)))
|
|
||||||
|
@ -2,7 +2,17 @@
|
|||||||
ffmpeg -i path/to/file.ext
|
ffmpeg -i path/to/file.ext
|
||||||
|
|
||||||
# Convert all m4a files to mp3
|
# Convert all m4a files to mp3
|
||||||
for f in *.m4a; do ffmpeg -i "$f" -acodec libmp3lame -ab 320k "${f%.m4a}.mp3"; done
|
for f in *.m4a; do ffmpeg -i "$f" -acodec libmp3lame -vn -b:a 320k "${f%.m4a}.mp3"; done
|
||||||
|
|
||||||
|
# Convert video from .foo to .bar
|
||||||
|
# -g : GOP, for searchability
|
||||||
|
ffmpeg -i input.foo -vcodec bar -acodec baz -b:v 21000k -b:a 320k -g 150 -threads 4 output.bar
|
||||||
|
|
||||||
|
# Convert image sequence to video
|
||||||
|
ffmpeg -r 18 -pattern_type glob -i '*.png' -b:v 21000k -s hd1080 -vcodec vp9 -an -pix_fmt yuv420p -deinterlace output.ext
|
||||||
|
|
||||||
|
# Combine video and audio into one file
|
||||||
|
ffmpeg -i video.ext -i audio.ext -c:v copy -c:a copy output.ext
|
||||||
|
|
||||||
# Listen to 10 seconds of audio from a video file
|
# Listen to 10 seconds of audio from a video file
|
||||||
#
|
#
|
||||||
@ -10,3 +20,4 @@ for f in *.m4a; do ffmpeg -i "$f" -acodec libmp3lame -ab 320k "${f%.m4a}.mp3"; d
|
|||||||
# -t : seconds to cut
|
# -t : seconds to cut
|
||||||
# -autoexit : closes ffplay as soon as the audio finishes
|
# -autoexit : closes ffplay as soon as the audio finishes
|
||||||
ffmpeg -ss 00:34:24.85 -t 10 -i path/to/file.mp4 -f mp3 pipe:play | ffplay -i pipe:play -autoexit
|
ffmpeg -ss 00:34:24.85 -t 10 -i path/to/file.mp4 -f mp3 pipe:play | ffplay -i pipe:play -autoexit
|
||||||
|
|
||||||
|
@ -11,6 +11,24 @@ git config --global color.ui true
|
|||||||
# To stage all changes for commit:
|
# To stage all changes for commit:
|
||||||
git add --all
|
git add --all
|
||||||
|
|
||||||
|
# To stash changes locally, this will keep the changes in a separate changelist
|
||||||
|
# called stash and the working directory is cleaned. You can apply changes
|
||||||
|
# from the stash anytime
|
||||||
|
git stash
|
||||||
|
|
||||||
|
# To stash changes with a message
|
||||||
|
git stash save "message"
|
||||||
|
|
||||||
|
# To list all the stashed changes
|
||||||
|
git stash list
|
||||||
|
|
||||||
|
# To apply the most recent change and remove the stash from the stash list
|
||||||
|
git stash pop
|
||||||
|
|
||||||
|
# To apply any stash from the list of stashes. This does not remove the stash
|
||||||
|
# from the stash list
|
||||||
|
git stash apply stash@{6}
|
||||||
|
|
||||||
# To commit staged changes
|
# To commit staged changes
|
||||||
git commit -m "Your commit message"
|
git commit -m "Your commit message"
|
||||||
|
|
||||||
@ -104,3 +122,30 @@ git clone --depth 1 <remote-url>
|
|||||||
|
|
||||||
# To unshallow a clone
|
# To unshallow a clone
|
||||||
git pull --unshallow
|
git pull --unshallow
|
||||||
|
|
||||||
|
# Create a bare branch (one that has no commits on it)
|
||||||
|
git checkout --orphan branch_name
|
||||||
|
|
||||||
|
# Checkout a new branch from a different starting point
|
||||||
|
git checkout -b master upstream/master
|
||||||
|
|
||||||
|
# Remove all stale branches (ones that have been deleted on remote)
|
||||||
|
# So if you have a lot of useless branches, delete them on Github and then run this
|
||||||
|
git remote prune origin
|
||||||
|
|
||||||
|
# The following can be used to prune all remotes at once
|
||||||
|
git remote prune $(git remote | tr '\n' ' ')
|
||||||
|
|
||||||
|
# Revisions can also be identified with :/text
|
||||||
|
# So, this will show the first commit that has "cool" in their message body
|
||||||
|
git show :/cool
|
||||||
|
|
||||||
|
# Undo parts of last commit in a specific file
|
||||||
|
git checkout -p HEAD^ -- /path/to/file
|
||||||
|
|
||||||
|
# Revert a commit and keep the history of the reverted change as a separate revert commit
|
||||||
|
git revert <commit SHA>
|
||||||
|
|
||||||
|
# Pich a commit from a branch to current branch. This is different than merge as
|
||||||
|
# this just applies a single commit from a branch to current branch
|
||||||
|
git cherry-pick <commit SHA1>
|
||||||
|
20
cheat/cheatsheets/hg
Normal file
20
cheat/cheatsheets/hg
Normal 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
|
@ -1,2 +1,9 @@
|
|||||||
# To disable the terminal refresh when exiting
|
# To disable the terminal refresh when exiting
|
||||||
less -X
|
less -X
|
||||||
|
|
||||||
|
# To save the contents to a file
|
||||||
|
# Method 1 - Only works when the input is a pipe
|
||||||
|
s <filename>
|
||||||
|
|
||||||
|
# Method 2 - This should work whether input is a pipe or an ordinary file.
|
||||||
|
Type g or < (g or less-than) | $ (pipe then dollar) then cat > <filename> and Enter.
|
||||||
|
@ -4,20 +4,34 @@ sudo lsof -i4
|
|||||||
# List all IPv6 network files
|
# List all IPv6 network files
|
||||||
sudo lsof -i6
|
sudo lsof -i6
|
||||||
|
|
||||||
# To find listening ports:
|
# List all open sockets
|
||||||
|
lsof -i
|
||||||
|
|
||||||
|
# List all listening ports
|
||||||
lsof -Pnl +M -i4
|
lsof -Pnl +M -i4
|
||||||
|
|
||||||
# To find which program is using the port 80:
|
# Find which program is using the port 80
|
||||||
lsof -i TCP:80
|
lsof -i TCP:80
|
||||||
|
|
||||||
|
# List all connections to a specific host
|
||||||
|
lsof -i@192.168.1.5
|
||||||
|
|
||||||
# List all processes accessing a particular file/directory
|
# List all processes accessing a particular file/directory
|
||||||
lsof </path/to/file>
|
lsof </path/to/file>
|
||||||
|
|
||||||
# List all files open for a particular user
|
# List all files open for a particular user
|
||||||
lsof -u <username>
|
lsof -u <username>
|
||||||
|
|
||||||
# List all files/network connections a given process is using
|
# List all files/network connections a command is using
|
||||||
lsof -c <command-name>
|
lsof -c <command-name>
|
||||||
|
|
||||||
|
# List all files a process has open
|
||||||
|
lsof -p <pid>
|
||||||
|
|
||||||
|
# List all files open mounted at /mount/point.
|
||||||
|
# Particularly useful for finding which process(es) are using a
|
||||||
|
# mounted USB stick or CD/DVD.
|
||||||
|
lsof +f -- </mount/point>
|
||||||
|
|
||||||
# See this primer: http://www.danielmiessler.com/study/lsof/
|
# See this primer: http://www.danielmiessler.com/study/lsof/
|
||||||
# for a number of other useful lsof tips
|
# for a number of other useful lsof tips
|
||||||
|
11
cheat/cheatsheets/ncdu
Normal file
11
cheat/cheatsheets/ncdu
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Save results to file
|
||||||
|
ncdu -o ncdu.file
|
||||||
|
|
||||||
|
# Read from file
|
||||||
|
ncdu -f ncdu.file
|
||||||
|
|
||||||
|
# Save results to compressed file
|
||||||
|
ncdu -o-| gzip > ncdu.file.gz
|
||||||
|
|
||||||
|
# Read from compressed file
|
||||||
|
zcat ncdu.file.gz | ncdu -f-
|
22
cheat/cheatsheets/npm
Normal file
22
cheat/cheatsheets/npm
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Every command shown here can be used with the `-g` switch for global scope
|
||||||
|
|
||||||
|
# Install a package in the current directory
|
||||||
|
npm install <package>
|
||||||
|
|
||||||
|
# Install a package, and save it in the `dependencies` section of `package.json`
|
||||||
|
npm install --save <package>
|
||||||
|
|
||||||
|
# Install a package, and save it in the `devDependencies` section of `package.json`
|
||||||
|
npm install --save-dev <package>
|
||||||
|
|
||||||
|
# Show outdated packages in the current directory
|
||||||
|
npm outdated
|
||||||
|
|
||||||
|
# Update outdated packages
|
||||||
|
npm update
|
||||||
|
|
||||||
|
# Update `npm` (will override the one shipped with Node.js)
|
||||||
|
npm install -g npm
|
||||||
|
|
||||||
|
# Uninstall a package
|
||||||
|
npm uninstall <package>
|
46
cheat/cheatsheets/org-mode
Normal file
46
cheat/cheatsheets/org-mode
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
Begin org-mode ALT-x org-mode
|
||||||
|
Save CTRL-x CTRL-s
|
||||||
|
Export in other file formats (eg HTML,PDF) CTRL-c CTRL-e
|
||||||
|
|
||||||
|
# Outline
|
||||||
|
|
||||||
|
Section heading *
|
||||||
|
New headline ALT-return
|
||||||
|
Move headline up or down ALT-up_arrow/down_arrow
|
||||||
|
Adjust indent depth of headline ALT-left_arrow/right_arrow
|
||||||
|
Open/collapse section TAB
|
||||||
|
Open/collapse All CTRL-TAB
|
||||||
|
|
||||||
|
# To-Do Lists
|
||||||
|
|
||||||
|
Mark list item as TODO ** TODO
|
||||||
|
Cycle through workflow SHIFT-left_arrow/right_arrow
|
||||||
|
Show only outstanding TODO items CTRL-c CTRL-v
|
||||||
|
|
||||||
|
# Tables
|
||||||
|
|
||||||
|
Table column separator Vertical/pipe character
|
||||||
|
Reorganize table TAB
|
||||||
|
Move column ALT-left_arrow/right_arrow
|
||||||
|
Move row ALT-up_arrow/down_arrow
|
||||||
|
|
||||||
|
# Styles
|
||||||
|
|
||||||
|
*bold*
|
||||||
|
/italic/
|
||||||
|
_underlined_
|
||||||
|
=code=
|
||||||
|
~verbatim~
|
||||||
|
+strike-through+
|
||||||
|
|
||||||
|
# Heading
|
||||||
|
|
||||||
|
Header -*- mode: org -*-
|
||||||
|
|
||||||
|
# .emacs
|
||||||
|
|
||||||
|
To make org-mode automatically wrap lines:
|
||||||
|
|
||||||
|
(add-hook 'org-mode-hook
|
||||||
|
'(lambda ()
|
||||||
|
(visual-line-mode 1)))
|
13
cheat/cheatsheets/patch
Normal file
13
cheat/cheatsheets/patch
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Patch one file
|
||||||
|
patch version1 < version.patch
|
||||||
|
|
||||||
|
# Reverse a patch
|
||||||
|
patch -R version1 < version.patch
|
||||||
|
|
||||||
|
# Patch all files in a directory, adding any missing new files
|
||||||
|
# -p strips leading slashes
|
||||||
|
$ cd dir
|
||||||
|
$ patch -p1 -i ../big.patch
|
||||||
|
|
||||||
|
# Patch files in a directory, with one level (/) offset
|
||||||
|
patch -p1 -r version1/ < version.patch
|
27
cheat/cheatsheets/pkgtools
Normal file
27
cheat/cheatsheets/pkgtools
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Create a Slackware package from a structured directory and sub-tree
|
||||||
|
$ cd /path/to/pkg/dir
|
||||||
|
$ su - c 'makepkg --linkadd y --chown n $foo-1.0.3-x86_64-1_tag.tgz'
|
||||||
|
|
||||||
|
|
||||||
|
# Install a Slackware package
|
||||||
|
installpkg foo-1.0.3-x86_64-1.tgz
|
||||||
|
|
||||||
|
# Install a Slackware package to non-standard location
|
||||||
|
ROOT=/path/to/dir installpkg foo-1.0.4-noarch-1.tgz
|
||||||
|
|
||||||
|
# Create backup of files that will be overwritten when installing
|
||||||
|
tar czvf /tmp/backup.tar.gz $(installpkg --warn foo-1.0.4-noarch-1.tgz)
|
||||||
|
|
||||||
|
|
||||||
|
# Upgrade a Slackware package including files only in new version
|
||||||
|
upgradepkg --install-new foo-1.0.6-noarch-1.tgz
|
||||||
|
|
||||||
|
# Upgrade a Slackware package even if version is the same
|
||||||
|
upgradepkg --reinstall foo-1.0.4-noarch-1.tgz
|
||||||
|
|
||||||
|
|
||||||
|
# Remove a Slackware package
|
||||||
|
removepkg foo-0.2.8-x86_64-1
|
||||||
|
|
||||||
|
# Remove a Slackware package, retaining a backup (uninstalled) copy
|
||||||
|
removepkg -copy foo-0.2.8-x86_64-1 # -> /var/log/setup/tmp/preserved_packages/foo...
|
2
cheat/cheatsheets/popd
Normal file
2
cheat/cheatsheets/popd
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Returns to the directory at the top of the `pushd' stack
|
||||||
|
popd
|
5
cheat/cheatsheets/pushd
Normal file
5
cheat/cheatsheets/pushd
Normal 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
|
5
cheat/cheatsheets/rpm2cpio
Normal file
5
cheat/cheatsheets/rpm2cpio
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# List contents of RPM
|
||||||
|
rpm2cpio foo.rpm | cpio -vt
|
||||||
|
|
||||||
|
# Extract contents of RPM
|
||||||
|
rpm2cpio foo.rpm | cpio -vid
|
8
cheat/cheatsheets/shutdown
Normal file
8
cheat/cheatsheets/shutdown
Normal 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
|
32
cheat/cheatsheets/sport
Normal file
32
cheat/cheatsheets/sport
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Sync to newest SlackBuild.org tree
|
||||||
|
sport r
|
||||||
|
|
||||||
|
# Search (fuzzy) SlackBuild tree for packages foo and BaR
|
||||||
|
sport s foo bar
|
||||||
|
|
||||||
|
# Operate from alternate build tree
|
||||||
|
SBOPATH=/path/to/tree sport s foo
|
||||||
|
|
||||||
|
# View info and README of BaR (not fuzzy)
|
||||||
|
sport c foo BaR
|
||||||
|
|
||||||
|
# Build a package
|
||||||
|
sport i --build-only foo
|
||||||
|
|
||||||
|
# Build and install package foo and BaR
|
||||||
|
sport i foo BaR
|
||||||
|
|
||||||
|
# Build and install package from current directory
|
||||||
|
sport i .
|
||||||
|
|
||||||
|
# Upgrade instead of install
|
||||||
|
INSTALLER=upgradepkg sport i foo
|
||||||
|
|
||||||
|
# Build dependency list for baz
|
||||||
|
echo "foo BaR" >> /tmp/baz.list
|
||||||
|
|
||||||
|
# Install list of packages from file
|
||||||
|
sport i $(< /tmp/baz.list)
|
||||||
|
|
||||||
|
# Check if package is installed
|
||||||
|
sport k foo
|
20
cheat/cheatsheets/sqlite3
Normal file
20
cheat/cheatsheets/sqlite3
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# create database and launch interactive shell
|
||||||
|
sqlite3 example.db
|
||||||
|
|
||||||
|
# create table
|
||||||
|
sqlite3 example.db "CREATE TABLE Os(ID INTEGER PRIMARY KEY, Name TEXT, Year INTEGER);"
|
||||||
|
|
||||||
|
# insert data
|
||||||
|
sqlite3 example.db "INSERT INTO 'Os' VALUES(1,'Linux',1991);"
|
||||||
|
|
||||||
|
# list tables
|
||||||
|
sqlite3 example.db ".tables"
|
||||||
|
|
||||||
|
# view records in table
|
||||||
|
sqlite3 example.db "SELECT * FROM 'Os';"
|
||||||
|
|
||||||
|
# view records in table conditionally
|
||||||
|
sqlite example.db "SELECT * FROM 'Os' WHERE Year='1991';"
|
||||||
|
|
||||||
|
# view records with fuzzy matching
|
||||||
|
sqlite3 ~/example.db "SELECT * FROM 'Os' WHERE Year like '19%';"
|
@ -32,3 +32,12 @@ ssh user@example.com -C -c blowfish -X
|
|||||||
# Copy files and folders through ssh from remote host to pwd with tar.gz compression
|
# Copy files and folders through ssh from remote host to pwd with tar.gz compression
|
||||||
# when there is no rsync command available
|
# when there is no rsync command available
|
||||||
ssh user@example.com "cd /var/www/Shared/; tar zcf - asset1 asset2" | tar zxf -
|
ssh user@example.com "cd /var/www/Shared/; tar zcf - asset1 asset2" | tar zxf -
|
||||||
|
|
||||||
|
# Mount folder/filesystem through SSH
|
||||||
|
# Install SSHFS from https://github.com/libfuse/sshfs
|
||||||
|
# Will allow you to mount a folder securely over a network.
|
||||||
|
sshfs name@server:/path/to/folder /path/to/mount/point
|
||||||
|
|
||||||
|
# Emacs can read file through SSH
|
||||||
|
# Doc: http://www.gnu.org/software/emacs/manual/html_node/emacs/Remote-Files.html
|
||||||
|
emacs /ssh:name@server:/path/to/file
|
||||||
|
2
cheat/cheatsheets/su
Normal file
2
cheat/cheatsheets/su
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Switch to another user account
|
||||||
|
su USERNAME
|
20
cheat/cheatsheets/svn
Normal file
20
cheat/cheatsheets/svn
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# update working copy from repository
|
||||||
|
svn update "/path"
|
||||||
|
|
||||||
|
# show changed files in working copy
|
||||||
|
svn status
|
||||||
|
|
||||||
|
# show what changed in local file
|
||||||
|
svn diff "/path/filename"
|
||||||
|
|
||||||
|
# add files or folders
|
||||||
|
svn add "path/item"
|
||||||
|
|
||||||
|
# revert local uncommited changes
|
||||||
|
svn revert "/path/file"
|
||||||
|
|
||||||
|
# commit changes to repo
|
||||||
|
svn commit -m "message" "/path"
|
||||||
|
|
||||||
|
# show help for 'svn diff'
|
||||||
|
svn help diff
|
14
cheat/cheatsheets/trashy
Normal file
14
cheat/cheatsheets/trashy
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Trash foo and bar
|
||||||
|
trash foo bar
|
||||||
|
|
||||||
|
# Trash "foo bar"
|
||||||
|
trash foo\ bar
|
||||||
|
|
||||||
|
# List files in trash
|
||||||
|
trash -v --list
|
||||||
|
|
||||||
|
# Restore foo from trash
|
||||||
|
trash --restore foo
|
||||||
|
|
||||||
|
# Empty trash
|
||||||
|
trash --empty
|
14
cheat/cheatsheets/urpm
Normal file
14
cheat/cheatsheets/urpm
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# search (fuzzy) for package foo
|
||||||
|
urpmq -Y foo
|
||||||
|
|
||||||
|
# check if foo is installed
|
||||||
|
rpm -q foo
|
||||||
|
|
||||||
|
# install package foo
|
||||||
|
urpmi foo
|
||||||
|
|
||||||
|
# download but don't install foo
|
||||||
|
urpmi --no-install foo
|
||||||
|
|
||||||
|
# uninstall package foo
|
||||||
|
urpme foo
|
14
cheat/cheatsheets/xmlto
Normal file
14
cheat/cheatsheets/xmlto
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# DocBook XML to PDF
|
||||||
|
xmlto pdf mydoc.xml
|
||||||
|
|
||||||
|
# DocBook XML to HTML
|
||||||
|
xmlto -o html-dir html mydoc.xml
|
||||||
|
|
||||||
|
# DocBook XML to single HTML file
|
||||||
|
xmlto html-nochunks mydoc.xml
|
||||||
|
|
||||||
|
# modify output with XSL override
|
||||||
|
xmlto -m ulink.xsl pdf mydoc.xml
|
||||||
|
|
||||||
|
# use non-default xsl
|
||||||
|
xmlto -x mystylesheet.xsl pdf mydoc.xml
|
8
cheat/cheatsheets/xxd
Normal file
8
cheat/cheatsheets/xxd
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Convert bin/string to hex.
|
||||||
|
# Result: 34322069732074686520736f6c7574696f6e0a
|
||||||
|
echo '42 is the solution' | xxd -p
|
||||||
|
|
||||||
|
# Convert hex to bin/string.
|
||||||
|
# Result: 42 is the solution
|
||||||
|
echo '34322069732074686520736f6c7574696f6e0a' | xxd -r -p
|
||||||
|
|
@ -1,10 +1,8 @@
|
|||||||
from cheat import sheets
|
|
||||||
from cheat import utils
|
|
||||||
from cheat.utils import *
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
from cheat import sheets
|
||||||
|
from cheat.utils import die, open_with_editor
|
||||||
|
|
||||||
def copy(current_sheet_path, new_sheet_path):
|
def copy(current_sheet_path, new_sheet_path):
|
||||||
""" Copies a sheet to a new path """
|
""" Copies a sheet to a new path """
|
||||||
@ -16,7 +14,7 @@ def copy(current_sheet_path, new_sheet_path):
|
|||||||
# fail gracefully if the cheatsheet cannot be copied. This can happen if
|
# fail gracefully if the cheatsheet cannot be copied. This can happen if
|
||||||
# DEFAULT_CHEAT_DIR does not exist
|
# DEFAULT_CHEAT_DIR does not exist
|
||||||
except IOError:
|
except IOError:
|
||||||
die ('Could not copy cheatsheet for editing.')
|
die('Could not copy cheatsheet for editing.')
|
||||||
|
|
||||||
|
|
||||||
def create_or_edit(sheet):
|
def create_or_edit(sheet):
|
||||||
@ -40,22 +38,12 @@ def create_or_edit(sheet):
|
|||||||
def create(sheet):
|
def create(sheet):
|
||||||
""" Creates a cheatsheet """
|
""" Creates a cheatsheet """
|
||||||
new_sheet_path = os.path.join(sheets.default_path(), sheet)
|
new_sheet_path = os.path.join(sheets.default_path(), sheet)
|
||||||
|
open_with_editor(new_sheet_path)
|
||||||
try:
|
|
||||||
subprocess.call([editor(), new_sheet_path])
|
|
||||||
|
|
||||||
except OSError:
|
|
||||||
die('Could not launch ' + editor())
|
|
||||||
|
|
||||||
|
|
||||||
def edit(sheet):
|
def edit(sheet):
|
||||||
""" Opens a cheatsheet for editing """
|
""" Opens a cheatsheet for editing """
|
||||||
|
open_with_editor(path(sheet))
|
||||||
try:
|
|
||||||
subprocess.call([editor(), path(sheet)])
|
|
||||||
|
|
||||||
except OSError:
|
|
||||||
die('Could not launch ' + editor())
|
|
||||||
|
|
||||||
|
|
||||||
def exists(sheet):
|
def exists(sheet):
|
||||||
@ -84,5 +72,5 @@ def read(sheet):
|
|||||||
if not exists(sheet):
|
if not exists(sheet):
|
||||||
die('No cheatsheet found for ' + sheet)
|
die('No cheatsheet found for ' + sheet)
|
||||||
|
|
||||||
with open (path(sheet)) as cheatfile:
|
with open(path(sheet)) as cheatfile:
|
||||||
return cheatfile.read()
|
return cheatfile.read()
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
from cheat import cheatsheets
|
|
||||||
from cheat.utils import *
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from cheat import cheatsheets
|
||||||
|
from cheat.utils import die
|
||||||
|
|
||||||
def default_path():
|
def default_path():
|
||||||
""" Returns the default cheatsheet path """
|
""" Returns the default cheatsheet path """
|
||||||
|
|
||||||
# determine the default cheatsheet dir
|
# determine the default cheatsheet dir
|
||||||
default_sheets_dir = os.environ.get('DEFAULT_CHEAT_DIR') or os.path.join(os.path.expanduser('~'), '.cheat')
|
default_sheets_dir = os.environ.get('DEFAULT_CHEAT_DIR') or os.path.join('~', '.cheat')
|
||||||
|
default_sheets_dir = os.path.expanduser(os.path.expandvars(default_sheets_dir))
|
||||||
|
|
||||||
# create the DEFAULT_CHEAT_DIR if it does not exist
|
# create the DEFAULT_CHEAT_DIR if it does not exist
|
||||||
if not os.path.isdir(default_sheets_dir):
|
if not os.path.isdir(default_sheets_dir):
|
||||||
@ -22,7 +24,7 @@ def default_path():
|
|||||||
if not os.access(default_sheets_dir, os.R_OK):
|
if not os.access(default_sheets_dir, os.R_OK):
|
||||||
die('The DEFAULT_CHEAT_DIR (' + default_sheets_dir +') is not readable.')
|
die('The DEFAULT_CHEAT_DIR (' + default_sheets_dir +') is not readable.')
|
||||||
if not os.access(default_sheets_dir, os.W_OK):
|
if not os.access(default_sheets_dir, os.W_OK):
|
||||||
die('The DEFAULT_CHEAT_DIR (' + default_sheets_dir +') is not writeable.')
|
die('The DEFAULT_CHEAT_DIR (' + default_sheets_dir +') is not writable.')
|
||||||
|
|
||||||
# return the default dir
|
# return the default dir
|
||||||
return default_sheets_dir
|
return default_sheets_dir
|
||||||
@ -81,10 +83,10 @@ def search(term):
|
|||||||
for cheatsheet in sorted(get().items()):
|
for cheatsheet in sorted(get().items()):
|
||||||
match = ''
|
match = ''
|
||||||
for line in open(cheatsheet[1]):
|
for line in open(cheatsheet[1]):
|
||||||
if term in line:
|
if term in line:
|
||||||
match += ' ' + line
|
match += ' ' + line
|
||||||
|
|
||||||
if not match == '':
|
if match != '':
|
||||||
result += cheatsheet[0] + ":\n" + match + "\n"
|
result += cheatsheet[0] + ":\n" + match + "\n"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def colorize(sheet_content):
|
def colorize(sheet_content):
|
||||||
@ -12,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):
|
||||||
@ -30,34 +40,30 @@ def die(message):
|
|||||||
|
|
||||||
def editor():
|
def editor():
|
||||||
""" Determines the user's preferred editor """
|
""" Determines the user's preferred editor """
|
||||||
if 'EDITOR' not in os.environ:
|
|
||||||
|
# determine which editor to use
|
||||||
|
editor = os.environ.get('CHEAT_EDITOR') \
|
||||||
|
or os.environ.get('VISUAL') \
|
||||||
|
or os.environ.get('EDITOR') \
|
||||||
|
or False
|
||||||
|
|
||||||
|
# assert that the editor is set
|
||||||
|
if editor == False:
|
||||||
die(
|
die(
|
||||||
'In order to create/edit a cheatsheet you must set your EDITOR '
|
'You must set a CHEAT_EDITOR, VISUAL, or EDITOR environment '
|
||||||
'environment variable to your editor\'s path.'
|
'variable in order to create/edit a cheatsheet.'
|
||||||
)
|
)
|
||||||
|
|
||||||
elif os.environ['EDITOR'] == "":
|
return editor
|
||||||
die(
|
|
||||||
'Your EDITOR environment variable is set to an empty string. It must '
|
|
||||||
'be set to your editor\'s path.'
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
|
||||||
return os.environ['EDITOR']
|
|
||||||
|
|
||||||
|
|
||||||
def prompt_yes_or_no(question):
|
def open_with_editor(filepath):
|
||||||
""" Prompts the user with a yes-or-no question """
|
""" Open `filepath` using the EDITOR specified by the environment variables """
|
||||||
# Support Python 2 and 3 input
|
editor_cmd = editor().split()
|
||||||
# Default to Python 2's input()
|
try:
|
||||||
get_input = raw_input
|
subprocess.call(editor_cmd + [filepath])
|
||||||
|
except OSError:
|
||||||
# If this is Python 3, use input()
|
die('Could not launch ' + editor())
|
||||||
if sys.version_info[:2] >= (3, 0):
|
|
||||||
get_input = input
|
|
||||||
|
|
||||||
print(question)
|
|
||||||
return get_input('[y/n] ') == 'y'
|
|
||||||
|
|
||||||
|
|
||||||
def warn(message):
|
def warn(message):
|
||||||
|
BIN
man1/cheat.1.gz
Normal file
BIN
man1/cheat.1.gz
Normal file
Binary file not shown.
2
setup.py
2
setup.py
@ -3,7 +3,7 @@ import os
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = 'cheat',
|
name = 'cheat',
|
||||||
version = '2.1.24',
|
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',
|
||||||
|
Reference in New Issue
Block a user