Code tagged with zsh
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’
alias grep='grep --with-filename --context=1 --color --line-number '
Gives the usage:
grep whatever **/*.rb
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
Most modern shells support csh's bang commands - bash, tcsh and zsh
all do. While some bang commands don't work in all those shells, all of the following do. The plus side to using them is that no matter what shell you're using, these shortcuts will work.
For the purposes of these tips, every tip will assume these are the last three commands you ran:
% which firefox
% make
% ./foo -f foo.conf
% vi foo.c bar.c
Getting stuff from the last command:
Full line: % !! becomes: % vi foo.c bar.c
Last arg : % svn ci !$ becomes: % svn ci bar.c
All args : % svn ci !* becomes: % svn ci foo.c bar.c
First arg: % svn ci !!:1 becomes: % svn ci foo.c
Accessing commandlines by pattern:
Full line: % !./f becomes: % ./foo -f foo.conf
Full line: % vi `!whi` becomes: % vi `which firefox`
Last arg : % vi !./f:$ becomes: % vi foo.conf
All args : % ./bar !./f:* becomes: % ./bar -f foo.conf
First arg: % svn ci !vi:1 becomes: % svn ci foo.c
Various shells have options that can affect this. Be careful with
shells that let you share history among instances. Some shells also allow bang commands to be expanded with tabs or expanded and reloaded on the command line for further editing when you press return.
These functions encode or decode a string given as argument to be used in URLs, which means characters are encoded to %FF strings and back. Requires option extendedglob to be set.
function url-encode { E=${${(j: :)@}//(#b)(?)/%$[[##16]##${match[1]}]} }
function url-decode { D=${1//\%(#b)([0-F][0-F])/\\\x$match[1]} }
# Example:
$ url-encode "This needs to be escaped."
$ echo $E
%54%68%69%73%20%6E%65%65%64%73%20%74%6F%20%62%65%20%65%73%63%61%70%65%64%2E
$ url-decode $E
$ echo $D
This needs to be escaped.
$ URL="http://www.my-cgi-page.com/index.pl?q=$E"