cheat-fork-echo/cheat

124 lines
3.3 KiB
Text
Raw Normal View History

2013-07-31 04:48:07 +02:00
#!/usr/bin/env python
import sys
2013-07-31 05:25:36 +02:00
# assemble a keyphrase out of all params passed to the script
keyphrase = ' '.join(sys.argv[1:])
# create a dictionary of cheatsheets
cheatsheets = {
2013-07-31 04:48:07 +02:00
2013-08-10 03:56:42 +02:00
########## convert ##########################################################
'convert' : '''
To resize an image to a fixed width and proportional height:
convert original-image.jpg -resize 100x converted-image.jpg
To resize an image to a fixed height and proportional width:
convert original-image.jpg -resize x100 converted-image.jpg
To resize an image to a fixed width and height:
convert original-image.jpg -resize 100x100 converted-image.jpg
To resize an image and simultaneously change its file type:
convert original-image.jpg -resize 100x converted-image.png
To resize all of the images within a directory:
for file in original/image/path/;
do new_path=${file%.*};
new_file=`basename $new_path`;
convert $file -resize 150 conerted/image/path/$new_file.png;
done
''',
2013-07-31 05:57:04 +02:00
########## dhclient ##########################################################
'dhclient' : '''
@todo
''',
########## find ##############################################################
2013-07-31 04:48:07 +02:00
'find' : '''
2013-07-31 05:25:36 +02:00
executable perms
file not directory
directory not file
2013-07-31 04:48:07 +02:00
''',
2013-07-31 05:57:04 +02:00
########## git ###############################################################
2013-07-31 04:48:07 +02:00
'git' : '''
To set your identify:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
To enable color:
git config --global color.ui true
''',
2013-07-31 05:57:04 +02:00
########## ifconfig ##########################################################
'ifconfig' : '''
@todo
''',
########## ln ################################################################
2013-07-31 04:48:07 +02:00
'ln' : '''
To create a symlink:
2013-08-10 03:56:42 +02:00
ln -s path/to/the/target/directory name-of-symlink
2013-07-31 04:48:07 +02:00
''',
2013-08-10 03:56:42 +02:00
########## netstat ###########################################################
'netstat' : '''
To view which users/processes are listening to which ports:
sudo netstat -lnptu
''',
########## sockstat ##########################################################
'sockstat' : '''
To view which users/processes are listening to which ports:
sudo sockstat -l
''',
2013-07-31 05:57:04 +02:00
########## ssh ###############################################################
'ssh' : '''
To execute a command on a remote server:
2013-08-10 03:56:42 +02:00
ssh -t user@example.com 'the-remote-command'
To tunnel an x session over SSH:
ssh -X user@example.com
2013-07-31 05:57:04 +02:00
2013-08-10 03:56:42 +02:00
To launch a specific x application over SSH:
ssh -X -t user@example.com 'chromium-browser'
For more information, see:
http://unix.stackexchange.com/q/12755/44856
''',
2013-07-31 05:57:04 +02:00
########## tar ###############################################################
2013-07-31 04:48:07 +02:00
'tar' : '''
To extract an uncompressed archive:
tar -xvf /path/to/foo.tar
2013-07-31 05:57:04 +02:00
To extract a .gz archive:
2013-07-31 04:48:07 +02:00
tar -xzvf /path/to/foo.tgz
2013-07-31 05:57:04 +02:00
To create a .gz archive:
2013-07-31 04:48:07 +02:00
tar -czvf /path/to/foo.tgz /path/to/foo/
2013-07-31 05:57:04 +02:00
To extract a .bz2 archive:
2013-07-31 04:48:07 +02:00
tar -xjvf /path/to/foo.tgz
2013-07-31 05:57:04 +02:00
To create a .bz2 archive:
2013-07-31 04:48:07 +02:00
tar -cjvf /path/to/foo.tgz /path/to/foo/
''',
}
# print help if requested
2013-07-31 05:57:04 +02:00
if keyphrase in ['', 'help', '--help', '-h']:
cheatsheets_sorted = cheatsheets.keys()
cheatsheets_sorted.sort()
print "Usage: cheat [keyphrase]\n"
print "Available keyphrases:"
print "\n".join(cheatsheets_sorted)
2013-07-31 05:25:36 +02:00
exit()
# print the cheatsheet if it exists
print cheatsheets[keyphrase] if keyphrase in cheatsheets.keys() else 'No cheatsheet found.'