Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
2,355 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
--- | ||
bash::complete: |+ | ||
# mategem. complete with installed gem directories | ||
_mategem() | ||
{ | ||
local curw | ||
COMPREPLY=() | ||
curw=${COMP_WORDS[COMP_CWORD]} | ||
local gems="$(gem environment gemdir)/gems" | ||
COMPREPLY=($(compgen -W '$(ls $gems)' -- $curw)); | ||
return 0 | ||
} | ||
complete -F _mategem -o dirnames mategem | ||
bash_complete: |- | ||
A bash snippet to have auto-complete for | ||
the 'cheat' gem. | ||
# chit | ||
_chit() | ||
{ | ||
COMPREPLY=($(compgen -W '$(chit all)' -- ${COMP_WORDS[COMP_CWORD]})); | ||
return 0 | ||
} | ||
complete -F _chit chit | ||
Use by typing : | ||
$ cheat str<tab> | ||
and get: | ||
strftime string string_unpack | ||
-------- bash script -------- | ||
function complete_cheat { | ||
COMPREPLY=() | ||
if [ $COMP_CWORD = 1 ]; then | ||
sheets=`cheat sheets | grep '^ '` | ||
COMPREPLY=(`compgen -W "$sheets" -- $2`) | ||
fi | ||
} | ||
complete -F complete_cheat cheat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
bash_emacskeys: | | ||
Emacs keyboard bindings | ||
For OS X, open Terminal Preferences > keyboard, and check: | ||
"Use option key as meta key" | ||
--- | ||
In Terminal | ||
* and ** = variable user input | ||
opt-b : back one word | ||
opt-f : forward one word | ||
ctrl-a : beginning of line | ||
ctrl-e : end of line | ||
ctrl-]* : jump forward to character * | ||
ctrl-opt-]* : jump backward to character * (not OS X 10.4?) | ||
opt-* : repeat the next command * times where * is an integer | ||
ctrl-r * : reverse history search for * | ||
ctrl-j : edit found command | ||
!* : run last command matching * | ||
* opt-. : find last command matching * (repeat to cycle) | ||
*!$ : grab last command argument and execute | ||
!#:* : grab *th argument of current line (to repeat it) | ||
:s/*/** : search and replace * with ** | ||
^*^** : search and replace in previous command | ||
e.g. | ||
ls al | ||
ls: al: No such file or directory | ||
^al^-al | ||
gives | ||
ls -al | ||
^* : delete first instance of * in previous command | ||
e.g. | ||
lss -al | ||
-bash: lss: command not found | ||
^s | ||
gives | ||
ls -al | ||
Cut and paste (Kill and Yank) | ||
ctrl -w : delete argument back to previous space | ||
: press immediately more than once to save multiple in one go | ||
opt-del : delete word back to previous word boundary | ||
opt-d : delete forward one word | ||
ctrl-k : kill to end of line | ||
ctrl-u : kill to start of line | ||
ctrl-y : paste | ||
opt-y : (after ctrl-y) cycle through 'kill ring' | ||
grab numbered argument e.g. | ||
echo a b c d > file.txt | ||
echo !echo:3 | ||
gives echo c | ||
transform: grab tail end :t of last argument e.g. | ||
wget ftp://somedomain.com/somefile.tar.gz | ||
tar xzf !$:t | ||
gives: | ||
tar xzf ftp://somedomain.com/somefile.tar.gz | ||
remove two extensions with :r | ||
cd !$:r:r | ||
gives | ||
cd somefile | ||
see: | ||
http://teachmetocode.com/screencasts/bash-command-line-editing/ | ||
ctrl-x ctrl-v : default bash editor | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
bash_param: | | ||
Bash parameter expansions | ||
========================= | ||
NOTE: | ||
The `:' character used in many of the expansions is optional. | ||
Using the `:' checks for param that is unset or null. | ||
Without the `:' checks for param that is unset. | ||
| Expansion | Note | | ||
|--------------------------+---------------------------------| | ||
| ${param} | Use value | | ||
| ${!param} | Variable indirection | | ||
| ${param:-word} | Use default value | | ||
| ${param:=word} | Assign default value | | ||
| ${param:?word} | Display error | | ||
| ${param:+word} | Use alternate value | | ||
| ${param:offset} | Substring expansion | | ||
| ${param:offset:length} | Substring expansion with length | | ||
| ${!prefix*} | Name expansion with prefix | | ||
| ${#param} | Length in characters | | ||
| ${param#word} | Remove shortest match at start | | ||
| ${param##word} | Remove longest match at start | | ||
| ${param%word} | Remove shortest match at end | | ||
| ${param%%word} | Remove longest match at end | | ||
| ${param/pattern/string} | Replace first matching pattern | | ||
| ${param//pattern/string} | Replace all matching patterns | | ||
Examples: | ||
$ x=yes | ||
$ echo ${x} #=> yes | ||
$ echo ${x:-no} #=> yes | ||
$ x= | ||
$ echo ${x:-no} #=> no | ||
$ echo ${x-no} #=> "" <an empty string> | ||
$ unset x | ||
$ echo ${x:-no} #=> no | ||
$ echo ${x-no} #=> no | ||
$ path='/some/path/to/file.txt' | ||
$ echo ${path##*/} #=> file.txt | ||
$ echo ${path%/*} #=> /some/path/to | ||
$ x=yes | ||
$ y=x | ||
$ echo ${!y} #=> yes | ||
$ x=0123456789 | ||
$ echo ${x:0} #=> 0123456789 | ||
$ echo ${x:3} #=> 3456789 | ||
$ echo ${x:3:2} #=> 34 | ||
$ xval1=first | ||
$ xval2=second | ||
$ xval3=third | ||
$ echo ${!xval*} #=> xval1 xval2 xval3 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
bash_scripting: |- | ||
-z "string" String has zero length | ||
-n "string" String has non-zero length | ||
Note | ||
To check whether a variable is set and not blank, use -n "${BLAH}" rather than -n $BLAH. The latter will cause problems in some situations if the variable is unset. | ||
Integer Comparison in bash | ||
The general form of integer comparisons is int1 -operator int2. The following are available: | ||
Operator Purpose | ||
-eq Integer equality | ||
-ne Integer inequality | ||
-lt Integer less than | ||
-le Integer less than or equal to | ||
-gt Integer greater than | ||
-ge Integer greater than or equal to | ||
File Tests in bash | ||
The general form of a file test is -operator "filename". The following are available (lifted from man bash): | ||
Operator Purpose | ||
-a file Exists (use -e instead) | ||
-b file Exists and is a block special file | ||
-c file Exists and is a character special file | ||
-d file Exists and is a directory | ||
-e file Exists | ||
-f file Exists and is a regular file | ||
-g file Exists and is set-group-id | ||
-h file Exists and is a symbolic link | ||
-k file Exists and its sticky bit is set | ||
-p file Exists and is a named pipe (FIFO) | ||
-r file Exists and is readable | ||
-s file Exists and has a size greater than zero | ||
-t fd Descriptor fd is open and refers to a terminal | ||
-u file Exists and its set-user-id bit is set | ||
-w file Exists and is writable | ||
-x file Exists and is executable | ||
-O file Exists and is owned by the effective user id | ||
-G file Exists and is owned by the effective group id | ||
-L file Exists and is a symbolic link | ||
-S file Exists and is a socket | ||
-N file Exists and has been modified since it was last read | ||
File Comparison in bash | ||
The general form of a file comparison is "file1" -operator "file2". The following are available (lifted from man bash): | ||
Operator Purpose | ||
file1 -nt file2 file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not. | ||
file1 -ot file2 file1 is older than file2, or if file2 exists and file1 does not. | ||
file1 -ef file2 file1 and file2 refer to the same device and inode numbers. | ||
Boolean Algebra in bash | ||
There are constructs available for boolean algebra ('and', 'or' and 'not'). These are used outside of the [[ ]] blocks. For operator precedence, use ( ). | ||
Construct Effect | ||
first || second first or second (short circuit) | ||
first && second first and second (short circuit) | ||
! condition not condition | ||
Note | ||
These will also sometimes work inside [[ ]] constructs, and using ! before a test is fairly common. [[ ! -foo ]] && bar is fine. However, there are catches -- [[ -f foo && bar ]] will not work properly, since commands cannot be run inside [[ ]] blocks. | ||
Inside [ ] blocks, several -test style boolean operators are available. These should be avoided in favour of [[ ]] and the above operators. | ||
To download files that have zero-padded filenames (bob002.jpg etc. in this example): | ||
for i in `seq -f "%03g" 1 100`; do wget http://www.example.com/bob$i.jpg; done | ||
Change the seq formatting options for more or less padding. | ||
Arrays in bash: | ||
zombies=(bob tom) | ||
zombies[10]='helen' | ||
echo 'zombie 0 is' ${zombies[0]} | ||
#zombie 0 is bob | ||
for name in ${zombies[@]} | ||
do | ||
echo $name 'is a zombie' | ||
done | ||
#bob is a zombie | ||
#tom is a zombie | ||
#helen is a zombie | ||
for (( i=0; i < ${#zombies[@]}; i++ )) | ||
do | ||
echo 'zombie' $i 'is' ${zombies[$i]} | ||
done | ||
#zombie 0 is bob | ||
#zombie 1 is tom | ||
#zombie 3 is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
css_at_rules: |- | ||
@charset "ISO-8859-1"; | ||
Specify the encoding of the CSS file | ||
@import url("printing.css") print | ||
Import additional css file 'printing.css' for print media | ||
@page :first { margin: 10cm; } | ||
Sets content margins on the first 'page' to 10cm; see also :left and :right. | ||
@media screen, print { body { font-size: 10pt } } | ||
Set font size for body element for print and screen media | ||
In CSS 3 Web Fonts Module: | ||
@font-face { | ||
font-family: "My Helvetica"; src: url(my_helvetica.ttf) format("truetype"); | ||
} | ||
Load the font "My Helvetica" from the URL. | ||
In CSS 3 Namespaces Module: | ||
@namespace "http://www.w3.org/1999/xhtml"; | ||
@namespace svg "http://www.w3.org/2000/svg"; | ||
The default namespace sets to the XHTML URI, the 'svg' prefix maps SVG URI | ||
In CSS 3 Paged Media Module: | ||
@page :left { @bottom-left-corner { content: counter(page); } } | ||
@page :right { @bottom-right-corner { content: counter(page); } } | ||
Print page numbers on the outside bottom corners of (printed) pages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
css_boxing: |- | ||
+-----------------------------------------------------+ | ||
: : | ||
: _______________________________________________ : | ||
: | _____________________________________________ | : | ||
: || || : | ||
: || || : | ||
: || +-------------------------------------+ || : | ||
: || | | || : | ||
: || | Content (width x height) | || : | ||
: || | | || : | ||
: || +-------------------------------------+ || : | ||
: || Padding (background) || : | ||
: ||_____________________________________________|| : | ||
: |___________________Border______________________| : | ||
: : | ||
: Margin (transparent) : | ||
+-----------------------------------------------------+ | ||
Area = (width,height) + padding + border + margin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
css_media: |- | ||
Common: | ||
all Suitable for all devices. | ||
screen Computer screens and most handheld devices. | ||
print Page-delimited mode for printing and print preview | ||
Rare: | ||
projection Projections/presentations, used by Opera 4+ fullscreen mode | ||
aural Speech synthesizers, used by Firevox. Deprecated in CSS 2.1 | ||
speech Speech synthesizers, reserved. | ||
tv Television displays, used by WebTV. | ||
handheld Handheld devices, supported by Symbian. | ||
Not used by any known agents: | ||
braille Braille tactile feedback devices. | ||
embossed Paged braille printers. | ||
tty Fixed width character grid such as terminals. | ||
@import url("fancyfonts.css") screen, print; | ||
load the file fancyfonts.css for screen and print within your CSS. | ||
@media print { /* style sheet for print goes here */ } | ||
Inline style rules for print within your CSS | ||
<link rel="stylesheet" type="text/css" media="print" href="print.css"> | ||
HTML inclusion of different sheets based on agent media type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
css_selectors: |- | ||
CSS 1: | ||
E An element of type E | ||
S1 S2 Any selector S1 with descendant match S2 (not just children) | ||
E F ... such as element E with descendant element F | ||
E.myclass Element E marked with class "myclass" | ||
E#myid ... with a document ID of "myid" | ||
E:link ... which is an unvisited link | ||
E:visited ... which is a visited link | ||
E:active ... which is activated (such as between mouse down and up) | ||
E:hover ... with a pointing device within its boundaries | ||
E:focus ... which has input device focus | ||
E::first-line The first formatted line of E element | ||
E::first-letter The first formatted letter of E element | ||
S1, S2 Matching S1 or S2 | ||
CSS 2.x: | ||
* Special name matching any element | ||
S1 > S2 Selector S1 with child matching S2 | ||
S1 + S2 Selector S1 with immediately following sibling matching S2 | ||
E[attr] An E element with a "attr" attribute | ||
E[attr="val"] ... whose value is exactly equal to "val" | ||
E[attr~="val"] ... with "val" as a whitespace-separated element | ||
E[attr|="en"] ... whose value is "en" or begins with "en-" (hreflang) | ||
E:first-child E element, first child of its parent | ||
E:lang(fr) E element in language "fr" (lang or xml:lang) | ||
E::before Generated content before E element (see style 'content') | ||
E::after Generated content after E element (see style 'content') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
git_add_i: |- | ||
git-add -i | ||
========== | ||
y - stage this hunk | ||
n - do not stage this hunk | ||
a - stage this and all the remaining hunks in the file | ||
d - do not stage this hunk nor any of the remaining hunks in the file | ||
j - leave this hunk undecided, see next undecided hunk | ||
J - leave this hunk undecided, see next hunk | ||
k - leave this hunk undecided, see previous undecided hunk | ||
K - leave this hunk undecided, see previous hunk | ||
s - split the current hunk into smaller hunks | ||
? - print help |
Oops, something went wrong.