Compare commits

...

27 Commits
2.1.3 ... 2.1.7

Author SHA1 Message Date
e9b8f04c24 Bug fix
A bug was introduced in 2.1.6 that would prevent user-defined
cheatsheets from being edited more than once.
2015-02-11 21:45:32 -05:00
d14c759a48 Merge pull request #210 from chrisallenlane/issue-180
Issue #180
2015-02-11 21:05:12 -05:00
c70dc002fa Issue #180
Now, whenever a cheatsheet is to be edited, if that cheatsheet does not
exist on the `DEFAULT_SHEET_PATH`, it is first copied there before being
opened for editing. This prevents system-wide cheatsheets from being
edited when using `cheat` as `root`.
2015-02-11 21:02:45 -05:00
ff8ba4e717 Merge pull request #209 from chrisallenlane/edit-after-copy
Resolves #207
2015-02-10 19:37:05 -05:00
718ec4f685 Resolves #207
- Solves issue whereby global cheatsheets fail to save after editing

- `cheat` no longer asks a user if a global cheatsheet should be copied
  locally before editing, and instead just silently does so.
2015-02-10 19:35:14 -05:00
3d8343a878 Version bump 2015-02-09 18:10:08 -05:00
a5352ad9e5 Trivial edits to uniq cheatsheet 2015-02-09 18:07:17 -05:00
f5ee3d5e29 Merge branch 'master' of https://github.com/shigemk2/cheat into shigemk2-master
* 'master' of https://github.com/shigemk2/cheat:
  Refer sort -u
  Fix dc option
  uniq: add examples
2015-02-09 18:06:20 -05:00
e64babc972 Trivial edits to cheatsheets. 2015-02-09 18:05:13 -05:00
cd465ef84f Merge branch 'master' of https://github.com/Aayush-Kasurde/cheat into Aayush-Kasurde-master
* 'master' of https://github.com/Aayush-Kasurde/cheat:
  Added perforce commands
  Added udisksctl
  Added Journalctl commands
  Added zoneadm commands
2015-02-09 18:03:28 -05:00
96e26a38d4 Added newline to end of dnf file. 2015-02-09 18:01:40 -05:00
998ed00424 Merge branch 'dnf' of https://github.com/amitsaha/cheat into amitsaha-dnf
* 'dnf' of https://github.com/amitsaha/cheat:
  Add cheatsheet for dnf
2015-02-09 18:00:38 -05:00
1fd03d3305 Merge pull request #205 from thylong/dpkg
Add cheat for dpkg
2015-02-09 17:58:24 -05:00
77cba58599 Merge pull request #203 from amitsaha/docker_update
docker: add 'docker exec'
2015-02-09 17:57:39 -05:00
c5a738a8b1 Merge pull request #199 from Mic92/patch-8
ip: better route example
2015-02-09 17:56:57 -05:00
250a265b25 Added perforce commands 2015-01-27 22:07:43 +05:30
c232721119 Add cheatsheet for dnf 2015-01-22 16:30:49 +10:00
55492c50ac Added udisksctl 2015-01-20 21:34:11 +05:30
d9df28e3f2 Update dpkg 2015-01-20 12:22:47 +01:00
710c7bcf70 Add cheat for dpkg 2015-01-20 01:42:26 +01:00
efba736aee Added Journalctl commands 2015-01-18 20:03:42 +05:30
95774db7c5 Added zoneadm commands 2015-01-14 21:12:23 +05:30
da63c5d27f docker: add 'docker exec' 2015-01-13 13:51:35 +10:00
2e1cda114a Refer sort -u 2015-01-12 21:29:35 +09:00
353fe48d60 Fix dc option 2015-01-12 21:17:55 +09:00
a96bd229a6 uniq: add examples 2015-01-10 00:28:18 +09:00
27482cbabd ip: better route example
Assigning a subnet is already covered in the example below. Setting a default route via a router is the most common use case of ip route IMHO.
2014-12-30 10:07:13 +01:00
14 changed files with 116 additions and 36 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.pyc
MANIFEST
build
cheat.egg-info
dist

View File

@ -38,7 +38,7 @@ from docopt import docopt
if __name__ == '__main__':
# parse the command-line options
options = docopt(__doc__, version='cheat 2.1.3')
options = docopt(__doc__, version='cheat 2.1.7')
# list directories
if options['--directories']:

16
cheat/cheatsheets/dnf Normal file
View File

@ -0,0 +1,16 @@
# To install the latest version of a package:
dnf install <package name>
# To search package details for the given string
dnf search <string>
# To find which package provides a binary
dnf provides <path to binary>
# The following are available after installing "dnf-plugins-core"
# Download a package
dnf download <package name>
# install the build dependencies for a SRPM or from a .spec file
dnf builddep <srpm/.spec file>

View File

@ -4,6 +4,9 @@ docker -d
# start a container with an interactive shell
docker run -ti <image_name> /bin/bash
# "shell" into a running container (docker-1.3+)
docker exec -ti <container_name> bash
# inspect a running container
docker inspect <container_name> (or <container_id>)

11
cheat/cheatsheets/dpkg Normal file
View File

@ -0,0 +1,11 @@
# Install the package or upgrade it
dpkg -i test.deb
# Remove a package including configuration files
dpkg -P test.deb
# List all installed packages with versions and details
dpkg -I
# Find out if a Debian package is installed or not
dpkg -s test.deb | grep Status

View File

@ -19,8 +19,8 @@ ip route
# Display all routes for IPv6
ip -6 route
# Add route via gateway IP
ip route add 192.168.0.0/24 via 192.168.1.1
# Add default route via gateway IP
ip route add default via 192.168.1.1
# Add route via interface
ip route add 192.168.0.0/24 dev eth0

View File

@ -19,3 +19,14 @@ journalctl /usr/bin/dbus-daemon
# Filter by PID
journalctl _PID=123
# Filter by Command, e.g., sshd
journalctl _COMM=sshd
# Filter by Command and time period
journalctl _COMM=crond --since '10:00' --until '11:00'
# List all available boots
journalctl --list-boots
# Filter by specific User ID e.g., user id 1000
journalctl _UID=1000

5
cheat/cheatsheets/p4 Normal file
View File

@ -0,0 +1,5 @@
# Print details related to Client and server configuration
p4 info
# Open a file and add it to depot
p4 add <filename>

View File

@ -0,0 +1,11 @@
# Get info about block device
udisksctl info -b <block_device>
# Mounting device
udisksctl mount --block-device <block_device>
# Unmounting device
udisksctl unmount --block-device <block_device>
# Get help
udisksctl help

18
cheat/cheatsheets/uniq Normal file
View File

@ -0,0 +1,18 @@
# show all lines without duplication
# `sort -u` and `uniq` is the same effect.
sort file | uniq
# show not duplicated lines
sort file | uniq -u
# show duplicated lines only
sort file | uniq -d
# count all lines
sort file | uniq -c
# count not duplicated lines
sort file | uniq -uc
# count only duplicated lines
sort file | uniq -dc

21
cheat/cheatsheets/zoneadm Normal file
View File

@ -0,0 +1,21 @@
# Halt zone
zoneadm -z <zone_name> halt
# Delete Zone
zoneadm -z <zone_name> halt
zoneadm -z <zone_name> uninstall
# Verify Zone
zoneadm -z <zone_name> verify
# Installing Zone
zoneadm -z <zone_name> install
# Boot Zone
zoneadm -z <zone_name> boot
# Reboot Zone
zoneadm -z <zone_name> reboot
# List Zones
zoneadm list -cv

View File

@ -25,28 +25,16 @@ def create_or_edit(sheet):
# if the cheatsheet does not exist
if not exists(sheet):
create(sheet)
# if the cheatsheet exists and is writeable...
elif exists(sheet) and is_writable(sheet):
# if the cheatsheet exists but not in the default_path, copy it to the
# 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)
# if the cheatsheet exists but is not writable...
elif exists(sheet) and not is_writable(sheet):
# ... ask the user if we should copy the cheatsheet to her home directory for editing
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.')
# if it exists and is in the default path, then just open it
else:
edit(sheet)
def create(sheet):
@ -75,6 +63,12 @@ def exists(sheet):
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):
""" Predicate that returns true if the sheet is writeable """
return sheet in sheets.get() and os.access(path(sheet), os.W_OK)

View File

@ -2,13 +2,6 @@ from cheat import cheatsheets
from cheat.utils import *
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():
""" Returns the default cheatsheet path """
@ -37,11 +30,7 @@ def default_path():
def get():
""" Assembles a dictionary of cheatsheets as name => file-path """
# if we've already reached out to the filesystem, just return the result
# from memory
if cheats:
return cheats
cheats = {}
# otherwise, scan the filesystem
for cheat_dir in reversed(paths()):

View File

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