Table of Contents

1 Shell    slide

1.1 zsh    slide

  • Better interactive usage
  • Better completion
  • Useful config in oh-my-zsh

1.2 Some useful keys    slide

  • Ctrl-r to search backward
  • Alt-. to repeat last argument of last command
  • Editing keys: Ctrl-w, Alt-f, Alt-b
  • Alt-l to ls
  • gnome-terminal: hide the menu, otherwise many M- combos are taken

1.3 Prompt    slide

Configure prompt to show more information

1.4 Customized shortcuts for better editing    slide

bindkey -e "\eu" backward-word
bindkey -e "\er" emacs-forward-word

bindkey -e "\ed" backward-kill-word
bindkey -e "\ef" kill-word

bindkey -e "\eh" beginning-of-line
bindkey -e "\eH" end-of-line

bindkey -e "\ei" up-history
bindkey -e "\ek" down-history

bindkey -e "\e\t" menu-complete
bindkey -e "\t" menu-complete
bindkey -e "\en" menu-complete

bindkey -e "\e " insert-last-word

1.5 Aliases    slide

  • Better default
alias ls='ls -aCFGlh --color=auto'
  • Search processes by name (check if something is actually running)
alias pp='ps -ef | grep'
pp twistd
  • Search processes listening on port (check if the server is ok)
alias sk='sudo netstat -ntlp | grep'
sk 8092

1.6 Simple shell functions    slide

  • Search packages
function pa {
    apt-cache search --names-only $1 | grep $1
pa bpython
  • Simple server for a static site
function server {
    local port="${1:-1111}"
    gnome-open "http://localhost:${port}/"
    python -m SimpleHTTPServer $port
cd server-root
server # or server 8080

2 Useful programs    slide

2.1 Quick directory switching with autojump    slide

sudo apt-get install autojump

In .profile or .zshrc

if [ -f /usr/share/autojump/ ]; then
    . /usr/share/autojump/

Switching between frequently used directories

cd ~/Programming/cogini/click-vagrant/clickserver
cd ~/Programming/cogini/bidandbuy-vagrant/bidandbuy
j cli
j bid

2.2 Copying with rsync    slide

  • Local/remote
  • Incremental
  • Compression
  • Generally better than cp/scp
alias rs='rsync --progress -rv'
alias rsl='rsync --progress -rv --inplace' # Local
alias rsn='rsync --progress -rvz'          # Network
rsn bnb-prod2:~/bidandbuy/web/html/protected/dump.sql ./
rsn ~/Programming/cogini/phyaura/phyauraehr/ phyaura@dev3:~/

# Set up a quick-n-dirty git repo
rsn ~/Programming/cogini/phyaura/phyauraehr/.git/ phyaura@dev3:~/phyaura.git/
git clone phyaura@dev3:~/phyaura.git

2.3 Port forwarding with ssh    slide

Access a local port on the remote machine

ssh -L [local_bind_address]:local_port:remote_host:remote_port
# Remote MySQL
ssh -L bnb-dev1

Let a remote machine access a port on your machine

ssh -R [remote_bind_address]:remote_port:localhost:local_port
# Make a local server accessible on a remote machine
ssh -R :8080:localhost:9022 click-dev1

Add -f -N if you want it to run in the background

2.4 Search in file name or content    slide

  • The better way, if you use Emacs M-x find-grep M-x find-name-dired
  • Or use grep, find, locate

2.5 Persistent session with tmux    slide

  • Disconnection-safe
tmux new-session -s ubolonton
tmux attach-session -t ubolonton
  • Split screen into smaller "windows": edit code and see logs at the same time
  • Multiple "tabs"
  • Pair programming without sharing monitor
  • Configure shortcuts and other options with .tmux.conf
set-option -g default-shell /usr/bin/zsh
set-option -g prefix C-h
bind-key C-h last-window
bind h previous-window
bind - split-window -v
bind | split-window -h

2.6 xbindkeys

Assign system-wide shortcuts to shell command

  • Custom volume control
  • xdotool:
  • Getting the mouse out of the way
  • Rudimentary window management, app switching, fullscreen toggling
  • conkeror:
  • Control web music player without switching to the browser
  • Switch to browser's mail tab from anywhere
  • emacsclient:
  • Anything you want

2.7 git    slide

  • Easier-to-read log (or just use magit): put in ~/.gitconfig
    pretty = "Commit:  %C(cyan)%H%nAuthor:  %C(green)%aN <%aE>%nDate:    (%C(yellow)%ar%Creset) %ai%n%n     %C(white)%s%n%b"
  • Manage config files and other personal stuff
cd ~
git clone
ln -s ~/dotfiles/.zshrc ~/.zshrc

Date: 2012-12-12T14:57+0700

Author: Nguyễn Tuấn Anh

Org version 7.9.2 with Emacs version 24

Validate XHTML 1.0