Compare commits

...

32 Commits

Author SHA1 Message Date
Chris Lane
8cad76943a v2.1.27
`patch` version bump.
2016-11-27 11:10:05 -05:00
Romanos Skiadas
a6ec02c296 Support multi-word EDITOR values
When the value of EDITOR was more than one words (e.g. emacsclient -c),
it wasn't properly split in an array for subprocess.call and cheat would
fail to launch it.
This commit fixes that.

Closes #301
2016-11-27 10:53:10 -05:00
Chris Lane
7392787e31 Merge branch 'patch-1' of https://github.com/brutus/cheat into brutus-patch-1 2016-11-27 10:42:46 -05:00
Chris Lane
208dd24a0c Minor cheatsheet edits. 2016-11-27 10:31:49 -05:00
Chris Lane
df34774a7a Merge branch 'master' of https://github.com/notklaatu/cheat into notklaatu-master 2016-11-27 08:57:54 -05:00
Chris Lane
8d65424ffb README edit
Modified the README with regards to the environment variable changes
made in #294.
2016-11-27 08:54:33 -05:00
Chris Lane
597acec6ac cheat now honors CHEAT_EDITOR and VISUAL environment variables in
addition to `EDITOR`.
2016-11-27 08:54:33 -05:00
Chris Allen Lane
7d4150b937 Merge pull request #291 from proinsias/patch-1
Create MANIFEST.in
2016-11-27 08:53:45 -05:00
Chris Allen Lane
5df5b1ab49 Merge pull request #299 from jonlabelle/patch-1
Fix uninstall typo.
2016-11-27 08:46:55 -05:00
Chris Allen Lane
f1c8017342 Merge pull request #304 from dufferzafar/sheets
Add aria2c sheet
2016-11-27 08:45:50 -05:00
Brutus
05400a92ed Added support for ~ and environment variables in DEFAULT_CHEAT_DIR
If the `DEFAULT_CHEAT_DIR` environment variable contains the `~` — as shortcut for the users home directory — or environment variables like `$HOME`, the program bails. This change allows the usage of both.
2016-11-24 16:14:37 +01:00
Shadab Zafar
034c1a2415 Add aria2c sheet 2016-10-15 00:02:45 +05:30
Jon LaBelle
dab8645394 Fix uninstall type. 2016-10-02 16:23:42 -05:00
Chris Lane
403d715127 Merge pull request #292 from rahulkavale/master
Add stash, cherry-pick, revert in git cheat
2016-09-30 20:40:20 -04:00
Chris Lane
0edd1450dc Merge pull request #293 from nagromc/npm-cheat
Add npm cheatsheet
2016-09-30 20:38:15 -04:00
Chris Lane
d87a26ce4f Merge pull request #297 from dufferzafar/sheets
Update lsof sheet
2016-09-30 20:37:20 -04:00
Shadab Zafar
cdf240b70e Fix grammar of lsof 2016-09-27 22:43:54 +05:30
Shadab Zafar
809c6d77bc Update lsof sheet 2016-09-27 21:23:39 +05:30
Klaatu
be543450c7 Merge branch 'master' of github.com:notklaatu/cheat 2016-09-21 22:25:27 +12:00
Klaatu
9889d77adb xmlto cheatsheet 2016-09-21 22:24:47 +12:00
Klaatu
354376340f Missing man page #272 2016-09-10 14:17:01 +12:00
Morgan Courbet
d82eee726c Add npm cheatsheet 2016-09-09 10:05:22 +02:00
Klaatu
9a23458a2d ffmpeg combine, add sqlite3 2016-09-09 12:05:08 +12:00
Klaatu
32802c2907 patch cheat 2016-09-04 09:48:01 +12:00
Klaatu
2a6d34de35 diff addition 2016-09-02 09:44:19 +12:00
Klaatu
f1253031f2 bzip2 2016-09-01 22:28:28 +12:00
Klaatu
76fa9cfc23 urpm* mageia open mandriva 2016-09-01 22:01:01 +12:00
Klaatu
0a54b2a2ff updated emacs, ffmpeg. branched org-mode. added slack. 2016-09-01 12:10:21 +12:00
rahul
6a1742984c Add cheery-pick to git cheat 2016-08-28 08:26:55 +05:30
rahul
80d2a09456 Add revert in git cheat 2016-08-28 08:19:20 +05:30
rahul
5121fece91 Add git stash cheat 2016-08-28 08:13:08 +05:30
Francis T. O'Donovan
e8d32102cb Create MANIFEST.in
I'm working on submitting this package to conda-forge. As part of this, I would like to include the license files in the MANIFEST.in for this project.
2016-08-25 20:31:13 -04:00
26 changed files with 329 additions and 58 deletions

6
MANIFEST.in Normal file
View File

@@ -0,0 +1,6 @@
include CHANGELOG
include CONTRIBUTING.md
include LICENSE
include README.md
include licenses/gpl-3.txt
include licenses/mit.txt

View File

@@ -67,8 +67,8 @@ 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

View File

@@ -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.26') options = docopt(__doc__, version='cheat 2.1.27')
# list directories # list directories
if options['--directories']: if options['--directories']:

12
cheat/cheatsheets/aria2c Normal file
View 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
View 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

3
cheat/cheatsheets/deb Normal file
View File

@@ -0,0 +1,3 @@
# Extract contents of a .deb file
$ ar vx foo.deb # -> data.tar.gz
$ tar xf data.tar.gz

View File

@@ -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

View File

@@ -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)))

View File

@@ -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

View File

@@ -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"
@@ -124,3 +142,10 @@ git show :/cool
# Undo parts of last commit in a specific file # Undo parts of last commit in a specific file
git checkout -p HEAD^ -- /path/to/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>

View File

@@ -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

22
cheat/cheatsheets/npm Normal file
View 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>

View 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
View 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

View 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...

View File

@@ -0,0 +1,5 @@
# List contents of RPM
rpm2cpio foo.rpm | cpio -vt
# Extract contents of RPM
rpm2cpio foo.rpm | cpio -vid

32
cheat/cheatsheets/sport Normal file
View 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
View 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%';"

14
cheat/cheatsheets/trashy Normal file
View 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
View 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
View 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

View File

@@ -1,9 +1,8 @@
import os import os
import shutil import shutil
import subprocess
from cheat import sheets from cheat import sheets
from cheat.utils import die, editor 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 """
@@ -39,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):

View File

@@ -7,7 +7,8 @@ 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):

View File

@@ -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):
@@ -30,20 +31,31 @@ 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.' def open_with_editor(filepath):
) """ Open `filepath` using the EDITOR specified by the environment variables """
editor_cmd = editor().split()
try:
subprocess.call(editor_cmd + [filepath])
except OSError:
die('Could not launch ' + editor())
else:
return os.environ['EDITOR']
def warn(message): def warn(message):
""" Prints a message to stderr """ """ Prints a message to stderr """

BIN
man1/cheat.1.gz Normal file

Binary file not shown.

View File

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