Code written in Shell/Scripting

Manpage fix for programs installed via MacPorts on OSX

export MANPATH=/opt/local/share/man:$MANPATH
Language Shell/Scripting / Tagged with osx, git, man

Common git bash/zsh aliases

alias g=’git’
alias gb=’git branch’
alias gba=’git branch -a’
alias gc=’git commit -v’
alias gca=’git commit -v -a’
alias gd=’git diff | mate’
alias gl=’git pull’
alias gp=’git push’
Language Shell/Scripting / Tagged with git, bash, zsh

Git Commits That Need to be Pushed

I constantly find myself wondering what the difference is between what I’ve committed to my local Git repository, and what’s been pushed up to Github. Here’s one way, I’m sure there’s others:

git cherry -v origin
Or, how about a bash alias?
alias push?='git cherry -v origin'
Language Shell/Scripting / Tagged with git

Searching for a deleted method with git

git log -S'some_string'
git whatchanged -p (after the pager comes up, type '/' and then 'some_string')
Language Shell/Scripting / Tagged with git

Simple git continuous integration

Preventing your developers (and yourself) from breaking the build is as simple as putting this in your .git/hooks/pre-commit and making it executable (chmod +x .git/hooks/pre-commit).
#!/bin/sh
rake spec 2> /dev/null
This will stop the commit if the specs don’t pass.
Language Shell/Scripting / Tagged with git

Grep with globs alias for zsh

Posted by Chad Humphries about 1 year ago
alias grep='grep --with-filename --context=1 --color --line-number '

Gives the usage:

grep whatever **/*.rb
Language Shell/Scripting / Tagged with zsh

zsh/bash keyboard shortcuts

Posted by Chad Humphries about 1 year ago
Line Navigation:
	Beginning of Line
	⁃ control + a
	End of Line
	⁃ control + e
	Move back a character
	⁃ control + b
	Move forward a character
	⁃ control + f
	Move one word backward
	⁃ escape + b
	Move forward one word
	⁃ escape + f
Line Editing:
	Delete the word before the cursor
	⁃ control + w
	Swap the last two characters before the cursor
	⁃ control + t
	Swap the last two words before the cursor
	⁃ escape + t
	Erase/Yank the word before the cursor
	⁃ control + w
	Paste in front of cursor
	⁃ control + y
	Clear line after the cursor
	⁃ control + k
	Clear line before the cursor
	⁃ control + u
History:
	Search through previously used commands
	⁃ control + r
Language Shell/Scripting / Tagged with zsh, bash

VIM Tips

gk, gj    - Move up or down one screen line.  (Helpful if lines wrap.)

ga        - Display ASCII, hex and octal value of character under cursor.
            Helpful to search/replace control characters.  For example,
            /x1a will search for Control-Z (^Z).  ( is not literal,
            it means hit Control and v at the same time.)

gd        - Jump to declaration of local variable in a C program.
            This doesn't seem to work for multiple declarations on one line.
ge        - Move to end of previous word.
gE        - Same thing, but words are considered separated by whitespace.
W         - Go to beginning of next word after whitespace.
B         - Go to character after closest whitespace left of cursor.
E         - Go to character before closest whitespace right of cursor.
'.        - Jumps to last modified line.
`.        - Jumps to last modified position.

;         - Repeat last character search (f,F,t,T).
,         - Repeat last character search in the other direction.

C-x C-f   - Complete filename under cursor
  
g    - Display byte, word, line, etc. cursor is on.
go - Go to count byte.

     - Decrements first number after the cursor.
     - Increments first number after the cursor. 

read !... - Inserts standard output of shell command.

     - Moves cursor to beginning of command-line.
     - Moves cursor to end of command-line.
     - Deletes word before cursor on command-line.
     - Wipes command-line clean.
[I        - Grep current buffer for word under cursor.

vi *.txt                   - Open a series of files and replace all
argdo %s/pat/rep/gc | wn     occurrences of pat with rep.

set shortmess=a     Outlaws "Hit ENTER to continue" prompts.
Language Shell/Scripting / Tagged with vi, vim

Tar/Gzip Simple How-to

Posted by Chad Humphries about 1 year ago / Source: http://www.gzip.org/#faq14
With GNU tar:
gtar cvzf file.tar.gz filenames
With tar:
tar cvf -  filenames | gzip > file.tar.gz
Decompression:
tar -xzvf file.tar.gz
Language Shell/Scripting / Tagged with compression

Bash keyboard shortcuts

Bash, which is the default shell in Linux contains a whole lot of key bindings which makes it really easy to use . The most commonly used shortcuts are listed below :

____________CTRL Key Bound_____________
Ctrl + a - Jump to the start of the line
Ctrl + b - Move back a char
Ctrl + c - Terminate the command
Ctrl + d - Delete from under the cursor
Ctrl + e - Jump to the end of the line
Ctrl + f - Move forward a char
Ctrl + k - Delete to EOL
Ctrl + l - Clear the screen
Ctrl + r - Search the history backwards
Ctrl + R - Search the history backwards with multi occurrence
Ctrl + u - Delete backward from cursor
Ctrl + xx - Move between EOL and current cursor position
Ctrl + x @ - Show possible hostname completions
Ctrl + z - Suspend/ Stop the command
____________ALT Key Bound___________
Alt + < - Move to the first line in the history
Alt + > - Move to the last line in the history
Alt + ? - Show current completion list
Alt + * - Insert all possible completions
Alt + / - Attempt to complete filename
Alt + . - Yank last argument to previous command
Alt + b - Move backward
Alt + c - Capitalize the word
Alt + d - Delete word
Alt + f - Move forward
Alt + l - Make word lowercase
Alt + n - Search the history forwards non-incremental
Alt + p - Search the history backwards non-incremental
Alt + r - Recall command
Alt + t - Move words around
Alt + u - Make word uppercase
Alt + back-space - Delete backward from cursor
----------------More Special Keybindings-------------------
Here "2T" means Press TAB twice
$ 2T - All available commands(common)
$ (string)2T - All available commands starting with (string)
$ /2T - Entire directory structure including Hidden one
$ 2T - Only Sub Dirs inside including Hidden one
$ *2T - Only Sub Dirs inside without Hidden one
$ ~2T - All Present Users on system from "/etc/passwd"
$ $2T - All Sys variables
$ @2T - Entries from "/etc/hosts"
$ =2T - Output like ls or dir
Language Shell/Scripting / Tagged with bash