<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AskApache &#187; Search Results  &#187;  vim</title>
	<atom:link href="http://www.askapache.com/search/vim/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Thu, 26 Apr 2012 11:29:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Optimized Vimrc with 256 Colorscheme</title>
		<link>http://www.askapache.com/linux/fast-vimrc.html</link>
		<comments>http://www.askapache.com/linux/fast-vimrc.html#comments</comments>
		<pubDate>Sun, 26 Feb 2012 18:15:32 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=7062</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/linux/fast-vimrc.html"><img src="http://uploads.askapache.com/2012/02/vimrc-colorscheme.png" alt="askapachecode 256color colorscheme and vimrc screenshot" title="askapachecode 256color colorscheme and vimrc screenshot" width="525" height="277" class="size-full wp-image-7074" /></a><strong>This is not your everyday vimrc</strong>.  This is <em>my</em> personalized vimrc.. works especially great on remote servers, in tmux, screen, etc. <br /><br />This doesn't require a git checkout, a vim update, a bash update, an OS update, a plugin.  No.  1 vimrc, 1 colorscheme, just use curl to download and it's on.  I use this on <a href="http://archlinux.org/">Arch Linux</a>, NetBSD, FreeBSD, OpenBSD, Debian, Ubuntu, Cent OS, Red Hat, and that's mostly it so far. <br />If you aren't already using vim as your primary editor in a powerful way, you are gonna owe me for this.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/linux/fast-vimrc.html"></a><a href="http://www.askapache.com/linux/fast-vimrc.html"><cite>AskApache.com</cite></a></p><p>This is 90% geared for purely console/terminal/pty/tty/ssh/putty/telnet/tmux/screen users.  I've only just the past couple years started understanding why it was key to learn vim, in the past I never had the patience for it and preferred nano-like editors.  Now vim is all I use when on linux, it's so much more productive.. especially with a customized vimrc file.  This doesn't require a git checkout, a vim update, a bash update, an OS update, a plugin.  No.  This is a single file that I use on <a href="http://archlinux.org/">Arch Linux</a>, NetBSD, FreeBSD, OpenBSD, Debian, Ubuntu, Cent OS, Red Hat, and that's it so far.  This is geared for users who use SSH more than anything else.  Of course, it works perfect on an X enabled box locally as well.</p>

<h2>ScreenShot</h2>
<p><a href="http://uploads.askapache.com/2012/02/vimrc-screenshot.png"><img src="http://uploads.askapache.com/2012/02/vimrc-screenshot.png" alt="Screenshot of this vimrc in action" title="Screenshot of this vimrc in action" width="911" height="987" class="size-full wp-image-7073" /></a></p>

<h2>Setup</h2>
<p>I install this as <code>/etc/vimrc</code> if possible.  Individual users can use a vim config file in their home directories.</p>
<pre>source /etc/vimrc</pre>
<p>To install for a single user just save it in their home dir at <code>/home/username/.vimrc</code></p>

<h2>Portability</h2>
<p>For the portability needed to work on many different systems, this doesn't rely on any plugins other than those built into the default installation of vim 7.0.
It works well on all types of consoles, and depending on the TERM environment variable (and whether it has the right term capabilities) it will load 256 color support or not.  Usually on a new system I just scp this right over and it works without any modifications.  But an ongoing Work in progress.</p>



<h2>Optimized Vimrc</h2>
<p>Download - <a href='http://uploads.askapache.com/2012/02/vimrc.txt'>Optimized vimrc</a></p>
<pre>" Updated: Wed Feb 22 13:25:23 2012 by galileo@galileo
&nbsp;
" For all key mappings like &#039;, .&#039; to reload vimrc
let maplocalleader=&#039;,&#039;
&nbsp;
" BACKUPS, SWAPFILES, VIEWDIR, TMPDIR  "{{{1
" ================================================================================================================================================================
&nbsp;
" SET RUNTIMEPATH {{{3
if isdirectory(expand("$HOME/.vim"))
  let $VIMRUNTIME=expand("$HOME/.vim")
  set runtimepath=$VIMRUNTIME
endif
&nbsp;
" IF BKDIR IS NOT SET OR EMPTY, SET {{{3
if $BKDIR == ""
  let $BKDIR=expand("$HOME/.bk")
  if !isdirectory(expand("$BKDIR"))
    call mkdir(expand("$BKDIR"), "p", 0700)
  endif
endif
&nbsp;
" MAKE DIRS IF mkdir exists {{{3
if exists("*mkdir")
  if !isdirectory(expand("$BKDIR/.vim/viewdir"))|call mkdir(expand("$BKDIR/.vim/viewdir"), "p", 0700)|endif
  if !isdirectory(expand("$BKDIR/.vim/tmp"))|call mkdir(expand("$BKDIR/.vim/tmp"), "p", 0700)|endif
  if !isdirectory(expand("$BKDIR/.vim/backups"))|call mkdir(expand("$BKDIR/.vim/backups"), "p", 0700)|endif
endif
&nbsp;
" SETTINGS USING NEW DIRS {{{3
let &amp;dir=expand("$BKDIR") . "/.vim"
let &amp;viewdir=expand("$BKDIR") . "/.vim/viewdir"
let &amp;backupdir=expand("$BKDIR") . "/.vim/backups"
"let &amp;verbosefile=expand("$BKDIR") . "/.vim/vim-messages.
&nbsp;
" VIMINFO {{{3
" COMMENTED OUT {{{4
"  "       Maximum number of lines saved for each register
"  %       When included, save and restore the buffer lis
"  &#039;       Maximum number of previously edited files for which the marks are remembere
"  /       Maximum number of items in the search pattern history to be saved
"  :        Maximum number of items in the command-line history
"  &lt;       Maximum number of lines saved for each register.
"   @       Maximum number of items in the input-line history
"  h       Disable the effect of &#039;hlsearch&#039; when loading the viminfo
"  n       Name of the viminfo file.  The name must immediately follow the &#039;n&#039;.  Must be the last oneEnvironment variables are expanded when opening the file, not when setting the option
"  r       Removable media.  The argument is a string
"  s       Maximum size of an item in Kbyte
"   }}}4 COMMENTED OUT
let &amp;viminfo="%200,&#039;200,/800,h,&lt;500,:500,s150,r/tmp,r" . expand("$BKDIR") . "/.vim/tmp,n" . expand("$BKDIR") ."/.vim/.vinfo"
&nbsp;
" CUSTOM FUNCTIONS "{{{1
" ================================================================================================================================================================
if !exists("AskApacheLoaded")
  let AskApacheLoaded=1
&nbsp;
  " FUNCTION - LastMod {{{3
  " Warning, this is controlled by an autocmd triggered when closing the file that updates the file (in a great way)
  " Updated: Wed Feb 22 13:25:23 2012 by galileo@galileo
  function! LastMod()
    exe "silent! 1,20s/Updated: .*/" . printf(&#039;Updated: %s by %s@%s&#039;, strftime("%c"), expand("$LOGNAME"), hostname()) . "/e"
  endfunction
&nbsp;
  " FUNCTION - LastModNow {{{3
  " An even better version than LastMod()
  function! LastModNow()
    call setline(line(&#039;.&#039;), printf(&#039;%sUpdated: %s by %s@%s&#039;, printf(&amp;commentstring, &#039; &#039;), strftime("%c"), expand("$LOGNAME"), hostname()))
    "printf(&#039;%sUpdated: %s by %s@%s&#039;, printf(&amp;commentstring, &#039; &#039;), strftime("%c"), expand("$LOGNAME"), hostname())\|dd\|j\|dd&lt;CR&gt;&lt;ESC&gt;
    "printf(&#039;Updated: %s by %s %s&#039;, strftime("%c"), expand("$LOGNAME@$HOSTNAME")) ."/e"
  endfunction
&nbsp;
  " FUNCTION - AppendModeline {{{3
  " Append modeline after last line in buffer.  Use substitute() instead of printf() to handle &#039;%%s&#039; modeline
  function! AppendModeline()
    let l:modeline = printf(" vim: set ft=%s ts=%d sw=%d tw=%d foldmethod=%s :", &amp;filetype, &amp;tabstop, &amp;shiftwidth, &amp;textwidth, &amp;foldmethod)
    let l:modeline = substitute(&amp;commentstring, "%s", l:modeline, "")
    call append(line("$"), l:modeline)
  endfunction
&nbsp;
  " FUNCTION - LastModAAZZZ {{{3
  " AA_UPDATED=&#039;01/24/12-00:56:00&#039;
  function! LastModAAZZZ()
    exe "1,50s/AA_UPDATED=.*/AA_UPDATED=&#039;" . strftime("%c") . "&#039;"
  endfunction
&nbsp;
  " FUNCTION - StripTrailingWhitespace {{{3
  " automatically remove trailing whitespace before write
  function! StripTrailingWhitespace()
    normal mZ
    %s/\s\+$//e
    if line("&#039;Z") != line(".")|echo "Stripped whitespace\n"|endif
    normal `Z
  endfunction
&nbsp;
  " FUNCTION - MyTabL {{{3
  function! MyTabL()
    let s = &#039;&#039;|let t = tabpagenr()|let i = 1
    while i &lt;= tabpagenr(&#039;$&#039;)
      let bl = tabpagebuflist(i)|let wn = tabpagewinnr(i)
      let s .= &#039;%&#039; . i . &#039;T&#039;. (i == t ? &#039;%1*&#039; : &#039;%2*&#039;) . &#039;%*&#039; . (i == t ? &#039; %#TabLineSel# &#039; : &#039;%#TabLine#&#039;)
      let file = (i == t ? fnamemodify(bufname(bl[wn - 1]), &#039;:p&#039;) : fnamemodify(bufname(bl[wn - 1]), &#039;:t&#039;) )|if file == &#039;&#039;|let file = &#039;[No Name]&#039;|endif
      let s .= i.&#039; &#039;. file .(i == t ? &#039; &#039; : &#039;&#039;)|let i += 1
    endwhile
    let s .= &#039;%T%#TabLineFill#%=&#039; . (tabpagenr(&#039;$&#039;) &gt; 1 ? &#039;%999XX&#039; : &#039;X&#039;)
    return s
  endfunction
&nbsp;
  " FUNCTION - DiffWithSaved {{{3
  " Diff with saved version of the file
  function! s:DiffWithSaved()
    let filetype=&amp;ft
    diffthis
    vnew | r # | normal! 1Gdd
    diffthis
    exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
  endfunction
  com! DiffSaved call s:DiffWithSaved()
&nbsp;
  " FUNCTION - ShowWhitespace() {{{3
  function! ShowWhitespace(flags)
    let bad = &#039;&#039;
    let pat = []
    for c in split(a:flags, &#039;\zs&#039;)
      if c == &#039;e&#039;
        call add(pat, &#039;\s\+$&#039;)
      elseif c == &#039;i&#039;
        call add(pat, &#039;^\t*\zs \+&#039;)
      elseif c == &#039;s&#039;
        call add(pat, &#039; \+\ze\t&#039;)
      elseif c == &#039;t&#039;
        call add(pat, &#039;[^\t]\zs\t\+&#039;)
      else
        let bad .= c
      endif
    endfor
&nbsp;
    if len(pat) &gt; 0
      let s = join(pat, &#039;\|&#039;)
      exec &#039;syntax match ExtraWhitespace "&#039;.s.&#039;" containedin=ALL&#039;
    else
      syntax clear ExtraWhitespace
    endif
&nbsp;
    if len(bad) &gt; 0|echo &#039;ShowWhitespace ignored: &#039;.bad|endif
  endfunction
&nbsp;
  " FUNCTION - ToggleShowWhitespace {{{3
  " I use this all the time, it&#039;s mapped to , ts
  function! ToggleShowWhitespace()
    if !exists(&#039;b:ws_show&#039;)|let b:ws_show = 0|endif
    if !exists(&#039;b:ws_flags&#039;)|let b:ws_flags = &#039;est&#039;|endif
    let b:ws_show = !b:ws_show
    if b:ws_show|call ShowWhitespace(b:ws_flags)|else|call ShowWhitespace(&#039;&#039;)|endif
  endfunction
&nbsp;
endif
&nbsp;
" DYNAMIC SETTINGS / COLORS / TERMINAL {{{1
" ================================================================================================================================================================
&nbsp;
" DISABLE MOUSE NO GOOEYS {{{3
if has(&#039;mouse&#039;)|set mouse=|endif
&nbsp;
" SET TITLESTRING {{{3
if has(&#039;title&#039;)|set titlestring=%t%(\ [%R%M]%)|endif
&nbsp;
" SET TABLINE {{{3
if exists("*s:MyTabL")|set tabline=%!MyTabL()|endif
&nbsp;
let g:vimsyn_folding=&#039;af&#039;
&nbsp;
"DISABLE FILETYPE-SPECIFIC MAPS {{{3
let no_plugin_maps=1
&nbsp;
"}}}1 DYNAMIC SETTINGS / COLORS / TERMINAL
&nbsp;
" OPTIONS "{{{1
" ===========================================================================================================================================================================
&nbsp;
" BACKUP, FILE OPTIONS {{{2
" ================================================================================
set backup        " Make a backup before overwriting a file.  Leave it around after the file has been successfully written.
set backupcopy=auto " When writing a file and a backup is made, this option tells how it&#039;s done.  This is a comma separated list of words. - value: yes,no,auto - no:rename the file and write a new one
&nbsp;
set swapfile
set swapsync=fsync
&nbsp;
"}}}2 BACKUP, FILE OPTIONS
&nbsp;
" BASIC SETTINGS "{{{2
" ================================================================================
set nocompatible    " vim, not vi.. must be first, because it changes other options as a side effect
set modeline
&nbsp;
set statusline=%M%h%y\ %t\ %F\ %p%%\ %l/%L\ %=[%{&amp;ff},%{&amp;ft}]\ [a=\%03.3b]\ [h=\%02.2B]\ [%l,%v]
set title titlelen=150 titlestring=%(\ %M%)%(\ (%{expand(\"%:p:h\")})%)%(\ %a%)\ -\ %{v:servername}
&nbsp;
"set tags=tags;/      " search recursively up for tags
&nbsp;
set ttyfast        " we have a fast terminal
set scrolljump=5    " when scrolling up down, show at least 5 lines
"set ttyscroll=999    " make vim redraw screen instead of scrolling when there are more than 3 lines to be scrolled
&nbsp;
"set tw=500        " default textwidth is a max of 5
&nbsp;
set undolevels=10    " 50 undos - saved in memory
set updatecount=250    " switch every 250 chars, save swap
&nbsp;
set whichwrap+=b,s,&lt;,&gt;,h,l,[,]      " backspaces and cursor keys wrap to
"set wildignore+=*.o,*~,.lo,*.exe,*.bak  " ignore object files
"set wildmenu              " menu has tab completion
"set wildmode=longest:full        " *wild* mode
set nowrap
&nbsp;
set autoindent smartindent    " auto/smart indent
&nbsp;
set autoread          " watch for file changes
&nbsp;
set backspace=indent,eol,start  " backspace over all kinds of things
&nbsp;
set cmdheight=1          " command line two lines high
set complete=.,w,b,u,U,t,i,d  " do lots of scanning on tab completion
set cursorline          " show the cursor line
"set enc=utf-8 fenc=utf-8    " utf-8
&nbsp;
set history=3000        " keep 3000 lines of command line history
&nbsp;
set keywordprg=TERM=mostlike\ man\ -s\ -Pless
&nbsp;
set laststatus=2
&nbsp;
"set lazyredraw          " don&#039;t redraw when don&#039;t have to
set linebreak          " wrap at &#039;breakat&#039; instead of last char
set magic            " Enable the "magic"
&nbsp;
set maxmem=25123  " 24 MB -  max mem in Kbyte to use for one buffer.  Max is 2000000
&nbsp;
set noautowrite          " don&#039;t automagically write on :next
&nbsp;
set noexpandtab          " no expand tabs to spaces"
set noruler          " show the line number on the bar
set nospell
set nohidden          " close the buffer when I close a tab (I use tabs more than buffers)
&nbsp;
set noerrorbells visualbell t_vb= " Disable ALL bells
&nbsp;
set number          " line numbers
&nbsp;
set pastetoggle=&lt;F11&gt;
&nbsp;
set scrolloff=3        " keep at least 3 lines above/below
set shiftwidth=3      " shift width
&nbsp;
set showcmd          " Show us the command we&#039;re typing
set showfulltag        " show full completion tags
set showmode        " show the mode all the time
&nbsp;
set sidescroll=2      " if wrap is off, this is fasster for horizontal scrolling
set sidescrolloff=2      "keep at least 5 lines left/right
&nbsp;
set noguipty
&nbsp;
set splitright
set splitbelow
&nbsp;
set restorescreen=on " restore screen contents when vim exits -  disable withset t_ti= t_te=
&nbsp;
"set sessionoptions=word,blank,buffers,curdir,folds,globals,help,localoptions,resize,sesdir,tabpages,winpos,winsize
set winheight=25
set winminheight=1  " minimal value for window height
"set winheight=30  " set the minimal window height
set equalalways    " all the windows are automatically sized same
set eadirection=both  " only equalalways for horizontally split windows
&nbsp;
set hlsearch
&nbsp;
set laststatus=2
&nbsp;
set tabstop=4
set softtabstop=4
&nbsp;
set shiftwidth=3
set switchbuf=usetab
&nbsp;
set commentstring=#%s
&nbsp;
set tabpagemax=55
set showtabline=2    " 2 always, 1 only if multiple tabs
set smarttab      " tab and backspace are smart
&nbsp;
set foldmethod=marker
set foldenable
set foldcolumn=6        " the blank left-most bar left of the numbered lines
&nbsp;
set incsearch          " incremental search
"set ignorecase          " search ignoring case
set sc              " override &#039;ignorecase&#039; when pattern has upper case characters
set smartcase          " Ignore case when searching lowercase
&nbsp;
set showmatch          " show matching bracket
set diffopt=filler,iwhite    " ignore all whitespace and sync"
set stal=2
&nbsp;
"}}}1 OPTIONS
&nbsp;
" PLUGIN SETTINGS {{{1
" ================================================================================================================================================================
" Settings for :TOhtml "{{{3
let html_number_lines=1
let html_use_css=1
let use_xhtml=1
"}}}1 PLUGIN SETTINGS
&nbsp;
" COLORSCHEME IF MORE THAN 2 COLORS lol {{{1
" ================================================================================================================================================================
if &amp;t_Co &gt; 2
&nbsp;
  if &amp;term =~ "256"
&nbsp;
    set bg=dark t_Co=256 vb
    let &amp;t_vb="\&lt;Esc&gt;[?5h\&lt;Esc&gt;[?5l"  " flash screen for visual bell
&nbsp;
    if filereadable(expand("$VIMRUNTIME/colors/askapachecode.vim"))
      colorscheme askapachecode
    elseif filereadable(expand("$HOME/.vim/colors/askapachecode.vim"))
      colorscheme askapachecode
    else
      colorscheme default
    endif
&nbsp;
    filetype indent plugin on
    syntax on
&nbsp;
  else
    " things like cfdisk, crontab -e, visudo, vless, etc.
    set term=linux
    set t_Co=8
    syntax off
    filetype indent plugin off
&nbsp;
  endif
&nbsp;
endif
&nbsp;
"}}}1
&nbsp;
" AUTOCOMMANDS "{{{1
" ===========================================================================================================================================================================
"if !exists(":DiffOrig") | command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis | endif
&nbsp;
" auto load extensions for different file types
if has(&#039;autocmd&#039;)
&nbsp;
  if !exists("autocommands_loaded")
    let autocommands_loaded = 1
&nbsp;
    " JUMP TO LAST POS {{{3
    " When editing a file, always jump to the last known cursor position. Don&#039;t do it when the position is invalid or when inside an event handler
    " (happens when dropping a file on gvim). Also don&#039;t do it when the mark is in the first line, that is the default position when opening a file.
    au BufReadPost * if line("&#039;\"") &gt; 1 &amp;&amp; line("&#039;\"") &lt;= line("$") | exe "normal! g`\"" | endif
&nbsp;
    " CLEARMATCHES ON BUFWINLEAVE {{{3
    au BufWinLeave * call clearmatches()
&nbsp;
    " STRIP TRAILING WHITESPACE {{{3
    autocmd BufWritePre *.cpp,*.hpp,*.i :call StripTrailingWhitespace()
&nbsp;
    " AA_ZZZ LAST MOD {{{3
    autocmd BufWritePre,FileWritePre,TabLeave zzz_askapache-bash.sh ks|call LastModAAZZZ()|&#039;s
&nbsp;
    " SET VIM SETTINGS FOR AA_ZZZ SCRIPTS {{{3
    autocmd BufRead /etc/ZZZ/*.sh,.bash_profile,.bash_login,.bashrc,.bash_login_user,.bash_logout setlocal ts=4 sw=3 ft=sh foldmethod=marker tw=500 foldcolumn=7
&nbsp;
    " INSERT CURRENT DATE AND TIME IN A *.SH FILE WHEN WRITING IT {{{3
    autocmd BufWritePre,FileWritePre *.*   ks|call LastMod()|&#039;s
&nbsp;
    " IMPROVE LEGIBILITY {{{3
    autocmd BufRead quickfix setlocal nobuflisted wrap number
&nbsp;
    " SAVE BACKUPFILE AS BACKUPDIR/FILENAME-06-13-1331 {{{3
    autocmd BufWritePre * let &amp;bex = strftime("-%m-%d-%H%M")
&nbsp;
    " TMUX FILETYPE {{{3
    autocmd BufRead tmux.conf,.tmux.conf,.tmux*,*/tmux-sessions/* setlocal filetype=tmux foldmethod=marker
&nbsp;
    " APACHE2 FILETYPE {{{3
    autocmd BufRead /opt/a*/conf/*,/etc/httpd/*.conf setlocal filetype=apache
&nbsp;
    " SH FILETYPES {{{3
    autocmd BufRead *.sh,*.cron,*.bash setlocal filetype=sh
&nbsp;
    " SYSLOG-NG FILETYPE {{{3
    autocmd BufRead syslog-ng.conf setlocal filetype=syslog-ng
&nbsp;
    " COMMENTSTRING FOR VIM "{{{3
    au FileType vim setlocal commentstring="%s
&nbsp;
    " COMMENTSTRING FOR XDEFAULTS "{{{3
    au FileType xdefaults setlocal foldmethod=marker foldlevel=2 commentstring=!%s
&nbsp;
    " VIMRC {{{3
    augroup vimrc
      au BufReadPre * setlocal foldmethod=indent
      au BufWinEnter * if &amp;fdm == &#039;indent&#039; | set foldmethod=manual | endif
      au BufRead *.vim,vimrc,*.vimrc set filetype=vim ts=3 sw=3 tw=500 foldmethod=marker foldcolumn=6
    augroup END
&nbsp;
    " AUTOMKVIEWS {{{3
    " Warning - this will save your settings for each file you edit and restore those settings when opened again - can fill up quick
    au BufWinLeave *.sh,*.conf,*.vim,*.c,*.txt,.htaccess,*.cgi,*.php,*.html,*.conf,vimrc mkview
    au BufWinEnter *.sh,*.conf,*.vim,*.c,*.txt,.htaccess,*.cgi,*.php,*.html,*.conf,vimrc silent loadview
    " }}}3
&nbsp;
    " MAN RUNTIME - TODO REPLACE WITH TMUXES CTRL-M BINDING {{{3
    " Lets you type :Man anymanpage and it will load in vim, color-coded and searchable
    "runtime ftplugin/man.vim
&nbsp;
  endif
&nbsp;
endif
"}}}1
&nbsp;
" MAPS "{{{1
" ===========================================================================================================================================================================
&nbsp;
" FUNCTION MAPS {{{2
" ---------------------------------
" APPEND MODELINE {{{3
map &lt;silent&gt; &lt;LocalLeader&gt;ml :call AppendModeline()&lt;CR&gt;
&nbsp;
" SHOW WHITESPACE {{{3
nnoremap &lt;LocalLeader&gt;ts :call ToggleShowWhitespace()&lt;CR&gt;
&nbsp;
" SUDO A WRITE {{{3
command! W :execute &#039;:silent w !sudo tee % &gt; /dev/null&#039; | :edit!
"cmap w!! %!sudo tee &gt; /dev/null %
" :w !sudo tee &gt; /dev/null %
&nbsp;
" SET TABLINE {{{3
" My Personal Fav, inserts last-modified manually on current line when you press &lt;F12&gt; key
" call setline(1, printf(&#039;%sUpdated: %s by %s@%s&#039;, printf(&amp;commentstring, &#039; &#039;), strftime("%c"), expand("$LOGNAME"), hostname()))
if exists("*s:LastModNow")
  map &lt;silent&gt; &lt;F12&gt; :call LastModNow()&lt;CR&gt;
endif
&nbsp;
" RELOAD VIMRC FILES {{{3
map &lt;LocalLeader&gt;. :mkview&lt;CR&gt;:unlet! AskApacheLoaded autocommands_loaded&lt;CR&gt;:mapclear&lt;CR&gt;:source /etc/vimrc&lt;CR&gt;:echoerr &#039;VIMRC RELOADED&#039;&lt;CR&gt;
&nbsp;
" SCROLLING MAPS {{{3
map &lt;PageDown&gt; :set scroll=0&lt;CR&gt;:set scroll^=2&lt;CR&gt;:set scroll-=1&lt;CR&gt;&lt;C-D&gt;:set scroll=0&lt;CR&gt;
map &lt;PageUp&gt; :set scroll=0&lt;CR&gt;:set scroll^=2&lt;CR&gt;:set scroll-=1&lt;CR&gt;&lt;C-U&gt;:set scroll=0&lt;CR&gt;
nnoremap &lt;silent&gt; &lt;PageUp&gt; &lt;C-U&gt;&lt;C-U&gt;
vnoremap &lt;silent&gt; &lt;PageUp&gt; &lt;C-U&gt;&lt;C-U&gt;
inoremap &lt;silent&gt; &lt;PageUp&gt; &lt;C-\&gt;&lt;C-O&gt;&lt;C-U&gt;&lt;C-\&gt;&lt;C-O&gt;&lt;C-U&gt;
nnoremap &lt;silent&gt; &lt;PageDown&gt; &lt;C-D&gt;&lt;C-D&gt;
vnoremap &lt;silent&gt; &lt;PageDown&gt; &lt;C-D&gt;&lt;C-D&gt;
inoremap &lt;silent&gt; &lt;PageDown&gt; &lt;C-\&gt;&lt;C-O&gt;&lt;C-D&gt;&lt;C-\&gt;&lt;C-O&gt;&lt;C-D&gt;
"}}}3
&nbsp;
" KEY MAPS {{{2
" physically map keys to produce different key, type CTRL-V in insert mode followed by any key to see how vim sees it
" ----------------------------------------
imap &lt;ESC&gt;[8~ &lt;End&gt;
map &lt;ESC&gt;[8~ &lt;End&gt;
&nbsp;
imap &lt;ESC&gt;[7~ &lt;Home&gt;
map &lt;ESC&gt;[7~ &lt;Home&gt;
&nbsp;
" Basic Maps  {{{2
" ----------------------------------------
" TOGGLE PASTE MODE {{{3
map &lt;LocalLeader&gt;pm :set nonumber! foldcolumn=0&lt;CR&gt;
&nbsp;
" REINDENT FILE {{{3
map &lt;LocalLeader&gt;ri G=gg&lt;CR&gt;
&nbsp;
" CLEAR SPACES AT END OF LINE {{{3
map &lt;LocalLeader&gt;cs :%s/\s\+$//e&lt;CR&gt;
&nbsp;
" Y YANKS FROM CURSOR TO $ {{{3
map Y y$
&nbsp;
" DON&#039;T USE EX MODE, USE Q FOR FORMATTING {{{3
map Q gq
map! ^H ^?
&nbsp;
" NEXT SEARCH RESULT {{{3
map &lt;silent&gt; &lt;LocalLeader&gt;cn :cn&lt;CR&gt;
&nbsp;
" WRAP? {{{3
map &lt;silent&gt; &lt;LocalLeader&gt;ww :ww
&nbsp;
" ERR INSERTION {{{3
"map &lt;silent&gt; &lt;LocalLeader&gt;e &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s&#039;, &#039;_err "$0 $FUNCNAME:$LINENO FAILED WITH ARGS= $*"&#039;)&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
&nbsp;
" CUSTOM LINES FOR CODING {{{3
map &lt;silent&gt; &lt;LocalLeader&gt;l1 &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s%s&#039;, printf(&amp;commentstring, &#039; &#039;), repeat(&#039;=&#039;, 160))&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
map &lt;silent&gt; &lt;LocalLeader&gt;l2 &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s%s&#039;, printf(&amp;commentstring, &#039; &#039;), repeat(&#039;=&#039;, 80))&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
map &lt;silent&gt; &lt;LocalLeader&gt;l3 &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s%s&#039;, printf(&amp;commentstring, &#039; &#039;), repeat(&#039;-&#039;, 40))&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
map &lt;silent&gt; &lt;LocalLeader&gt;l4 &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s%s&#039;, printf(&amp;commentstring, &#039; &#039;), repeat(&#039;-&#039;, 20))&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
&nbsp;
" CHANGE DIRECTORY TO THAT OF CURRENT FILE {{{3
nmap &lt;LocalLeader&gt;cd :cd%:p:h&lt;CR&gt;
&nbsp;
" CHANGE LOCAL DIRECTORY TO THAT OF CURRENT FILE {{{3
nmap &lt;LocalLeader&gt;lcd :lcd%:p:h&lt;CR&gt;
&nbsp;
" TOGGLE WRAPPING {{{3
nmap &lt;LocalLeader&gt;ww :set wrap!&lt;CR&gt;
nmap &lt;LocalLeader&gt;wo :set wrap&lt;CR&gt;
&nbsp;
" TABS "{{{2
" ---------------------------------
&nbsp;
" CREATE A NEW TAB {{{3
map &lt;LocalLeader&gt;tc :tabnew %&lt;CR&gt;
&nbsp;
" LAST TAB {{{3
map &lt;LocalLeader&gt;t&lt;Space&gt; :tablast&lt;CR&gt;
&nbsp;
" CLOSE A TAB {{{3
map &lt;LocalLeader&gt;tk :tabclose&lt;CR&gt;
&nbsp;
" NEXT TAB {{{3
map &lt;LocalLeader&gt;tn :tabnext&lt;CR&gt;
&nbsp;
" PREVIOUS TAB {{{3
map &lt;LocalLeader&gt;tp :tabprev&lt;CR&gt;
&nbsp;
" FOLDS   "{{{2
" ---------------------------------
" Fold with paren begin/end matching
nmap F zf%
&nbsp;
" When I use ,sf - return to syntax folding with a big foldcolumn
nmap &lt;LocalLeader&gt;sf :set foldcolumn=6 foldmethod=syntax&lt;cr&gt;
"}}}2
&nbsp;
"}}}1
&nbsp;
" HILITE "{{{1
" ===========================================================================================================================================================================
hi NonText cterm=NONE ctermfg=NONE
hi Search cterm=bold ctermbg=99 ctermfg=17
"}}}
&nbsp;
</pre>


<h2>Colorscheme</h2>
<p>Here is a colorscheme file optimized for 256 colors.  It will work if saved in <code>~/.vim/colors/askapachecode.vim</code> or likewise in your runtimepath.  Additionally, you could just paste it in the bottom of the above vimrc.  The code really needs to be cleaned up, but it looks awesome.</p>
<p>Download - <a href='http://uploads.askapache.com/2012/02/askapachecode.txt'>askapachecode - 256 Colors Vim Colorscheme</a></p>
<p><code>~/.vim/colors/askapachecode.vim</code></p>
<pre>
" Vim color file -- askapachecode
" Maintainer: AskApache &lt;webmaster@askapache.com&gt;
" Updated: Wed Feb 22 14:10:54 2012 by galileo@galileo
&nbsp;
set background=dark
hi clear
&nbsp;
if exists("syntax_on")|syntax reset|endif
&nbsp;
let g:colors_name="askapachecode"
&nbsp;
" Vim &gt;= 7.0 specific colors
if version &gt;= 700
 hi CursorLine ctermbg=236
 hi CursorColumn ctermbg=236
 hi MatchParen ctermfg=157 ctermbg=237 cterm=bold
 hi Pmenu ctermfg=255 ctermbg=238
 hi PmenuSel ctermfg=0 ctermbg=148
endif
&nbsp;
" General colors
hi Cursor ctermbg=241
hi Normal ctermfg=253 ctermbg=232
hi NonText ctermfg=244 ctermbg=235
hi LineNr ctermfg=244 ctermbg=232
hi StatusLine ctermfg=253 ctermbg=238 cterm=italic
hi StatusLineNC ctermfg=246 ctermbg=238
hi VertSplit ctermfg=238 ctermbg=238
hi Folded ctermbg=4 ctermfg=248
hi Title ctermfg=254 cterm=bold
hi Visual ctermfg=254 ctermbg=4
hi SpecialKey ctermfg=244 ctermbg=236
&nbsp;
hi pythonOperator ctermfg=103
&nbsp;
hi Search cterm=NONE  
&nbsp;
" basic highlight groups (:help highlight-groups) {{{1
&nbsp;
" text {{{2
hi Normal ctermfg=white ctermbg=black cterm=NONE
hi Folded ctermfg=lightgray ctermbg=black cterm=underline
hi LineNr ctermfg=darkgray ctermbg=NONE cterm=NONE
hi Directory ctermfg=cyan ctermbg=NONE cterm=NONE
hi NonText ctermfg=yellow ctermbg=NONE cterm=NONE
hi SpecialKey ctermfg=green ctermbg=NONE cterm=NONE
&nbsp;
hi DiffAdd ctermfg=white ctermbg=darkblue cterm=NONE
hi DiffChange ctermfg=black ctermbg=darkmagenta cterm=NONE
hi DiffDelete ctermfg=black ctermbg=red cterm=bold
hi DiffText ctermfg=white ctermbg=green cterm=bold
&nbsp;
" borders / separators / menus {{{2
hi FoldColumn ctermfg=lightgray ctermbg=darkgray cterm=NONE
hi SignColumn ctermfg=lightgray ctermbg=darkgray cterm=NONE
hi Pmenu ctermfg=white ctermbg=darkgray cterm=NONE
hi PmenuSel ctermfg=white ctermbg=lightblue cterm=NONE
hi PmenuSbar ctermfg=black ctermbg=black cterm=NONE
hi PmenuThumb ctermfg=gray ctermbg=gray cterm=NONE
&nbsp;
hi StatusLine ctermfg=black ctermbg=white cterm=bold
hi StatusLineNC ctermfg=darkgray ctermbg=white cterm=NONE
hi WildMenu ctermfg=white ctermbg=darkblue cterm=bold
hi VertSplit ctermfg=white ctermbg=white cterm=NONE
&nbsp;
if &amp;t_Co == 256|hi TabLine ctermfg=15 ctermbg=242 term=underline|else|hi TabLine ctermfg=grey ctermbg=white term=underline|endif
"hi TabLine ctermfg=white ctermbg=white cterm=NONE
hi TabLineFill ctermfg=grey ctermbg=white cterm=NONE
"hi TabLineSel ctermfg=black ctermbg=green cterm=NONE
hi TabLineSel ctermfg=green ctermbg=black term=bold
"hi TabLineSel term=bold cterm=bold
"hi TabLineFill term=reverse cterm=reverse 
"hi TabLine term=underline cterm=underline ctermfg=15 ctermbg=242
&nbsp;
"hi Menu
"hi Scrollbar
"hi Tooltip
&nbsp;
" cursor / dynamic / other {{{2
hi Cursor ctermfg=black ctermbg=white cterm=NONE
hi CursorIM ctermfg=black ctermbg=white cterm=reverse
hi CursorLine ctermfg=NONE ctermbg=NONE cterm=NONE
hi CursorColumn ctermfg=NONE ctermbg=NONE cterm=NONE
&nbsp;
hi Visual ctermfg=white ctermbg=lightblue cterm=NONE
hi IncSearch ctermfg=white ctermbg=yellow cterm=NONE
hi Search ctermfg=white ctermbg=darkgreen cterm=NONE
&nbsp;
" LISTINGS / MESSAGES {{{2
hi ModeMsg ctermfg=yellow ctermbg=NONE cterm=NONE
hi Title ctermfg=red ctermbg=NONE cterm=bold
hi Question ctermfg=green ctermbg=NONE cterm=NONE
hi MoreMsg ctermfg=green ctermbg=NONE cterm=NONE
hi ErrorMsg ctermfg=white ctermbg=red cterm=bold
hi WarningMsg ctermfg=yellow ctermbg=NONE cterm=bold
&nbsp;
hi Directory term=bold ctermfg=4 "{{{
hi ErrorMsg term=standout ctermfg=15 ctermbg=1  
hi IncSearch term=reverse cterm=reverse 
hi Search term=NONE ctermfg=255 ctermbg=135
hi MoreMsg term=bold ctermfg=2  
hi ModeMsg term=bold cterm=bold 
hi LineNr term=underline ctermfg=244 ctermbg=232  
hi Question term=standout ctermfg=2  
hi StatusLine term=bold,reverse cterm=italic ctermfg=253 ctermbg=238   
hi StatusLineNC term=reverse cterm=reverse ctermfg=246 ctermbg=238  
hi VertSplit term=reverse cterm=reverse ctermfg=238 ctermbg=238  
hi Title term=bold cterm=bold ctermfg=254  
hi Visual term=reverse ctermfg=254 ctermbg=4  
hi VisualNOS term=bold,underline cterm=bold,underline
hi WarningMsg term=standout ctermfg=1 
hi WildMenu term=standout ctermfg=0 ctermbg=11  
hi Folded term=standout cterm=BOLD ctermfg=7 ctermbg=27
hi FoldColumn term=NONE cterm=NONE ctermfg=75 ctermbg=16
hi IncSearch term=bold,underline cterm=bold,underline ctermfg=7 ctermbg=9
hi DiffAdd term=bold ctermbg=12 
hi DiffChange term=bold ctermbg=13 
hi DiffDelete term=bold ctermfg=12 ctermbg=14   
hi DiffText term=reverse cterm=bold ctermbg=9  
hi SpellBad term=reverse ctermbg=9  
hi SpellCap term=reverse ctermbg=12  
hi SpellRare term=reverse ctermbg=13  
hi SpellLocal term=underline ctermbg=14  
hi Pmenu ctermfg=255 ctermbg=238  
hi PmenuSel ctermfg=0 ctermbg=148  
hi PmenuSbar ctermbg=7 
hi PmenuThumb cterm=reverse 
hi TabLine term=underline cterm=underline ctermfg=0 ctermbg=7  
hi TabLineSel term=bold cterm=bold 
hi TabLineFill term=reverse cterm=reverse 
hi CursorLine term=underline cterm=bold ctermbg=234
hi Cursor ctermbg=241 
hi MatchParen term=reverse cterm=bold ctermfg=157 ctermbg=237   
hi Error term=reverse ctermfg=15 ctermbg=9  
&nbsp;
" :hi TabLineSel|hi TabLineFill|hi TabLine
"hi TabLineSel term=bold cterm=bold 
"hi TabLineFill term=reverse cterm=reverse 
"hi TabLine term=underline cterm=underline ctermfg=15 ctermbg=242 
hi ExtraWhitespace ctermbg=red
hi Comment term=none ctermfg=darkgrey 
hi Constant term=underline ctermfg=Magenta 
hi Special term=bold ctermfg=DarkMagenta 
hi Identifier term=underline cterm=bold ctermfg=Cyan 
hi Statement term=bold ctermfg=Yellow 
hi PreProc term=underline ctermfg=LightBlue 
hi Type term=underline ctermfg=LightGreen 
hi Repeat term=underline ctermfg=White 
hi Operator ctermfg=Red 
hi Ignore ctermfg=black 
hi Error term=reverse ctermbg=Red ctermfg=White 
hi Todo term=standout ctermbg=Yellow ctermfg=Black 
&nbsp;
" COMMON GROUPS THAT LINK TO DEFAULT HIGHLIGHTING.
&nbsp;
hi Function ctermfg=85
hi String ctermfg=204
hi Statement term=bold cterm=bold ctermfg=81
hi Function term=bold cterm=bold ctermfg=32
hi Number ctermfg=129
hi Conditional term=bold cterm=bold ctermfg=47
hi Special term=underline ctermfg=191
hi Normal ctermfg=7
hi PreProc ctermfg=141
" Syntax highlighting
hi Comment ctermfg=244
hi Todo ctermfg=245
hi Boolean ctermfg=148
hi String ctermfg=148
hi Identifier ctermfg=148
hi Function ctermfg=124
hi Type ctermfg=103
hi Statement ctermfg=103
hi Keyword ctermfg=81
hi Constant ctermfg=81
hi Number ctermfg=81
hi Special ctermfg=81
hi PreProc ctermfg=230
" Code-specific colors
 
&nbsp;
" SYNTAX HIGHLIGHTING GROUPS (:HELP GROUP-NAME) {{{2
hi FoldColumn ctermbg=0 ctermfg=2
hi Folded cterm=none ctermfg=2
hi NonText cterm=NONE ctermfg=NONE 
hi StatusLine ctermfg=black ctermbg=White cterm=bold
hi StatusLineNC ctermfg=White ctermbg=green cterm=NONE
hi CursorLine cterm=bold term=bold
&nbsp;
" FINAL THOUGHTS "{{{2
"syn region myFold start="{" end="}" transparent fold
hi Search term=reverse ctermfg=0 ctermbg=11
hi LineNr term=underline ctermfg=244 ctermbg=232
hi MatchParen ctermfg=15 ctermbg=242
hi String ctermfg=10
hi Constant ctermfg=14
hi Identifier ctermfg=14
hi Operator ctermfg=13
hi NonText cterm=NONE ctermfg=NONE
hi Search cterm=bold ctermbg=99 ctermfg=17
</pre>


<h2>Additional Resources</h2>
<ol>
<li><a href="http://spf13.com/post/perfect-vimrc-vim-config-file">The perfect .vimrc vim config file</a></li>
</ol><p><a href="http://www.askapache.com/linux/fast-vimrc.html"></a><a href="http://www.askapache.com/linux/fast-vimrc.html">Optimized Vimrc with 256 Colorscheme</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/linux/fast-vimrc.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Programming Fonts for the Web</title>
		<link>http://www.askapache.com/css/programming-fonts-code.html</link>
		<comments>http://www.askapache.com/css/programming-fonts-code.html#comments</comments>
		<pubDate>Sat, 29 Oct 2011 09:37:43 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4809</guid>
		<description><![CDATA[<p>The idea is to use CSS to have the browser display programming and code similar to the high-quality look of a developers machine, like this older screenshot of my VIM.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/css/programming-fonts-code.html"></a><a href="http://www.askapache.com/css/programming-fonts-code.html"><cite>AskApache.com</cite></a></p><p>The idea is to have the browser display programming and code similar to the high-quality found on a developers machine, like this older screenshot of my vim. <br /><a href="http://www.askapache.com/linux/bash-power-prompt.html/bash-prompt-screenshot/" rel="attachment wp-att-4177"><img src="http://uploads.askapache.com/2010/03/bash-prompt-screenshot.png" alt="Custom Power Prompt" title="Custom Power Prompt" width="795" height="596" /></a></p>
<p>The most important step is to figure out the font-family and the basic font-attributes.  You want to show the best font for those visitors (like me) who have all these extra console fonts, but fallback to a font that anyone in the world can view.</p>

<h2>Monospace is the fallback</h2>
<blockquote cite="http://www.w3.org/TR/CSS2/fonts.html">
<h4><a href="http://www.w3.org/TR/CSS2/fonts.html">15.3.1.5 <dfn>monospace</dfn></a></h4>
<p><p>The sole criterion of a monospace font is that all glyphs have the same fixed width. (This can make some scripts, such as Arabic, look most peculiar.) The effect is similar to a manual typewriter, and is often used to set samples of computer code.</p>
</blockquote>



<h2>CSS Rules for Code</h2>
<p>Here are a few css rules I use.  That is my ultimate font-family heirarchy of console-type fonts, though not many people have them installed.  The fallback is usually Andale Mono, Monaco, or DejaVu Sans Mono, Lucida Console, Bitstream, then Courier.</p>
<pre>kbd, samp, tt, pre, code, var,
.code, .pre {
   font-family: Terminus,Consolas,Profont,"Andale Mono",Monaco,Inconsolata,Inconsolata-g,
      Unifont,Lime,"ClearlyU PUA",Clean,"DejaVu Sans Mono","Lucida Console",
      "Bitstream Vera Sans Mono",Freemono,"Liberation Mono",Dina,Anka,Droid Sans Mono,
      Anonymous Pro,Proggy fonts,Envy Code R,Gamow,Courier,"Courier New",Terminal,monospace;
}</pre>

<p>This is just some basic pre attributes, useful as a reset or to force the issue.  You may just want to do <code>.pre {...}</code> to apply to elements with <code>class="pre"</code> instead of applying to all pre elements sitewide.</p>
<pre>pre { letter-spacing:normal; word-spacing:normal; text-transform:none; max-width:100%; overflow:auto; white-space:pre-wrap; }
pre.normal { white-space:normal }</pre>


<h2>Live Font Examples</h2>
<p>What you see is what you get, so experiment with different browsers.</p>
<ul>
<li><a id="font-Courier" name="font-Courier">Courier</a><br />
<pre style='font-family:Courier,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Courier-New" name="font-Courier-New">Courier New</a><br />
<pre style='font-family:Courier New,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Terminal" name="font-Terminal">Terminal</a><br />
<pre style='font-family:Terminal,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Agency-FB-Bold" name="Agency-FB-Bold">Agency FB Bold</a><br />
<pre style='font-family:Agency FB Bold,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Consolas" name="font-Consolas">Consolas</a><br />
<pre style='font-family:Consolas,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Terminus" name="font-Terminus">Terminus</a><br />
<pre style='font-family:Terminus,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Profont" name="font-Profont">Profont</a><br />
<pre style='font-family:Profont,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Andale-Mono" name="font-Andale-Mono">Andale Mono</a><br />
<pre style='font-family:Andale Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Monaco" name="font-Monaco">Monaco</a><br />
<pre style='font-family:Monaco,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Inconsolata" name="font-Inconsolata">Inconsolata</a><br />
<pre style='font-family:Inconsolata,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Inconsolata-g" name="font-Inconsolata-g">Inconsolata-g</a><br />
<pre style='font-family:Inconsolata-g,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Unifont" name="font-Unifont">Unifont</a><br />
<pre style='font-family:Unifont,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Lime" name="font-Lime">Lime</a><br />
<pre style='font-family:Lime,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-ClearlyU-PUA" name="font-ClearlyU-PUA">ClearlyU PUA</a><br />
<pre style='font-family:ClearlyU PUA,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Clean" name="font-Clean">Clean</a><br />
<pre style='font-family:Clean,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-DejaVu-Sans-Mono" name="font-DejaVu-Sans-Mono">DejaVu Sans Mono</a><br />
<pre style='font-family:DejaVu Sans Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Lucida-Console" name="font-Lucida-Console">Lucida Console</a><br />
<pre style='font-family:Lucida Console,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Bitstream-Vera-Sans-Mono" name="font-Bitstream-Vera-Sans-Mono">Bitstream Vera Sans Mono</a><br />
<pre style='font-family:Bitstream Vera Sans Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Freemono" name="font-Freemono">Freemono</a><br />

<pre style='font-family:Freemono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Liberation-Mono" name="font-Liberation-Mono">Liberation Mono</a><br />
<pre style='font-family:Liberation Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Dina" name="font-Dina">Dina</a><br />
<pre style='font-family:Dina,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Anka" name="font-Anka">Anka</a><br />
<pre style='font-family:Anka,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Droid-Sans-Mono" name="font-Droid-Sans-Mono">Droid Sans Mono</a><br />
<pre style='font-family:Droid Sans Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Anonymous-Pro" name="font-Anonymous-Pro">Anonymous Pro</a><br />
<pre style='font-family:Anonymous Pro,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Proggy-fonts" name="font-Proggy-fonts">Proggy fonts</a><br />
<pre style='font-family:Proggy fonts,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Envy-Code-R" name="font-Envy-Code-R">Envy-Code-R</a><br />
<pre style='font-family:Envy Code R,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Gamow" name="font-Gamow">Gamow</a><br />
<pre style='font-family:Gamow,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
</ul>



<h2>More Info and Software</h2>
<ul>
<li><a href="http://www.w3.org/Style/Examples/007/fonts#font-family">CSS Font Families Example at W3</a></li>
<li><a href="http://www.lowing.org/fonts/">Monospace/Fixed Width Programmer's Fonts</a></li>
<li><a href="http://www.nirsoft.net/utils/windows_fonts_viewer.html">WinFontsView v1.10 - View samples of Windows fonts installed on your system </a></li>
</ul>



<p><a class="hs hs13" href="http://www.askapache.com/servers/mod_rewrite.c.html"></a></p><p><a href="http://www.askapache.com/css/programming-fonts-code.html"></a><a href="http://www.askapache.com/css/programming-fonts-code.html">Programming Fonts for the Web</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/css/programming-fonts-code.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Advanced Linux Debugging using a Bootloader (GRUB)</title>
		<link>http://www.askapache.com/linux/advanced-linux-grub.html</link>
		<comments>http://www.askapache.com/linux/advanced-linux-grub.html#comments</comments>
		<pubDate>Thu, 07 Apr 2011 16:35:41 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4846</guid>
		<description><![CDATA[<p>As an example, here is the boot line that I am using at the moment on an older Dell Desktop, just to illustrate module parameters and environment vars.  </p>
<pre>title  Arch Linux X-256
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait pause_on_oops=5 panic=60 i915.modeset=1 no_console_suspend ipv6.disable=1 TERM=xterm-256color quiet 5
initrd /kernel26.img</pre>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/linux/advanced-linux-grub.html"></a><a href="http://www.askapache.com/linux/advanced-linux-grub.html"><cite>AskApache.com</cite></a></p><p>This is part of the <a href="https://wiki.archlinux.org/index.php/GRUB">GRUB article on the Arch Linux wiki that I contributed</a>.   As of now, just a copy.</p>

<p>The grub <code>menu.lst</code> provides for a convenient way to add a number of entries with <a href="http://www.kernel.org/doc/Documentation/kernel-parameters.txt" class="external text" rel="nofollow">extended kernel parameters</a> to configure all sorts of advanced settings to enable you to quickly and conveniently boot into your existing system with varying levels of debugging output.  It's very easy and useful to create several levels of debugging just by adding additional entries to your grub configuration. And if you ever have issues or problems down the road due to a power-failure or hardware failure, it can save you hours of trouble, and of course nothing can beat debugging output when it comes to learning about your system.</p>

<h2><span class="mw-headline" id="Useful_Menu.lst_Entries">Useful Menu.lst Entries</span></h2>
<p>If you are interested in debugging, then you deserve some grub entries for powerusers, here are a few that I like (just add to your <code>menu.lst</code>).</p>

<pre>title Shutdown the Computer
halt
&nbsp;
title Reboot the Computer
reboot
&nbsp;
title Command Line
commandline
&nbsp;
title Install GRUB to hd0 MBR
root (hd0,0)
setup (hd0)
&nbsp;
title Matrix
color green/black light-green/green
&nbsp;
title Scan for /boot/grub/menu.lst
find --set-root --ignore-floppies /boot/grub/menu.lst
configfile /boot/grub/menu.lst
&nbsp;
title Scan for /boot/menu.lst
find --set-root --ignore-floppies /menu.lst
configfile /boot/menu.lst
&nbsp;
# http://www.vortex.prodigynet.co.uk/x86test/
title    Run x86test (CPU Info)
kernel /boot/x86test_zImage.bin
#wget http://www.vortex.prodigynet.co.uk/x86test/x86test_zImage.bin
&nbsp;
# http://www.memtest.org/
title    Run memtest86+ (Memory Testing)
kernel /boot/memtest86+-1.70.bin</pre>

<h2> <span class="mw-headline" id="Light_Debug">Light Debug</span></h2>
<p>A quick way to see more verbose messages on your console is to bootup your normal grub entry after appending <strong>verbose</strong> to the kernel line.  This simple word added to your kernel line turns on more logging thanks to the <code>/etc/rc.sysinit</code> file, which at the top of the file runs:</p>
<pre>if /bin/grep -q " verbose" /proc/cmdline; then /bin/dmesg -n 8; fi</pre>
<p>Very simple way to get a bit more messages and debug output in your logs.</p>
<pre>title  Arch Linux DEBUG Light
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait verbose
initrd /kernel26.img</pre>

<h2> <span class="mw-headline" id="Medium_Debug">Medium Debug</span></h2>
<p>This example <code>menu.lst</code> entry turns on real logging that is set by the kernel and not in an init script.  Adding the <strong>debug</strong> kernel parameter to your kernel line is recognized by a lot of linux internals and enables quite a bit of debugging compared to the default. </p>

<pre>title Arch Linux DEBUG Medium
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootdelay=5 panic=10 debug
initrd /kernel26.img</pre>

<h2> <span class="mw-headline" id="Heavy_Debug">Heavy Debug</span></h2>
<p>An even more impressive kernel parameter is the <strong>ignore_loglevel</strong>, which causes the system to ignore any loglevel and keeps the internal loglevel at the maximum debugging level, basically rendering dmesg unable to lower the debug level.</p>
<pre>title Arch Linux DEBUG Heavy
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootdelay=5 panic=10 debug ignore_loglevel
initrd /kernel26.img</pre>

<h2> <span class="mw-headline" id="Extreme_Debug">Extreme Debug</span></h2>
<p>If the "Heavy Debug" seemed like a lot of output, thats about 1/2 of the logging that occurs with this example.  This does a couple things, it uses the <strong>earlyprintk</strong> parameter to setup your kernel for "early" "printing" of messages to your "vga" screen.  The <strong>,keep</strong> just lets it stay on the screen longer.  This will let you see logs that normally are hidden due to the boot-up process.
This also changes the log buffer length to 10MB, and also instructs that any fatal signals be printed with <strong>print_fatal_signals</strong>.  The last one, <strong>sched_debug</strong>, you can look up in the very excellent kernel documentation on <a href="http://www.kernel.org/doc/Documentation/kernel-parameters.txt" class="external text" rel="nofollow">kernel parameters</a>.</p>

<pre>title Arch Linux DEBUG Extreme
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro debug ignore_loglevel log_buf_len=10M print_fatal_signals=1 LOGLEVEL=8 earlyprintk=vga,keep sched_debug
initrd /kernel26.img</pre>

<h2> <span class="mw-headline" id="Insane_Debug">Insane Debug</span></h2>
<p>The first few debugging examples showed some really nice kernel parameters to turn on really verbose debugging.  This kind of debugging is absolutely critical if you want to max out your system or just learn more about what is going on behind the scenes.  But there is a final trick that is my favorite, it's the ability to set both environment variables, and more importantly, module parameters at boot.</p>

<p>As an example, here is the boot line that I am using at the moment on an older Dell Desktop, just to illustrate module parameters and environment vars.  </p>
<pre>title  Arch Linux X-256
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait pause_on_oops=5 panic=60 i915.modeset=1 no_console_suspend ipv6.disable=1 TERM=xterm-256color quiet 5
initrd /kernel26.img</pre>
<p>Since it's low on both memory and CPU, I disable ipv6. I also turn on kernel modesetting for the i915 video card, set my terminal to be xterm-256color, and boot straight into <a href="https://wiki.archlinux.org/index.php/Xorg" title="Xorg">X</a>.  This lets me use a very optimized arch-linux configuration, amazing how fast thanks to using <a href="https://wiki.archlinux.org/index.php/SLiM" title="SLiM">slim</a> as the login manager, <a href="https://wiki.archlinux.org/index.php/Ratpoison" title="Ratpoison">ratpoison</a> as my <a href="https://wiki.archlinux.org/index.php/Display_Manager" title="Display Manager">window manager</a>, and terminal with <a href="https://wiki.archlinux.org/index.php/Tmux" title="Tmux">tmux</a> as my login shell, all from boot, as the pstree shows (plus <a href="https://wiki.archlinux.org/index.php/Synergy" title="Synergy">Synergy</a>!).</p>
<pre>init,1
  |-slim,3096
  |   |-X,3098 -nolisten tcp vt07 -auth /var/run/slim.auth
  |   `-ratpoison,3107,askapache
  |       |-terminal,5341 -x sh -c exec /usr/bin/tmux -2 -l -u -q attach -d -t tmux-askapache
  |       |   |-bash,11165
  |       |   |-tmux,5345 -2 -l -u -q attach -d -t tmux-askapache
  |       |   `-{terminal},5346
  |       `-xscreensaver,3113 -no-splash
  |-synergyc,6121,galileo -f --name galileo-fire --restart 10.66.66.2:26666
  |
  `-tmux,5348,askapache -2 -l -u -q attach -d -t tmux-askapache
      |-bash,5351
      |   `-ssh,9969 lug@askapache.com
      `-bash,5868
         `-vim,11149 -p sda1/grub/menu.lst /boot/grub/menu.lst</pre>
<p>That kind of optimized system is only possible if you first can figure out your system, by debugging both the kernel as previously illustrated, debugging the init process, and most importantly, by debugging the modules enabled for your system's hardware/firmware/software.  Debugging modules is challenging but worth the effort, and then you are able to do some truly insane debugging from grub like the following example, note that the actual grub entry is all on one line, but I split it into 4 lines so you could see it all.  This basically turns on every module on this little Dell desktop to be at the absolute max debug level.  There is so much logging when I boot this that the system grinds to a halt and is slower than a TI-89 calculator (See <a href="https://wiki.archlinux.org/index.php/Improve_Boot_Performance" title="Improve Boot Performance">Improve Boot Performance</a>).</p>
<pre>title  Arch Linux DEBUG INSANE
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait ignore_loglevel debug debug_locks_verbose=1 sched_debug initcall_debug mminit_loglevel=4 udev.log_priority=8
       loglevel=8 earlyprintk=vga,keep log_buf_len=10M print_fatal_signals=1 apm.debug=Y i8042.debug=Y drm.debug=1 scsi_logging_level=1 usbserial.debug=Y
       option.debug=Y pl2303.debug=Y firewire_ohci.debug=1 hid.debug=1 pci_hotplug.debug=Y pci_hotplug.debug_acpi=Y shpchp.shpchp_debug=Y apic=debug
       show_lapic=all hpet=verbose lmb=debug pause_on_oops=5 panic=10 sysrq_always_enabled
initrd /kernel26.img</pre>
<p>A couple key items from that grub entry are <strong>sysrq_always_enabled</strong> which forces on the sysrq magic, which really is a lifesaver when debugging at this level as your machine will freeze/stop-responding sometimes and it's nice to use sysrq to kill all tasks, change the loglevel, unmount all filesystems, or do a hard reboot.  Another key parameter is the <strong>initcall_debug</strong>, which debugs the init process in excruciating detail.  Very useful at times.  The last parametery I find very useful is the <strong>udev.log_priority=8</strong> to turn on <a href="https://wiki.archlinux.org/index.php/Udev" title="Udev">udev</a> logging.  </p>


<h2><span class="mw-headline" id="Break_Into_Init">Break Into Init</span></h2>
<p>For instance, If you add <strong>break=y</strong> to your kernel cmdline, init will pause early in the <a href="https://wiki.archlinux.org/index.php/Arch_Boot_Process" title="Arch Boot Process">boot process</a> (after loading modules) and launch an interactive sh shell which can be used for troubleshooting purposes. (Normal boot continues after logout.)  This is very similar to the shell that shows up if your computer gets turned off before it is able to shutdown properly.  But using this parameter lets you enter into this mode differently at will.</p>
<pre>title  Arch Linux Init Break
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait break=y
initrd /kernel26.img</pre>

<h2><span class="mw-headline" id="Debugging_init">Debugging init</span></h2>

<p>This awesome parameter <strong>udev.log_priority=8</strong> does the same thing as editing the file <code>/etc/udev/udev.conf</code> except it executes earlier, turning on debugging output for <a href="https://wiki.archlinux.org/index.php/Udev" title="Udev">udev</a>.  If you want to know your hardware, that is the key parameter right there.  Another trick is if you change the <code>/etc/udev/udev.conf</code> to be verbose, then you can make your initrd image include that file to turn on verbose udeb debugging by adding it to your {{Filename|/etc/mkinitcpio.conf} like:</p>
<pre>FILES="/etc/modprobe.d/modprobe.conf /etc/udev/udev.conf"</pre>
<p>, which on arch is as easy as </p>
<pre># mkinitcpio -p kernel26</pre>
<p>Debugging <a href="https://wiki.archlinux.org/index.php/Udev" title="Udev">udev</a> is key because the <a href="https://wiki.archlinux.org/index.php/Initrd" title="Initrd">initrd</a> performs a <a href="https://wiki.archlinux.org/index.php/Change_Root" title="Change Root">root change</a> at the end of its run to usually launch a program like /sbin/init as part of a chroot, and unless the new file system has a valid /dev directory, udev must be initialized before invoking chroot in order to provide <code>/dev/console</code>.  </p>
<pre>exec chroot . /sbin/init &lt;dev/console &gt;dev/console 2&gt;&amp;1</pre>
<p>So basically, you aren't able to view the logs that are generated before /dev/console is initialized by udev or by a special initrd you compiled yourself.  One method the kernel developers use to be able to still get the log messages generated before /dev/console is available is to provide an alternative console that you can enable or disable from grub.</p>



<h2><span class="mw-headline" id="Net_Console">Net Console</span></h2>
<p>If you read through the kernel documentation regarding debugging, you will hear about Netconsole, which can be loaded from the kernel line in GRUB, compiled into your kernel, or loaded at runtime as a module.  Having a netconsole entry in your <code>menu.lst</code> is most excellent for debugging slower computers like old laptops or thin-clients.  It's easy to use.  Just setup a 2nd computer (running arch) to accept syslog requests on a remote port, very fast and quick to do on arch-linux, 1 line to syslog.conf.  Then you could use a log-color-parser like ccze to view all syslog logs, or just tail your everything.log. Then on your laptop, boot up and select the netconsole entry from the grub menu, and you will start seeing as much logging as you want on your syslog system.  This logging lets you view even earlier log output than is available with the earlyprintk=vga kernel parameter, as netconsole is used by kernel hackers and developers, so it's very powerful.</p>
<pre>title  Arch Linux DEBUG Netconsole
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro netconsole=514@10.0.0.2/12:34:56:78:9a:bc debug ignore_loglevel
initrd /kernel26.img</pre>

<h2><span class="mw-headline" id="Hijacking_cmdline">Hijacking cmdline</span></h2>
<p>If you do not have access to GRUB or the kernel boottime cmdline, like on a server or virtual machine, as long as you have root permissions you can still enable this kind of simplistic verbose logging using a neat hack.  While you cannot modify the <code>/proc/cmdline</code> even as root, you can place your own cmdline file on top of /proc/cmdline, so that accessing /proc/cmdline actually accesses your file.</p>
<p>For example if I <strong>cat /proc/cmdline</strong>, I have the following:</p>
<pre>root=/dev/disk/by-label/ROOT ro console=tty1 logo.nologo quiet</pre>
<p>So I use a simple sed command to replace <strong>quiet</strong> with <strong>verbose</strong> like:</p>
<pre>sed &#039;s/ quiet/ verbose/&#039; /proc/cmdline &gt; /root/cmdline</pre>
<p>Then I bind mount /root/cmdline so that it becomes /proc/cmdline, using the <strong>-n</strong> option to mount so that this mount won't be recorded in the systems mtab.</p>
<pre>mount -n --bind -o ro /root/cmdline /proc/cmdline</pre>
<p>Now if I <strong>cat /proc/cmdline</strong>, I have the following:</p>
<pre>root=/dev/disk/by-label/ROOT ro console=tty1 logo.nologo verbose</pre><p><a href="http://www.askapache.com/linux/advanced-linux-grub.html"></a><a href="http://www.askapache.com/linux/advanced-linux-grub.html">Advanced Linux Debugging using a Bootloader (GRUB)</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/linux/advanced-linux-grub.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ultimate Htaccess Part II</title>
		<link>http://www.askapache.com/htaccess/apache-htaccess-2.html</link>
		<comments>http://www.askapache.com/htaccess/apache-htaccess-2.html#comments</comments>
		<pubDate>Sat, 16 Oct 2010 16:11:33 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4693</guid>
		<description><![CDATA[<p><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html"><img src="http://uploads.askapache.com/2010/10/htaccess-editing-350x243.png" alt="Editing an Apache .htaccess file in VIM." title="htaccess editing" width="350" height="243" class="size-medium wp-image-4700" /></a>  Here is even more information from the <a href="http://www.askapache.com/htaccess/htaccess.html">Ultimate Htaccess Part I</a>.  For now this is very rough and you will want to come back later to read it.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html"></a><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" href="http://www.askapache.com/htaccess/apache-htaccess-2.html"><img src="http://uploads.askapache.com/2010/10/htaccess-editing-350x243.png" alt="Editing an Apache .htaccess file in VIM." title="htaccess editing" width="350" height="243" class="size-medium wp-image-4700" /></a>  Here is even more information from the <a href="http://www.askapache.com/htaccess/htaccess.html">Ultimate Htaccess Part I</a>.  For now this is very rough and you will want to come back later to read it.</p>



<p><a id="htaccess-merging-order"></a></p><h3>Merging Notes</h3>
<p>The order of merging is:</p>
<ol>
<li><code>&lt;Directory&gt;</code> (except regular expressions) and .htaccess done simultaneously (with .htaccess, if allowed, overriding <code>&lt;Directory&gt;</code>)</li>
<li><code>&lt;DirectoryMatch&gt;</code> (and <code>&lt;Directory ~&gt;</code>)</li>
<li><code>&lt;Files&gt;</code> and <code>&lt;FilesMatch&gt;</code> done simultaneously</li>
<li><code>&lt;Location&gt;</code> and <code>&lt;LocationMatch&gt;</code> done simultaneously</li>
</ol>
<p>Below is an artificial example to show the order of merging. Assuming they all apply to the request, the directives in this example will be applied in the order:</p>
<p><code>A &gt; B &gt; C &gt; D &gt; E</code></p>.
<pre>&lt;Location /&gt;
E
&lt;/Location&gt;
&lt;Files askapache.txt&gt;
D
&lt;/Files&gt;
&lt;VirtualHost *&gt;
&lt;Directory /a/b&gt;
B
&lt;/Directory&gt;
&lt;/VirtualHost&gt;
&lt;DirectoryMatch "^.*b$"&gt;
C
&lt;/DirectoryMatch&gt;
&lt;Directory /a/b&gt;
A
&lt;/Directory&gt;</pre>







<p><a id="htaccess-software"></a></p><h2>Htaccess Software</h2>
<p>Apache HTTP Server comes with the following <a href="http://httpd.apache.org/docs/trunk/programs/">programs</a>.</p>
<dl><dt><code>httpd</code></dt><dd>Apache hypertext transfer protocol server</dd><dt><code>apachectl</code></dt><dd>Apache HTTP server control interface</dd><dt><code>ab</code></dt><dd>Apache HTTP server benchmarking tool</dd><dt><code>apxs</code></dt><dd>APache eXtenSion tool</dd><dt><code>dbmmanage</code></dt><dd>Create and update user authentication files in DBM format for basic authentication</dd><dt><code>fcgistarter</code></dt><dd>Start a FastCGI program</dd><dt><code>htcacheclean</code></dt><dd>Clean up the disk cache</dd><dt><code>htdigest</code></dt><dd>Create and update user authentication files for digest authentication</dd><dt><code>htdbm</code></dt><dd>Manipulate DBM password databases.</dd><dt><code>htpasswd</code></dt><dd>Create and update user authentication files for basic authentication</dd><dt><code>httxt2dbm</code></dt><dd>Create dbm files for use with RewriteMap</dd><dt><code>logresolve</code></dt><dd>Resolve hostnames for IP-addresses in Apache logfiles</dd><dt>log_server_status</dt><dd>Periodically log the server's status</dd><dt><code>rotatelogs</code></dt><dd>Rotate Apache logs without having to kill the server</dd><dt>split-logfile</dt><dd>Split a multi-vhost logfile into per-host logfiles</dd><dt><code>suexec</code></dt><dd>Switch User For Exec</dd></dl>


<pre>Options All
AuthType "Basic"
AuthName "Protected Access"
&nbsp;
#SetEnv APPLICATION_ENV production
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
&nbsp;
ErrorDocument 404 /index.php
&nbsp;
AddType text/html url
&nbsp;
order allow,deny
allow from all
Options +ExecCGI
&nbsp;
AddHandler python-program .py
PythonHandler mod_python.publisher
PythonDebug On
PythonAutoReload On
&nbsp;
RewriteEngine on
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
&nbsp;
# updating tab.ser takes lots of memory
php_value memory_limit 64000000
&nbsp;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
&nbsp;
php_flag magic_quotes_gpc Off
php_flag magic_quotes_runtime Off
&nbsp;
# redirect moved files
RedirectMatch Permanent ^/fop/anttask(.*) http://xmlgraphics.apache.org/fop/0.20.5/anttask$1
RedirectMatch Permanent ^/fop/compiling(.*) http://xmlgraphics.apache.org/fop/0.20.5/compiling$1
RedirectMatch Permanent ^/fop/configuration(.*) http://xmlgraphics.apache.org/fop/0.20.5/configuration$1
RedirectMatch Permanent ^/fop/embedding(.*) http://xmlgraphics.apache.org/fop/0.20.5/embedding$1
&nbsp;
&lt;IfModule mod_expires.c&gt;
ExpiresActive On
ExpiresDefault "access plus 52 weeks"
&lt;/IfModule&gt;
&nbsp;
# $Id: .htaccess 1255 2003-12-21 05:30:57Z rufustfirefly $
# $Author: rufustfirefly $
#
# Since sometimes Apache isn&#039;t properly configured to view the
# proper PHP script, we do this instead, but only if PHP4 is
&nbsp;
&lt;IfModule mod_access.c&gt;
&lt;Files ~ "^wanewsletter"&gt;
Order Allow,Deny
Allow from 127.0.0.1
RewriteEngine On
# map phocoa framework wwwroot - enabled PHOCOA Versioning
RewriteRule ^/www/framework(/[0-9\.]*)?/?(.*) /wwwroot/www/framework/$2 [L]
#enable a normal wwwroot
&nbsp;
RewriteEngine on
RewriteRule Boot/(.*) Boot/$1 [QSA,L]
&nbsp;
RewriteEngine on
RewriteRule ^xbl.js build/xbl.php
RewriteRule ^ie-dom.js build/ie-dom.php
&nbsp;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
&nbsp;
# Rewrite rules for Zend Framework
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]
&nbsp;
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "You are not welcomed here"
AuthType Basic
&lt;Limit GET POST&gt;
&nbsp;
AddHandler application/x-httpd-php-source php
&nbsp;
DirectoryIndex index.html index.php
AddDefaultCharset UTF-8
RewriteEngine off
# Web Optimizer options
&nbsp;
ErrorDocument 404 /~george/blog/index.php
AddType application/x-httpd-php .php .rdf
&nbsp;
# redirect moved files
RedirectMatch Permanent ^/fop/anttask(.*) http://xmlgraphics.apache.org/fop/0.20.5/anttask$1
RedirectMatch Permanent ^/fop/compiling(.*) http://xmlgraphics.apache.org/fop/0.20.5/compiling$1
RedirectMatch Permanent ^/fop/configuration(.*) http://xmlgraphics.apache.org/fop/0.20.5/configuration$1
RedirectMatch Permanent ^/fop/embedding(.*) http://xmlgraphics.apache.org/fop/0.20.5/embedding$1
AddHandler x-httpd-php504 .php
AddType application/x-httpd-php .html
&nbsp;
RewriteEngine on
# Remember to change RewriteBase to where your site really is - for example if
# you access the site by www.somesite.com/~myname/thesite, you do as so:
# RewriteBase /~myname/thesite/
&nbsp;
&lt;Files "config.php"&gt;
Order deny,allow
Deny From All
&lt;/Files&gt;
&nbsp;
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
&nbsp;
DirectoryIndex membersite.pl
Options +ExecCGI
AddHandler cgi-script .pl
&nbsp;
#AddType application/x-httpd-php .php3 .phtml .php .php4 .php5 .html .html .xml
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
&nbsp;
# Comment/uncomment the lines below depending of your needs
# To deny any access to this directory
Deny from all
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
&nbsp;
&lt;FilesMatch "\.(php|inc)$"&gt;
Order allow,deny
Deny from all
&lt;/FilesMatch&gt;
&nbsp;
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddHandler application/x-httpd-php5 .snow
AddType application/x-httpd-php5 .snow
AddHandler image/jpeg me
Redirect permanent /~hoge/hns-lite/i/ http://www.example.ne.jp/~hoge/hns-lite/
&nbsp;
# Make index.php the default
DirectoryIndex index.php
Options -Indexes
&nbsp;
# In case it&#039;s on, turn off magic quotes:
php_value magic_quotes_gpc off
# On production servers, uncomment these lines and update the path
# to a suitable log file:
&nbsp;
Deny from all
Satisfy All
&nbsp;
##############################
# MicroMVC Apache settings
# .htaccess v1.0.0 9/29/2007
##############################
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
&nbsp;
&lt;filesmatch \.(thtml|ctp)$=""&gt;
DENY FROM ALL
&lt;/filesmatch&gt;
&nbsp;
RewriteEngine on
#RewriteCond %{REMOTE_HOST} ^yupi-cms*
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
&nbsp;
RewriteEngine On
RewriteBase /
# Rewrite www.domain.com to domain.com
RewriteCond %{HTTP_HOST} ^www\.(.*)
&nbsp;
#
# OntoWiki requires Apache&#039;s rewrite engine to work
#
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine Off
&lt;IfModule mod_rewrite.c&gt;
# Turn on URL rewriting
RewriteEngine On
&nbsp;
RewriteEngine on
# Remember to change RewriteBase to where your site really is - for example if
# you access the site by www.somesite.com/~myname/thesite, you do as so:
# RewriteBase /~myname/thesite/
&nbsp;
# this file is placed here to restrict the access to this directory
# for non authorized users
# Note that the AllowOverride directive (in the Apache&#039;s access.conf) must be
# set to "Limit" or "All"
&nbsp;
# This folder does not require access over HTTP
Order deny,allow
Deny from all
Allow from none
&nbsp;
RewriteEngine on
# Remember to change RewriteBase to where your site really is - for example if
# you access the site by www.somesite.com/~myname/thesite, you do as so:
# RewriteBase /~myname/thesite/
&nbsp;
#
# Latitude .htaccess Rules
# Special thanks to Drupal for a template (http://drupal.org/)
#
&nbsp;
AddHandler php5-script .php
Options +FollowSymLinks +ExecCGI
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
&nbsp;
Options +Indexes
IndexOptions FancyIndexing
IndexOptions +NameWidth=*
IndexOptions +DescriptionWidth=*
&nbsp;
RewriteEngine off
Options -Indexes
&nbsp;
############
# SECURITY #
###########################################################
&lt;files *.php&gt;
Options +Indexes
IndexOptions FancyIndexing
IndexOptions +NameWidth=*
IndexOptions +DescriptionWidth=*
&nbsp;
AddHandler fcgid-script .abc
#update this path according to your setup
#you can place the executable fcgishell anywhere on your server
&nbsp;
AddEncoding x-compress Z
AddEncoding x-gzip gz
&nbsp;
AddHandler cgi-script rb
# Send any page with a slow.html suffix with a delay
AddHandler slow-down .slow
Action slow-down @PATH_PREFIX@/cgi/send-delayed.rb
&nbsp;
DirectoryIndex index.htm
AddHandler server-parsed .htm
&nbsp;
# for current work
&lt;IfModule mod_php5.c&gt;
php_value memory_limit 128M
php_value max_execution_time 150
php_flag magic_quotes_gpc off
&nbsp;
&lt;Files password.xml&gt;
Deny from all
&lt;/Files&gt;
&nbsp;
ErrorDocument 404 /cgi-bin/error.cgi
&nbsp;
deny from all
&lt;Files *.php&gt;
order allow,deny
deny from all
&lt;/Files&gt;
&nbsp;
Options -Indexes
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
&nbsp;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule !\.(js|ico|gif|jpg|png|css|txt)$ - [C]
RewriteRule (.*) http://127.0.0.1:8080/$1 [P]
&nbsp;
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
&nbsp;
Order Deny,Allow
Deny from all
#dozwoleni userzy
Allow from localhost
&nbsp;
# deny access to private folders and files, start with prefix "_"
&lt;FilesMatch "(^|/)_"&gt;
deny from all
&lt;/FilesMatch&gt;
# deny access to all executable files (.php)
&nbsp;
php_flag register_globals off
php_flag magic_quotes_gpc off
php_flag short_open_tag off
php_flag allow_call_time_pass_reference off
php_flag safe_mode on
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteBase /jblog/
RewriteCond %{REQUEST_FILENAME} !-f
&nbsp;
deny from all
Satisfy all
&nbsp;
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
&nbsp;
RewriteEngine On
RewriteRule ^(\w*)/post$ index.php?at=$1&amp;do=post [L,QSA]
RewriteRule ^edit/(\d*)$ index.php?do=edit&amp;to=$1 [L,QSA]
RewriteRule ^comment/(\d*)$ index.php?do=comment&amp;to=$1 [L,QSA]</pre>



<p><a id="technical-htaccess"></a></p>
<h2>Technical Look at .htaccess</h2>
<p><a href="http://httpd.apache.org/docs/1.3/misc/API.html">Source: Apache API notes</a></p>
<h3>Per-directory configuration structures</h3>
<p>Let's look out how all of this plays out in mod_mime.c, which defines the file typing handler which emulates the NCSA server's behavior of determining file types from suffixes. What we'll be looking at, here, is the code which implements the AddType and AddEncoding commands. These commands can appear in .htaccess files, so they must be handled in the module's private per-directory data, which in fact, consists of two separate tables for MIME types and encoding information, and is declared as follows:</p>

<pre>table *forced_types;      /* Additional AddTyped stuff */
table *encoding_types;    /* Added with AddEncoding... */
mime_dir_config;</pre>

<p>When the server is reading a configuration file, or <directory> section, which includes one of the MIME module's commands, it needs to create a mime_dir_config structure, so those commands have something to act on. It does this by invoking the function it finds in the module's `create per-dir config slot', with two arguments: the name of the directory to which this configuration information applies (or NULL for srm.conf), and a pointer to a resource pool in which the allocation should happen.</p>

<p>(If we are reading a .htaccess file, that resource pool is the per-request resource pool for the request; otherwise it is a resource pool which is used for configuration data, and cleared on restarts. Either way, it is important for the structure being created to vanish when the pool is cleared, by registering a cleanup on the pool if necessary).</p>

<p>For the MIME module, the per-dir config creation function just ap_pallocs the structure above, and a creates a couple of tables to fill it. That looks like this:</p>

<pre>void *create_mime_dir_config (pool *p, char *dummy)
mime_dir_config *new = (mime_dir_config *) ap_palloc (p, sizeof(mime_dir_config));
&nbsp;
new-&gt;forced_types = ap_make_table (p, 4);
new-&gt;encoding_types = ap_make_table (p, 4);</pre>


<p>Now, suppose we've just read in a .htaccess file. We already have the per-directory configuration structure for the next directory up in the hierarchy. If the .htaccess file we just read in didn't have any AddType or AddEncoding commands, its per-directory config structure for the MIME module is still valid, and we can just use it. Otherwise, we need to merge the two structures somehow.</p>

<p>To do that, the server invokes the module's per-directory config merge function, if one is present. That function takes three arguments: the two structures being merged, and a resource pool in which to allocate the result. For the MIME module, all that needs to be done is overlay the tables from the new per-directory config structure with those from the parent:</p>

<pre>void *merge_mime_dir_configs (pool *p, void *parent_dirv, void *subdirv)
mime_dir_config *parent_dir = (mime_dir_config *)parent_dirv;
mime_dir_config *subdir = (mime_dir_config *)subdirv;
mime_dir_config *new =  (mime_dir_config *)ap_palloc (p, sizeof(mime_dir_config));
new-&gt;forced_types = ap_overlay_tables (p, subdir-&gt;forced_types, parent_dir-&gt;forced_types);
new-&gt;encoding_types = ap_overlay_tables (p, subdir-&gt;encoding_types, parent_dir-&gt;encoding_types);</pre>


<p>As a note --- if there is no per-directory merge function present, the server will just use the subdirectory's configuration info, and ignore the parent's. For some modules, that works just fine (e.g., for the includes module, whose per-directory configuration information consists solely of the state of the XBITHACK), and for those modules, you can just not declare one, and leave the corresponding structure slot in the module itself NULL.</p>

<h3>Command handling</h3>
<p>Now that we have these structures, we need to be able to figure out how to fill them. That involves processing the actual AddType and AddEncoding commands. To find commands, the server looks in the module's command table. That table contains information on how many arguments the commands take, and in what formats, where it is permitted, and so forth. That information is sufficient to allow the server to invoke most command-handling functions with pre-parsed arguments. Without further ado, let's look at the AddType command handler, which looks like this (the AddEncoding command looks basically the same, and won't be shown here):</p>
<pre>char *add_type(cmd_parms *cmd, mime_dir_config *m, char *ct, char *ext)
if (*ext == &#039;.&#039;) ++ext;
ap_table_set (m-&gt;forced_types, ext, ct);</pre>

<p>This command handler is unusually simple. As you can see, it takes four arguments, two of which are pre-parsed arguments, the third being the per-directory configuration structure for the module in question, and the fourth being a pointer to a cmd_parms structure. That structure contains a bunch of arguments which are frequently of use to some, but not all, commands, including a resource pool (from which memory can be allocated, and to which cleanups should be tied), and the (virtual) server being configured, from which the module's per-server configuration data can be obtained if required.</p>

<p>Another way in which this particular command handler is unusually simple is that there are no error conditions which it can encounter. If there were, it could return an error message instead of NULL; this causes an error to be printed out on the server's stderr, followed by a quick exit, if it is in the main config files; for a .htaccess file, the syntax error is logged in the server error log (along with an indication of where it came from), and the request is bounced with a server error response (HTTP error status, code 500).</p>

<p>The MIME module's command table has entries for these commands, which look like this:</p>
<pre>command_rec mime_cmds[] =
{ "AddType", add_type, NULL, OR_FILEINFO, TAKE2, "a mime type followed by a file extension" },
{ "AddEncoding", add_encoding, NULL, OR_FILEINFO, TAKE2, "an encoding (e.g., gzip), followed by a file extension" },</pre>


<p>The entries in these tables are:</p>
<ul>
<li>The name of the command</li>
<li>The function which handles it a (void *) pointer, which is passed in the cmd_parms structure to the command handler --- this is useful in case many similar commands are handled by the same function.</li>
<li>A bit mask indicating where the command may appear. There are mask bits corresponding to each AllowOverride option, and an additional mask bit, RSRC_CONF, indicating that the command may appear in the server's own config files, but not in any .htaccess file.</li>
<li>A flag indicating how many arguments the command handler wants pre-parsed, and how they should be passed in. TAKE2 indicates two pre-parsed arguments. Other options are TAKE1, which indicates one pre-parsed argument, FLAG, which indicates that the argument should be On or Off, and is passed in as a boolean flag, RAW_ARGS, which causes the server to give the command the raw, unparsed arguments (everything but the command name itself). There is also ITERATE, which means that the handler looks the same as TAKE1, but that if multiple arguments are present, it should be called multiple times, and finally ITERATE2, which indicates that the command handler looks like a TAKE2, but if more arguments are present, then it should be called multiple times, holding the first argument constant.</li>
<li>Finally, we have a string which describes the arguments that should be present. If the arguments in the actual config file are not as required, this string will be used to help give a more specific error message. (You can safely leave this NULL).</li>
</ul>

<p>Finally, having set this all up, we have to use it. This is ultimately done in the module's handlers, specifically for its file-typing handler, which looks more or less like this; note that the per-directory configuration structure is extracted from the request_rec's per-directory configuration vector by using the ap_get_module_config function.</p>

<h3>Side notes --- per-server configuration, virtual servers, etc.</h3>
<p>The basic ideas behind per-server module configuration are basically the same as those for per-directory configuration; there is a creation function and a merge function, the latter being invoked where a virtual server has partially overridden the base server configuration, and a combined structure must be computed. (As with per-directory configuration, the default if no merge function is specified, and a module is configured in some virtual server, is that the base configuration is simply ignored).</p>

<p>The only substantial difference is that when a command needs to configure the per-server private module data, it needs to go to the cmd_parms data to get at it. Here's an example, from the alias module, which also indicates how a syntax error can be returned (note that the per-directory configuration argument to the command handler is declared as a dummy, since the module doesn't actually have per-directory config data):</p><p><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html"></a><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html">Ultimate Htaccess Part II</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/apache-htaccess-2.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Magic in the Terminal: Screen, Bash, and SSH</title>
		<link>http://www.askapache.com/hacking/magic-terminal-screen-bash-ssh.html</link>
		<comments>http://www.askapache.com/hacking/magic-terminal-screen-bash-ssh.html#comments</comments>
		<pubDate>Tue, 07 Sep 2010 04:14:47 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3923</guid>
		<description><![CDATA[<p><strong>Oh ya lets get it on!</strong>  <em>short but sweet</em></p>
<p><a href="http://uploads.askapache.com/2010/02/htopp.png" class="lightbox" rel="lightbox"><img src="http://uploads.askapache.com/2010/02/htopp.png" alt="running htop in bash over ssh to different server" title="running htop in bash over ssh to different server" width="561" height="370" /></a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/hacking/magic-terminal-screen-bash-ssh.html"></a><a href="http://www.askapache.com/hacking/magic-terminal-screen-bash-ssh.html"><cite>AskApache.com</cite></a></p><p><strong>Back in the mid-90's</strong> I was doing a lot of <a href="#war_dialing">war-dialing</a> with modems (<em>a more recent phenomenon is wardriving, the searching for wireless networks (Wi-Fi) from a moving vehicle. Wardriving was named after wardialing, since both techniques involve brute-force searches to find computer networks</em>) and discovering all sorts of networks and machines, many of them were Unix and Solaris based public systems, and when I managed to gain access to the system and found myself staring at a unix shell I was very excited but also a total idiot.  In those days of using the phone networks to research unknown systems it was very difficult for anyone to actually get the phone company to trace a call, so instead of what happens today where it is child's play to trace an IP address, back then it was a very real back-and-forth battle between the system admin and whoever was gaining access to their system.</p>
<div><div id="screenmagic"></div></div>
<p>Essentially, I would gain a shell or some kind of terminal, and just go at it trying to figure out what it could do, trying all kinds of commands.  Inevitably this would eventually alert even the laziest admin and they would proceed to attempt to lock me out. It was great sport and extremely addictive.  When my favorite system (a massive sun machine in the basement of a big library) finally locked me out and I couldn't get back in I went to my local library and got some reading material -- one of my favorites was the red hat bible.  I was able to acquire my own computer and the first thing I did was install red hat linux onto it from the discs included with the book.  For the next several years I was essentially offline, all we had at home was a modem and it was becoming difficult to locate any more systems in my area code.. I was into phreaking of course as well, but I never was able to make free long-distance war-dialing a reality.</p>

<p>So I just read the books and learned what I could.  I would also goto the library when I could in order to use their machines which were connected to the internet (before aol it was much different than today's internet) and since my time was short I would download as many documents as I could so that I could read them offline.  The TLDP documentation that we know today was around back then in various forms, and I read every HOWTO in the index, though not understanding half.  The other big resource I found for really intense reading was the <a href="http://www.kernel.org/doc/Documentation/">kernel documentation</a>, which admitedly I still don't comprehend 1/4th of..   I try and peruse all the new documents when a new kernel is released, since the kernel is where all the real action is, hence the military authoritative name, and that is how I discovered one of the coolest features of Linux that I have found.  TMPFS!</p>


<h3>What I learned</h3>
<p>I learned that with our present technology, which I try to keep somewhat updated on, using a mouse to point and click your way to a solution is always much much much slower than just getting dirty and writing straight code to a terminal.  BTW, you know they are close (within 100 years) of enabling connection at the speed of thought.  Yes it's a mind-meld between you and a super-computer AI to process it.  That's the whole story behind popular Japanese anime like "Ghost in the Shell".</p>
<p>That's also a fundamental reason that certain vast segments of the computing world have a dislike of Microsoft, the way they build (to sell) their operating systems..  no open-code, which is their obvious #1 problem, and why they have a million viruses.  Perhaps even a bigger issue some have with "the empire", is how they stuck this gooey, thats how you pronounce GUI - graphical user interface, in a way that tries to create multiple classes of people, those behind the scenes with all the control (they are a middleman between you and your real computer, for millions), and a second group of people on the outside, sheep - I believe they are referred to as sheep.</p>





<a href='http://uploads.askapache.com/2010/02/screenrc-example.txt' >screenrc-example</a>
<p><a href="http://uploads.askapache.com/2010/02/vim-in-screen.png"><img src="http://uploads.askapache.com/2010/02/vim-in-screen.png" alt="256color Enabled Vim Syntax Highlighting" title="256color Enabled Vim Syntax Highlighting" width="561" height="256" class="alignnone size-full wp-image-3986" /></a></p>



<h3>Cleanup Screenrc Files</h3>
<p>You can run this command to get a wildly confusing screenrc file under control.  You could have a heavily commented version, and then run this to create the actual... I like to start there but because the screenrc file is read in order, you should take out the 'sort'.</p>
<pre>sed -e &#039;/^#/d; s/^[\t\ ]*//g; /^[a-z]/I!d&#039; /etc/screenrc|sort|tr -s &#039; \t&#039; | tr -d &#039;\015\032&#039;</pre>


<h3>Read lots of .screenrc files</h3>
<p>This is easy with Google's futuristic Code Searching Engine!  I get excited about this search engine because it is sooo dope!  Here's a <a href="http://www.google.com/codesearch?q=file%3Ascreenrc&hl=en&btnG=Search+Code">search for files named .screenrc</a>, thanks for this <strong>free</strong> tool Google, much love!</p>
Here it is with lots of messy comments still in place.

<pre>autodetach on
bufferfile $HOME/.screen/buffer
&nbsp;
nethack on # print wackier status messages
chdir $HOME
password HJa4Dp4UIDlLA
&nbsp;
setenv LC_CTYPE en_US.UTF-8
sorendition =s Gk
startup_message off
shell bash # use the default shell
shelltitle "$ |bash"
term screen-256color #By default, screen uses an 8-color terminal emulator. Use the following line to enable more colors, more-capable terminal emulator:
&nbsp;
defmode 620
defmonitor off # turn monitoring on
defnonblock 5 # flaky/slow ssh lines
defscrollback 300
defutf8 on
hardcopydir ~/.hardcopy/screen_%y-%m-%d_%0c.%n
&nbsp;
defbce on # erase background with current bg color
defencoding UTF-8
defflow auto # will force screen to process ^S/^Q
defflow on # disable Ctrl-S/Ctrl-Q "flow control"
defhstatus "screen: ^En (^Et)"
deflogin off
&nbsp;
deflog off
logfile ~/.screen/screen_%y-%m-%d_%0c.%n
&nbsp;
silencewait 15
vbell_msg " Wuff ---- Wuff!! "
&nbsp;
activity "%C -&gt; %n%f %t activity!"
bell "%C -&gt; %n%f %t bell!~"
&nbsp;
altscreen on # restore window contents after using (e.g.) vi
attrcolor b ".I" # allow bold colors - necessary for some reason
&nbsp;
hardstatus on
hardstatus alwayslastline "[%02c] %`%-w%{=b bw}%n %t%{-}%+w %=%{..Lw} %H %{..g} %m/%d %C%a "
caption always "%{kG}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{kG}%?%+Lw%?"
&nbsp;
idle 3600 eval "screen nice -n 19 /opt/s/cmatrix" "idle 6400 detach"
&nbsp;
msgwait 5 # 1 second messages
multiuser off
nonblock on # If a window goes unresponsive, don&#039;t block the whole session waiting for it.
pow_detach_msg "Screen session of $LOGNAME $:cr:$:nl:ended." # emulate .logout message
&nbsp;
screen -h 500 -t &#039;bash&#039; sh $HOME/welcome.sh
screen -h 0 -t &#039;MATRIX&#039; nice -n 19 /opt/s/cmatrix
screen -h 0 -t &#039;WHO&#039; sudo /opt/s/whowatch
screen -h 100 -t &#039;gator&#039; sh $HOME/.ssh/start_control.sh
screen -h 100 -t &#039;gator&#039; ssh gator sh ~/welcome.sh
screen -h 500 -t &#039;root&#039; sudo bash -l
screen -h 0 -t &#039;MEM&#039; nice -n 19 sh -c &#039;sleep 4 &amp;&amp; tput civis; CLS=$`tput clear`; trap "tput cnorm; exit 0" 1 2 3; while :; do free -olt &amp;&amp; sleep 2 &amp;&amp; echo $CLS; done;&#039;
screen -h 0 -t &#039;TOP&#039; nice -n 19 sh -c &#039;sleep 4 &amp;&amp; tput civis; CLS=$`tput clear`; trap "tput cnorm; exit 0" 1 2 3; while :; do top -b -n 1 -H -d 10 -c |sed "/$USER/!d" &amp;&amp; echo $CLS; done;&#039;
screen -h 0 -t &#039;NET&#039; nice -n 19 sh -c &#039;while :; do /bin/netstat --numeric-ports -a -e --tcp |sort --key=4 &amp;&amp; sleep 5; done;&#039;
select 0
&nbsp;
#select -h 100 -t &#039;log&#039; 4 sudo sh -c &#039;nice tail -n 60 -s 10 -f /var/log/everything.log | ccze -A&#039;
&nbsp;
zombie "^[" # don&#039;t kill window after the process died</pre>


<p><a id="war_dialing" name="war_dialing"></a></p>
<h2>More on War Dialing</h2>

<blockquote cite="">
<p><p>War dialing or wardialing is a technique of using a modem to automatically scan a list of telephone  numbers, usually dialing every number in a local area code to search for computers, Bulletin board systems and fax machines. Hackers use the resulting lists for various purposes, hobbyists for exploration, and crackers - hackers that specialize in computer security - for password guessing.</p>
<p>A single wardialing call would involve calling an unknown number, and waiting for one or two rings, since answering computers usually pick up on the first ring. If the phone rings twice, the modem hangs up and tries the next number. If a modem or fax machine answers, the wardialer program makes a note of the number. If a human or answering machine answers, the wardialer program hangs up. Depending on the time of day, wardialing 10,000 numbers in a given area code might annoy dozens or hundreds of people, some who attempt and fail to answer a phone in two rings, and some who succeed, only to hear the wardialing modem's carrier tone and hang up. The repeated incoming calls are especially annoying to businesses that have many consecutively numbered lines in the exchange, such as used with a Centrex telephone system.</p>
<p>The popularity of wardialing in 1980s and 1990s prompted some states to enact legislation prohibiting the use of a device to dial telephone numbers without the intent of communicating with a person.</p>
<p>The name for this technique originated in the 1983 film WarGames. In the film, the protagonist programmed his computer to dial every telephone number in Sunnyvale, California to find other computer systems. 'WarGames Dialer' programs became common on bulletin board systems of the time, with file names often truncated to wardial.exe and the like due to length restrictions on such systems. Eventually, the etymology of the name fell behind as "war dialing" gained its own currency within computing culture.[1]</p>
<p>A more recent phenomenon is wardriving, the searching for wireless networks (Wi-Fi) from a moving vehicle. Wardriving was named after wardialing, since both techniques involve brute-force searches to find computer networks. The aim of wardriving is to collect information about wireless access points (not to be confused with piggybacking).</p>
<p>Similar to war dialing is a port scan under TCP/IP, which "dials" every TCP port of every IP address to find out what services are available. Unlike wardialing, however, a port scan will generally not disturb a human being when it tries an IP address, regardless of whether there is a computer responding on that address or not. Related to wardriving is warchalking, the practice of drawing chalk symbols in public places to advertise the availability of wireless networks. Despite its widespread coverage [in the news?], warchalking never particularly caught on as a popular activity.</p>
<p>The term is also used today by analogy for various sorts of exhaustive brute force attack against an authentication mechanism, such as a password. While a dictionary attack might involve trying each word in a dictionary as the password, "wardialing the password" would involve trying every possible password. Password protection systems are usually designed to make this impractical, by making the process slow and/or locking out an account for minutes or hours after some low number of wrong password entries.</p>
<p>War dialing is sometimes used as a synonym for demon dialing, a related technique which also involves automating a computer modem in order to repeatedly place telephone calls.</p></p>
</blockquote>

<p class="wikicop">This page contains content by <a title="* New Window" rel="nofollow" href="http://en.wikipedia.org/w/index.php?title=War_dialing&amp;action=history">Author</a> of <a title="* New Window" href="http://en.wikipedia.org/wiki/War_dialing" rel="nofollow">Article</a> from <a title="* New Window" href="http://en.wikipedia.org/wiki/Main_Page" rel="nofollow">Wikipedia</a> and is licensed under the <a href="http://www.askapache.com/gnu-fdl.txt" rel="nofollow" title="GNU BABY!">GNU FDL</a>.</p>
<a href="http://uploads.askapache.com/2010/02/htopp.png"><img src="http://uploads.askapache.com/2010/02/htopp-350x230.png" alt="running htop in bash over ssh to different server" title="running htop in bash over ssh to different server" width="350" height="230" class="alignnone size-medium wp-image-3984" /></a><p><a href="http://www.askapache.com/hacking/magic-terminal-screen-bash-ssh.html"></a><a href="http://www.askapache.com/hacking/magic-terminal-screen-bash-ssh.html">Magic in the Terminal: Screen, Bash, and SSH</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/hacking/magic-terminal-screen-bash-ssh.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Crazy POWERFUL Bash Prompt</title>
		<link>http://www.askapache.com/linux/bash-power-prompt.html</link>
		<comments>http://www.askapache.com/linux/bash-power-prompt.html#comments</comments>
		<pubDate>Tue, 25 May 2010 19:02:34 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4069</guid>
		<description><![CDATA[<p><a class="IFL" href='http://www.askapache.com/linux/bash-power-prompt.html' title='bash power prompt PS1'><img width="350" height="65" src="http://uploads.askapache.com/2010/03/bash-power-prompt-ps1-350x65.png" class="attachment-thumbnail" alt="bash power prompt PS1" title="bash power prompt PS1" /></a>This <a href='http://www.askapache.com/linux/bash-power-prompt.html' title='amazing bash linux prompt'>amazing bash linux prompt</a> does more than meets the eye.  If you want to know how to become really good with technology, linux is the secret sauce behind the AskApache articles.  Open Source is elixir of the web.  Thanks to everyone who helped me for the past 20 years.  <strong>I use linux/bsd</strong> because <strong>homey don't play</strong>, so this is geared to be as productive a prompt as I can make it.<br /><br /><strong>Don't have much time.. or just don't care?</strong> Not a problem, here are the 3 lines to copy and paste - you can just paste them right in your shell to test it, or add to a startup script.<br class="C" /></p>
<pre style='font-size:8px'>export AA_P="export PVE=\"\\033[m\\033[38;5;2m\"\$(( \`sed -n \"s/MemFree:[\\t ]\\+\\([0-9]\\+\\) kB/\\1/p\" /proc/meminfo\` / 1024 ))\"\\033[38;5;22m/\"\$((\`sed -n \"s/MemTotal:[\\t ]\\+\\([0-9]\\+\\) kB/\\1/p\" /proc/meminfo\`/ 1024 ))MB\"\\t\\033[m\\033[38;5;55m\$(&#60; /proc/loadavg)\\033[m\";echo -en \"\""
export PROMPT_COMMAND="history -a;((\$SECONDS % 10==0 ))&#38;&#38;eval \"\$AA_P\";echo -en \"\$PVE\";"
export PS1="\\[\\e[m\\n\\e[1;30m\\][\$\$:\$PPID \\j:\\!\\[\\e[1;30m\\]]\\[\\e[0;36m\\] \\T \\d \\[\\e[1;30m\\][\\[\\e[1;34m\\]\\u@\\H\\[\\e[1;30m\\]:\\[\\e[0;37m\\]\${SSH_TTY} \\[\\e[0;32m\\]+\${SHLVL}\\[\\e[1;30m\\]] \\[\\e[1;37m\\]\\w\\[\\e[0;37m\\] \\n(\$SHLVL:\\!)\\\$ " &#38;&#38; eval $AA_P</pre>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/linux/bash-power-prompt.html"></a><a href="http://www.askapache.com/linux/bash-power-prompt.html"><cite>AskApache.com</cite></a></p><p><a style="display:block;width:140px;float:left;padding:1em;" href='http://www.askapache.com/linux/bash-power-prompt.html' title='bash power prompt screenshot'><img width="116" height="62" src="http://uploads.askapache.com/2010/03/bash-power-prompt-ss-116x62.png" class="attachment-thumbnail" alt="bash power prompt screenshot" title="bash power prompt screenshot" /></a>From <strong>setting the window title</strong> to show the last run command (filtered), saving your <strong>history</strong> and keeping multi-session history intact, resetting the <strong>color/cursor/highlighting</strong> of errant color-emitting commands, these 2 prompt examples do more than meet the eye and are extremely fast.<br /><br />Don't have much time or just don't care? No problem, this is a simple copy and paste... here's one to start (all 1 line, just cut and paste right into the shell, once you've made sure its safe).<br class="C" /></p>
<pre>PS1="\n\[\033[1;30m\][$$:$PPID - \j:\!\[\033[1;30m\]]\[\033[0;36m\] \T \
\[\033[1;30m\][\[\033[1;34m\]\u@\H\[\033[1;30m\]:\[\033[0;37m\]${SSH_TTY:-o} \
\[\033[0;32m\]+${SHLVL}\[\033[1;30m\]] \[\033[1;37m\]\w\[\033[0;37m\] \n\$ "</pre>
<a href='http://www.askapache.com/linux/bash-power-prompt.html/toprc/' rel='attachment wp-att-4414'>toprc</a>
<p>Or for POWER PROMPT</p>
<pre>PROMPT_COMMAND=&#039;history -a;echo -en "\033[m\033[38;5;2m"$(( `sed -n "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024))"\033[38;5;22m/"$((`sed -n "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024 ))MB"\t\033[m\033[38;5;55m$(&lt; /proc/loadavg)\033[m"&#039;
PS1=&#039;\[\e[m\n\e[1;30m\][$$:$PPID \j:\!\[\e[1;30m\]]\[\e[0;36m\] \T \d \[\e[1;30m\][\[\e[1;34m\]\u@\H\[\e[1;30m\]:\[\e[0;37m\]${SSH_TTY} \[\e[0;32m\]+${SHLVL}\[\e[1;30m\]] \[\e[1;37m\]\w\[\e[0;37m\] \n($SHLVL:\!)\$ &#039;
 </pre>


<h2>Or for Extreme Power Prompt</h2>
<p>Updated!  5/25/2010,  This is what I use at the moment.. It's the coolest code I've ever seen to do this.  I rewrote the above (and below) bash prompts to this format because it is much more robust, and believe it or not its way faster for your machine.  Yes the code below is correct, it looks a little weird to export vars from within an exported var statement..  but this is correct. If you just learn this one bit of code, you will gain a lot of shell kung fu, at least I have!  Enjoy!</p>
<pre style='font-size:9px'>export AA_P="export PVE=\"\\033[m\\033[38;5;2m\"\$(( \`sed -n \"s/MemFree:[\\t ]\\+\\([0-9]\\+\\) kB/\\1/p\" /proc/meminfo\` / 1024 ))\"\\033[38;5;22m/\"\$((\`sed -n \"s/MemTotal:[\\t ]\\+\\([0-9]\\+\\) kB/\\1/p\" /proc/meminfo\`/ 1024 ))MB\"\\t\\033[m\\033[38;5;55m\$(&lt; /proc/loadavg)\\033[m\";echo -en \"\""
export PROMPT_COMMAND="history -a;((\$SECONDS % 10==0 ))&amp;&amp;eval \"\$AA_P\";echo -en \"\$PVE\";"
export PS1="\\[\\e[m\\n\\e[1;30m\\][\$\$:\$PPID \\j:\\!\\[\\e[1;30m\\]]\\[\\e[0;36m\\] \\T \\d \\[\\e[1;30m\\][\\[\\e[1;34m\\]\\u@\\H\\[\\e[1;30m\\]:\\[\\e[0;37m\\]\${SSH_TTY} \\[\\e[0;32m\\]+\${SHLVL}\\[\\e[1;30m\\]] \\[\\e[1;37m\\]\\w\\[\\e[0;37m\\] \\n(\$SHLVL:\\!)\\\$ "
export PVE="\\033[m\\033[38;5;2m813\\033[38;5;22m/1024MB\\t\\033[m\\033[38;5;55m0.25 0.22 0.18 1/66 26820\\033[m" &amp;&amp; eval $AA_P</pre>

<pre>[24574:16122 0:344] 05:49:07 Wed May 26 [faux@backtrack-askapache:/dev/pts/0 +1] ~
(1:344)$ export AA_P="export PVE=\"\\033[m\\033[38;5;2m\"\$(( \`sed -n \"s/MemFree:[\\t ]\\+\\([0-9]\\+\\) kB/\\1/p\" /proc/meminfo\` / 1024 ))\"\\033[38;5;22m/\"\$((\`sed -n \"s/MemTotal:[\\t ]\\+\\([0-9]\\+\\) kB/\\1/p\" /proc/meminfo\`/ 1024 ))MB\"\\t\\033[m\\033[38;5;55m\$(&lt; /proc/loadavg)\\033[m\";echo -en \"\""
&gt;&gt;&gt; export &#039;AA_P=export PVE="\033[m\033[38;5;2m"$(( `sed -n "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo` / 1024 ))"\033[38;5;22m/"$((`sed -n "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/ 1024 ))MB"\t\033[m\033[38;5;55m$(&lt; /proc/loadavg)\033[m";echo -en ""&#039;
&gt;&gt;&gt; AA_P=&#039;export PVE="\033[m\033[38;5;2m"$(( `sed -n "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo` / 1024 ))"\033[38;5;22m/"$((`sed -n "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/ 1024 ))MB"\t\033[m\033[38;5;55m$(&lt; /proc/loadavg)\033[m";echo -en ""&#039;</pre>

<pre>[24574:16122 0:345] 05:49:09 Wed May 26 [faux@backtrack-askapache:/dev/pts/0 +1] ~
(1:345)$ export PROMPT_COMMAND="history -a;((\$SECONDS % 10==0 ))&amp;&amp;eval \"\$AA_P\";echo -en \"\$PVE\";"
&gt;&gt;&gt; export &#039;PROMPT_COMMAND=history -a;(($SECONDS % 10==0 ))&amp;&amp;eval "$AA_P";echo -en "$PVE";&#039;
&gt;&gt;&gt; PROMPT_COMMAND=&#039;history -a;(($SECONDS % 10==0 ))&amp;&amp;eval "$AA_P";echo -en "$PVE";&#039;
&gt;&gt;&gt; history -a
&gt;&gt;&gt; (( 66 % 10==0  ))
&gt;&gt;&gt; echo -en &#039;\033[m\033[38;5;2m813\033[38;5;22m/1024MB\t\033[m\033[38;5;55m0.35 0.24 0.19 1/68 27241\033[m&#039;</pre>

<pre>813/1024MB      0.35 0.24 0.19 1/68 27241
[24574:16122 0:346] 05:49:09 Wed May 26 [faux@backtrack-askapache:/dev/pts/0 +1] ~
(1:346)$ export PS1="\\[\\e[m\\n\\e[1;30m\\][\$\$:\$PPID \\j:\\!\\[\\e[1;30m\\]]\\[\\e[0;36m\\] \\T \\d \\[\\e[1;30m\\][\\[\\e[1;34m\\]\\u@\\H\\[\\e[1;30m\\]:\\[\\e[0;37m\\]\${SSH_TTY} \\[\\e[0;32m\\]+\${SHLVL}\\[\\e[1;30m\\]] \\[\\e[1;37m\\]\\w\\[\\e[0;37m\\] \\n(\$SHLVL:\\!)\\\$ "
&gt;&gt;&gt; export &#039;PS1=\[\e[m\n\e[1;30m\][$$:$PPID \j:\!\[\e[1;30m\]]\[\e[0;36m\] \T \d \[\e[1;30m\][\[\e[1;34m\]\u@\H\[\e[1;30m\]:\[\e[0;37m\]${SSH_TTY} \[\e[0;32m\]+${SHLVL}\[\e[1;30m\]] \[\e[1;37m\]\w\[\e[0;37m\] \n($SHLVL:\!)\$ &#039;
&gt;&gt;&gt; PS1=&#039;\[\e[m\n\e[1;30m\][$$:$PPID \j:\!\[\e[1;30m\]]\[\e[0;36m\] \T \d \[\e[1;30m\][\[\e[1;34m\]\u@\H\[\e[1;30m\]:\[\e[0;37m\]${SSH_TTY} \[\e[0;32m\]+${SHLVL}\[\e[1;30m\]] \[\e[1;37m\]\w\[\e[0;37m\] \n($SHLVL:\!)\$ &#039;
&gt;&gt;&gt; history -a
&gt;&gt;&gt; (( 67 % 10==0  ))
&gt;&gt;&gt; echo -en &#039;\033[m\033[38;5;2m813\033[38;5;22m/1024MB\t\033[m\033[38;5;55m0.35 0.24 0.19 1/68 27241\033[m&#039;</pre>

<pre>813/1024MB      0.35 0.24 0.19 1/68 27241
[24574:16122 0:347] 05:49:10 Wed May 26 [faux@backtrack-askapache:/dev/pts/0 +1] ~
(1:347)$ export PVE="\\033[m\\033[38;5;2m813\\033[38;5;22m/1024MB\\t\\033[m\\033[38;5;55m0.25 0.22 0.18 1/66 26820\\033[m"
&gt;&gt;&gt; export &#039;PVE=\033[m\033[38;5;2m813\033[38;5;22m/1024MB\t\033[m\033[38;5;55m0.25 0.22 0.18 1/66 26820\033[m&#039;
&gt;&gt;&gt; PVE=&#039;\033[m\033[38;5;2m813\033[38;5;22m/1024MB\t\033[m\033[38;5;55m0.25 0.22 0.18 1/66 26820\033[m&#039;
&gt;&gt;&gt; history -a
&gt;&gt;&gt; (( 67 % 10==0  ))
&gt;&gt;&gt; echo -en &#039;\033[m\033[38;5;2m813\033[38;5;22m/1024MB\t\033[m\033[38;5;55m0.25 0.22 0.18 1/66 26820\033[m&#039;</pre>








<h2>256 Color Prompt Command</h2>
<p class="bnote"><strong>NOTE:</strong> I have been preparing a 256color terminal article for some time now, as I have tweaked, hacked, read, and experimented with more than I would ever like to admit.  So stay tuned, there isn't any tutorial, book, or online howto remotely close to as good as what I'm close to posting...</p>
<p><a href="http://www.askapache.com/linux/bash-power-prompt.html/super-optimized-256color-prompt/" rel="attachment wp-att-4297"><img src="http://uploads.askapache.com/2010/03/super-optimized-256color-prompt.png" alt="Super-optimized 256color BASH Prompt" title="Super-optimized 256color BASH Prompt" width="726" height="177" class="size-full wp-image-4297" /></a></p>
<p><a href="http://www.askapache.com/linux/bash-power-prompt.html/256-color-prompt/" rel="attachment wp-att-4280"><img src="http://uploads.askapache.com/2010/03/256-color-prompt.png" alt="256 color prompt_command and PS1" title="256 color prompt" width="642" height="147" class="size-full wp-image-4280" /></a></p>
<p>If you have a 256-color enabled terminal try this..<br class="C" /></p>
<pre>    export PROMPT_COMMAND=&#039;echo -en "\033[m\033[38;5;2m"$(( `sed -n "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024))"\033[38;5;22m/"$((`sed -n "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024 ))MB"\t\033[m\033[38;5;55m$(&lt; /proc/loadavg)\033[m"&#039;
    export PS1=&#039;\[\e[m\n\e[1;30m\][$$:$PPID \j:\!\[\e[1;30m\]]\[\e[0;36m\] \T \d \[\e[1;30m\][\[\e[1;34m\]\u@\H\[\e[1;30m\]:\[\e[0;37m\]${SSH_TTY} \[\e[0;32m\]+${SHLVL}\[\e[1;30m\]] \[\e[1;37m\]\w\[\e[0;37m\] \n($SHLVL:\!)\$ &#039;</pre>
<p>Which double-quoted is:</p>
<pre>declare -x PROMPT_COMMAND="echo -en \"\\033[m\\033[38;5;2m\"\$(( \`sed -n \"s/MemFree:[\\t ]\\+\\([0-9]\\+\\) kB/\\1/p\" /proc/meminfo\`/1024))\"\\033[38;5;22m/\"\$((\`sed -n \"s/MemTotal:[\\t ]\\+\\([0-9]\\+\\) kB/\\1/Ip\" /proc/meminfo\`/1024 ))MB\"\\t\\033[m\\033[38;5;55m\$(&lt; /proc/loadavg)\\033[m\""
declare -x PS1="\\[\\e[m\\n\\e[1;30m\\][\$\$:\$PPID \\j:\\!\\[\\e[1;30m\\]]\\[\\e[0;36m\\] \\T \\d \\[\\e[1;30m\\][\\[\\e[1;34m\\]\\u@\\H\\[\\e[1;30m\\]:\\[\\e[0;37m\\]\${SSH_TTY} \\[\\e[0;32m\\]+\${SHLVL}\\[\\e[1;30m\\]] \\[\\e[1;37m\\]\\w\\[\\e[0;37m\\] \\n(\$SHLVL:\\!)\\\$ "</pre>

<p class="cnote"><strong>For Commandlinefu.com users</strong>:  Here ya go!  <a href='http://www.askapache.com/linux/bash-power-prompt.html/toprc/' rel='attachment wp-att-4414'>toprc</a></p>

<p>That looks great, and is practicallly totally free in terms of how much cpu/work it makes the shell do for each command.  So for slow terminals, or text-terminals like I use, this is great.  Other than PS1, there is 1 other variable..  It's called PROMPT_COMMAND and is execed right in front of the PS1.  I show 2 ways to utilize this, the goal being to show there is no right way.. fast is fast and money is money.  I use a function called aa_pc I threw together that shows me in color how much memory is on my system.. very cool.</p>


<h2>PROMPT = ?</h2>
<p>Here's a screenshot of the code in my vim + screen multiplexed bash 4 environment..   It's placed all the way at the bottom of the file and is the last thing executed by the client processing the script.  Also, while it's great to look so good, this is all 100% for efficiency since I use one shell or another every day.</p>
<div id="attachment_4177" class="wp-caption alignnone" style="width: 805px"><a href="http://www.askapache.com/linux/bash-power-prompt.html/bash-prompt-screenshot/" rel="attachment wp-att-4177"><img src="http://uploads.askapache.com/2010/03/bash-prompt-screenshot.png" alt="Custom Power Prompt - currently mine" title="Custom Power Prompt -
currently mine" width="795" height="596" class="size-full wp-image-4177" /></a><p class="wp-caption-text">Custom Power Prompt - currently mine</p></div>


<p>Here's the code I'm using today, that produced this screen-shot -- I am always changing stuff so it's a little more tough to figure out.</p>
<pre>  function aa_pc()
  {
        local M=$( free -olm|sed "/Mem/!d; s/Mem:[^0-9]*\([0-9]*\)[^0-9]*\([0-9]*\)[^0-9]*\([0-9]*\).*/ \
        ${GREP_COLOR}\2MB${R}\/\3MB/"; ); echo -e "$M `pwd`"
  }
&nbsp;
  aa_grep_color(){ export GREP_COLOR=`tput setaf $(aa_random_under 6)`; }
  aa_random_under(){ echo -en $(( $RANDOM % ${1:-$RANDOM} + 1 )); }
  uptime1(){ sed &#039;/.*,  \([0-9]*\) users,  load average: \(.*\)/!d; s//[ \2, \1 users ]/;q&#039;;
&nbsp;
  $SED -n &#039;/i/!Q2&#039; &lt;&lt;&lt; $- &amp;&amp; \
  {
        case ${TERM:-dummy} in xterm*|screen*|*color*)echo; ;; *) return; esac;
  }
&nbsp;
  # hack for being able to source all the functions in this file from a script
  MASTER_RESET=$`echo -e "rs1\nrs2\ninitc\nis2\ncnorm\nrmso\nsgr0" | tput -S`
&nbsp;
  # only for color-aware (some guessing) terminals, kick everyone else OUT
  case ${TERM:-dummy} in xterm*|screen*|*color*)echo; ;; *) return; esac;
&nbsp;
  [[ -r /etc/DIR_COLORS ]] &amp;&amp; eval `dircolors -b /etc/DIR_COLORS`
&nbsp;
  # changes the window title in terminals like putty or konsole
  echo -ne "\033]0; ${USER}@${HOSTNAME}  +${SHLVL} @${SSH_TTY/\/dev\/} - `uptime1` \007"
&nbsp;
  # show title, setup the colors, vars, funcs, settings
  asetup_colors &amp;&amp; ascript_title
  export PROMPT_COMMAND=&#039;history -a;aa_pc&#039;
  export PS1=&#039;\[\033[1;30m\][$$:$PPID - \j:\!\[\033[1;30m\]]\[\033[0;36m\] \T\
  \d \[\033[1;30m\][\[\033[1;34m\]\u@\H\[\033[1;30m\]:\[\033[0;37m\]${SSH_TTY} \
  \[\033[0;32m\]+${SHLVL}\[\033[1;30m\]] \[\033[1;37m\]\w\[\033[0;37m\] \n\$ &#039;</pre>



<p><a href="http://www.askapache.com/linux/bash-power-prompt.html"><img src="http://uploads.askapache.com/2010/03/bash-power-prompt-ss.png" alt="bash power prompt screenshot" title="bash power prompt screenshot" width="898" height="480" /></a></p>
<p>I've used many shells over the years and have learned many tweaks and tricks for a powerful prompt.  It may look deceptively simple.  One cool thing this prompt does is display the command line (filtered) in the putty/konsole/xterm window, so if you have several windows minimized you can easily find the one you are looking for.<br class="C" /></p>

<p>There is a lot of good info about the BASH prompt around the net, but it can be complicated for a new user, and as an advanced user you will notice most of the info is very outdated and not very optimized for speed.  To get this articles recommended prompt working is devastatingly simple, just export the <code>PROMPT_COMMAND</code> and <code>PS1</code> variables that are shown below.  Most "power prompts" that utilize things like PROMPT_COMMAND do so very haphazardly or very extravagantly.</p>
<p>I've been called a lot of things but not extravagant, and because I use this prompt on many different servers, platforms, and systems I made sure to not make things complicated.  To test them just copy and paste the code below into your shell which will <strong>export PROMPT_COMMAND</strong> and <strong>PS1</strong> variables and work right away.  So test it out, and if you like it add it to your .bashrc or other startup file (please do a <code>$ man bash</code>).</p>


<ul>
<li><a href="#power-prompt-commands">Custom Power Prompt Commands</a><ol>
     <li><a href="#prompt_command">PROMPT_COMMAND Detailed</a></li>
     <li><a href="#detailed-ps1">PS1 Detailed</a></li>
</ol></li>
<li><a href="#hacker-prompts">Additional Info for Hackers</a><ol>
     <li><a href="#set-xterm-title">Setting Window Title</a></li>
     <li><a href="#strip-colors">Stripping Colors from PS1</a></li>
     <li><a href="#uptime-alt">Alternative to Uptime/Loadavg (proc)</a></li>
     <li><a href="#multi-prompt-switcher">Multi-Prompt Switcher Function</a></li>
  </ol></li>
<li><a href="#bash-prompt-reading">Bash Prompts - More Reading</a><ol>
      <li><a href="#ps1-examples">Other Simple Power Prompt Examples</a></li>
     <li><a href="#bash-prompt-vars">All Prompt Variables</a></li>
     <li><a href="#prompt-escapes">Escape Codes for PS1</a></li>
<li><a href="#more-reading">Additional Reading</a></li>
  </ol></li>
</ul>



<p><a id="power-prompt-commands" name="power-prompt-commands"></a></p>
<h2>Bash Power Prompt</h2>
<p><a href="http://www.askapache.com/linux/bash-power-prompt.html"><img src="http://uploads.askapache.com/2010/03/bash-power-prompt-ps1.png" alt="bash power prompt PS1" title="bash power prompt PS1" width="513" height="96" /></a><br />From setting the window title to show the last run command (filtered), saving your history and keeping multi-session history intact, resetting the color/cursor/highlighting of errant color-emitting commands, this prompt does more than meets the eye extremely fast.</p>
<p class="enote">Don't have much time? Don't care?  You may copy and paste these 2 lines into your shell and that's all there is to it!</p>
<pre>export PROMPT_COMMAND=&#039;export H1="`history 1|sed -e "s/^[\ 0-9]*//; s/[\d0\d31\d34\d39\d96\d127]*//g; s/\(.\{1,50\}\).*$/\1/g"`";history -a;echo -e "sgr0\ncnorm\nrmso"|tput -S&#039;
export PS1=&#039;\n\e[1;30m[\j:\!\e[1;30m]\e[0;36m \T \d \e[1;30m[\e[1;34m\u@\H\e[1;30m:\e[0;37m`tty 2&gt;/dev/null` \e[0;32m+${SHLVL}\e[1;30m] \e[1;37m\w\e[0;37m\[\033]0;[ ${H1}... ] \w - \u@\H +$SHLVL @`tty 2&gt;/dev/null` - [ `uptime` ]\007\]\n\[\]\$ &#039;</pre>


<p><a id="prompt_command" name="prompt_command"></a></p>
<h2>PROMPT_COMMAND</h2>
<p>This holds commands to be run prior to displaying the prompt.  Let's break it down.</p>
<p><a href="http://www.askapache.com/linux/bash-power-prompt.html"><img src="http://uploads.askapache.com/2010/03/askapache-prompt.jpg" alt="PS1 Prompt Example" title="PS1 Prompt Example" width="663" height="120" class="size-full wp-image-4150" /></a>
<p>First this takes the last command executed and filters it using sed to remove the initial history command number, and also to remove any quotes (single or double) and/or backticks.  Also, it only saves the first 50 chars, which are then exported as the value of H1, which because it is exported is now globally accessible to the rest of the shell.  This is important because we use this variable in PS1 to print the last run command as the title of our putty window (or konsole).</p>
<pre>export H1=`history 1 | sed -e &#039;s/^[\ 0-9]*//; s/[\d0\d31\d34\d39\d96\d127]*//g; s/\(.\{1,50\}\).*$/\1/g&#039;`</pre>

<p>The next command simply appends your last command to the history file.  Usually this is <code>~/.bash_profile</code>, or whatever <code>$HISTFILE</code> is.  This makes sure you never lose history in case of a shell crash or ssh connection terminated. </p>
<pre>history -a</pre>

<p>Finally there is this golden nugget of shell kung-fu.  This outputs 3 terminal escape sequences according to the terminal in use and its capabilities.. so very robust, should work on any shell newer than 1984.  By echoing the following 3 term names separated by a newline <code>\n</code> and using tput -S it will output the terminal sequences for all 3.  sgr0 resets the colors, cnorm resets the cursor, and rmso resets the background color.</p>
<p class="cnote">You can view the escape sequences generated by tput with strace, cat -t, etc..  For instance on my shell (xterm-256color via portaputty) the below command generates: <code>\33(B\33[m\33[?12l\33[?25h\33[27m</code>.  This is helpful because if you aren't coding for several terminals you can hard code that in your echo's instead of using tput, saving some overhead.</p>
<pre>echo -e &#039;sgr0\ncnorm\nrmso&#039; | tput -S
# For my term this is the same as if I just did
# echo -e "\33(B\33[m\33[?12l\33[?25h\33[27m"</pre>






<p><a id="detailed-ps1" name="detailed-ps1"></a></p>
<h2>PS1 Detailed</h2>
<p><code>PS1</code> is the variable that is expanded as your prompt.  So if you did a <code>$ unset PS1</code> then you can still run commands and everything, but your screen will be blank which is confusing to say the least.</p>
<p><a href="http://www.askapache.com/linux/bash-power-prompt.html"><img src="http://uploads.askapache.com/2010/03/askapache-htop.jpg" alt="The HTOP command in full color to manage mysql" title="The HTOP command in full color to manage mysql" width="404" height="176" class="size-full wp-image-4149" /></a></p>

<p>This PS1 shows which SHLVL level the shell is in, which is how many levels deep of shells you are currently at.  If you run <code>$ bash -l</code> from a bash shell it will create a new instance of bash as a child of the calling bash, so the SHLVL (shell level) gets incremented by 1.  I usually avoid creating subshells by instead executing a new bash with <code>exec</code> which instead of creating a new bash as a child of the current bash, it replaces the current bash process with the new one: <code>$ exec bash -l</code>.</p>

<pre>export PS1=&#039;\n\e[1;30m[\j:\!\e[1;30m]\e[0;36m \T \d \e[1;30m[\e[1;34m\u@\H\e[1;30m:\e[0;37m`tty 2&gt;/dev/null` \e[0;32m+${SHLVL}\e[1;30m] \e[1;37m\w\e[0;37m\[\033]0;[ ${H1}... ] \w - \u@\H +$SHLVL @`tty 2&gt;/dev/null` - [ `uptime` ]\007\]\n\[\]\$ &#039;
&nbsp;
# with nocolors
# export PS1=&#039;\n[\j:\!] \T \d [\u@\H:`tty 2&gt;/dev/null` +${SHLVL}] \w\[\033]0;[ ${H1}... ] \w - \u@\H +$SHLVL @`tty 2&gt;/dev/null` - [ `uptime` ]\007\]\n\[\]\$ &#039;</pre>

<h3>TTY</h3>
<p>This command is very useful for me because I use multiplexed terminals, about 6 at a time, so it is crucial sometimes to know which tty I am using.  Since SSH is the ONLY protocol I ever use for anything, I used to depend on the SSH_TTY variable being set instead of using tty, which as a command has more overhead then just echoing a variable.  But I found that when running multiplexing terminals with tmux, screen, etc.. the SSH_TTY variable stays with the initial tty created upon login.   <strong>Note:</strong> <code>2&gt;/dev/null</code> redirects any errors that running the tty command might issue to the /dev/null device, which is the same thing as a black hole, it goes nowhere so is an efficient way to send data for deletion.  Depending on your server and ssh settings you may not even have a tty or it may just appear that you do not.  Some web hosting companies do odd things to prevent their users from using tty devices and programs.  But if you get a little creative you can always find the current tty.. like <code>$ readlink /proc/self/fd/0</code> will return the same thing as <code>$ tty</code>.</p>
<pre>`tty 2&gt;/dev/null`</pre>

<p><a id="set-xterm-title" name="set-xterm-title"></a></p>
<h3>Changing Window Title with PS1</h3>
<p>This simple bash function changes the title of the window to the passed parameter.  The key thing to note is that this works because of the special escapes on either end of the echo'd data.</p>
<pre>function set_window_title()
{
  echo -e "\033]0; ${1:-$USER@$HOST - $SHLVL} \007";
}</pre>










<p><a id="hacker-prompts" name="hacker-prompts"></a></p>
<h2>Additional Info for Hackers</h2>
<p>More reading and digging.</p>

<p><a id="strip-colors" name="strip-colors"></a></p>
<h3>Strip Colors for Readability</h3>
<p>You can use this command to strip a PS1 of all colors, which shortens the variable dramatically in some cases.</p>
<pre>sed &#039;s/\\[eE][[0-9]*;[0-9]*m//g&#039; &lt;&lt;&lt; $PS1
# ie export PS1=$(sed &#039;s/\\[eE][[0-9]*;[0-9]*m//g&#039; &lt;&lt;&lt; $PS1);</pre>



<p><a id="multi-prompt-switcher" name="multi-prompt-switcher"></a></p>
<h3>Multi-Prompt Switcher Function</h3>
<p>This function demonstrates 1 way that you can change your prompts at will.  It creates an array named AAPS that you can add as many PS1 values to as you want.  Each time the function is run it simply changes the prompt string variable PS1 to the value of the next item in the AAPS array.  Once it reaches the last item in AAPS, it resets back to the first <code>AAPS[0]</code> prompt.  Just an example to play with, not tested very much.</p>
<pre>aa_multi_prompt ()
{
    declare -a AAPS;
    AAPS[0]=&#039;\n[\j:\!] \T \d [\u@\H:`tty 2&gt;/dev/null` +${SHLVL}] \w\[\033]0;[ ${H1}... ] \w - \u@\H +$SHLVL @`tty 2&gt;/dev/null` - [ `uptime` ]\007\]\n\[\]\$&#039;;
    AAPS[1]=&#039;\n[\j:\!] \T \d \n[\u@\H:`tty 2&gt;/dev/null` +${SHLVL}] \w\[\033]0;[ ${H1}... ] \w - \u@\H +$SHLVL @`tty 2&gt;/dev/null` - [ `uptime` ]\007\]\n\[\]\$&#039;;
&nbsp;
    : ${PLVL:=0};
    [[ "${#AAPS[@]}" -lt "$PLVL" || "${#AAPS[@]}" -eq "$PLVL" ]] &amp;&amp; PLVL=0;
    export PS1=${AAPS[$PLVL]} &amp;&amp; (( PLVL++ )) &amp;&amp; export PLVL
}</pre>


<h3>BASH 4 Multi-Prompt</h3>
<p>Here's an example from bash-4, but it works for all bash versions.</p>
<pre>prompt ()
{
    case "$1" in
        d)
            PS1=&#039;$(dirs) \$ &#039;
        ;;
        n)
            PS1=&#039;\$ &#039;
        ;;
        hsw)
            PS1=&#039;\h[$SHLVL]: \w \$ &#039;
        ;;
        hw)
            PS1=&#039;\h: \w \$ &#039;
        ;;
        sh)
            PS1=&#039;[$SHLVL] \h\$ &#039;
        ;;
        sw)
            PS1=&#039;[$SHLVL] \w \$ &#039;
        ;;
        uh)
            PS1=&#039;\u@\h\$ &#039;
        ;;
        uhsHw)
            PS1=&#039;\u@\h[$SHLVL]:\#: \w \$ &#039;
        ;;
        uhsw)
            PS1=&#039;\u@\h[$SHLVL]: \w \$ &#039;
        ;;
        uhw)
            PS1=&#039;\u@\h: \w \$ &#039;
        ;;
        uw)
            PS1=&#039;(\u) \w \$ &#039;
        ;;
        w)
            PS1=&#039;\w \$ &#039;
        ;;
    esac
}</pre>

<p><a id="uptime-alt" name="uptime-alt"></a></p>
<h3>Alternative to uptime:</h3>
<pre>echo "Up for $(( $(sed &#039;s/^\([0-9]*\).*/\1/&#039; /proc/uptime) / (60*60*24) )) days - [`cat /proc/loadavg`]"
# or
echo "Uptime: $(( `sed &#039;s/^\([0-9]*\).*/\1/g&#039; /proc/uptime` / 86400 )) days. Load: $(&lt;/proc/loadavg)"</pre>





<p><a id="bash-prompt-reading" name="bash-prompt-reading"></a></p>
<h2>Bash Prompts - More Reading</h2>

<p><a id="bash-prompt-vars" name="bash-prompt-vars"></a></p>
<h3>All Bash Prompt Variables</h3>
<p>These are the environment variables provided by BASH (and most shells) and control your prompt string.   While all are interesting and good to know about, <code>PROMPT_COMMAND</code> and <code>PS1</code> are the only ones that directly modify the prompt that is displayed.</p>
<dl>
<dt>PROMPT_COMMAND</dt>
<dl>If set, the value is executed as a command <strong>prior</strong> to issuing each primary prompt.</dl>
<dt>PS1</dt>
<dl>The value of this parameter is expanded and used as the primary prompt string.  The default value is "<code>\s-\v\$ </code>".</dl>
<dt>PS2</dt>
<dl>The value of this parameter is expanded as with PS1 and used as the secondary prompt string.  The default is "<code>&gt; </code>".</dl>
<dt>PS3</dt>
<dl>The value of this parameter is used as the prompt for the select command.</dl>
<dt>PS4</dt>
<dl>The  value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace.  The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection.  The default is "<code>+</code>".</dl>
</dl>



<p><a id="prompt-escapes" name="prompt-escapes"></a></p>
<h3>Prompt Escape Codes</h3>
<p>When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command and the secondary prompt PS2 when it needs more input to complete a command.  Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:</p>
<ul>
<li><code>\a</code> - an ASCII bell character (07)</li>
<li><code>\d</code> - the date in "Weekday Month Date" format (e.g., "Tue May 26")</li>
<li><code>\D{format}</code> - the format is passed to <a href="http://www.freebsd.org/cgi/man.cgi?query=strftime">strftime(3)</a> and the result is inserted into the prompt string; an empty format results in a locale-specific time representation.  The braces are required
<li><code>\e</code> - an ASCII escape character (033)</li>
<li><code>\h</code> - the hostname up to the first '.'</li>
<li><code>\H</code> - the hostname</li>
<li><code>\j</code> - the number of jobs currently managed by the shell</li>
<li><code>\l</code> - the basename of the shellâs terminal device name</li>
<li><code>\n</code> - newline</li>
<li><code>\r</code> - carriage return</li>
<li><code>\s</code> - the name of the shell, the basename of <var>$0</var> (the portion following the final slash)</li>
<li><code>\t</code> - the current time in 24-hour HH:MM:SS format</li>
<li><code>\T</code> - the current time in 12-hour HH:MM:SS format</li>
<li><code>\@</code> - the current time in 12-hour am/pm format</li>
<li><code>\A</code> - the current time in 24-hour HH:MM format</li>
<li><code>\u</code> - the username of the current user</li>
<li><code>\v</code> - the version of bash (e.g., 2.00)</li>
<li><code>\V</code> - the release of bash, version + patch level (e.g., 2.00.0)</li>
<li><code>\w</code> - the current working directory, with <var>$HOME</var> abbreviated with a tilde</li>
<li><code>\W</code> - the basename of the current working directory, with <var>$HOME</var> abbreviated with a tilde</li>
<li><code>\!</code> - the history number of this command</li>
<li><code>\#</code> - the command number of this command</li>
<li><code>\$</code> - if the effective UID is 0, a <strong>#</strong>, otherwise a <strong>$</strong></li>
<li><code>\nnn</code> - the character corresponding to the octal number nnn
<li><code>\\</code> - a backslash</li>
<li><code>\[</code> - begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt</li>
<li><code>\]</code> - end a sequence of non-printing characters</li>
</ul>
<p>The  command  number  and the history number are usually different: the history number of a command is its position in the history list, which may include commands restored from the history file, while the command number is the position in the sequence of commands executed during the current shell session.  After the string is decoded, it is expanded via parameter expansion, command substitution, arithmetic expansion, and quote removal, subject to the value of the promptvars shell option, which if set, prompt strings undergo parameter expansion, command substitution, arithmetic expansion, and quote removal after being expanded as described in PROMPTING above.   <var>promptvars</var> is enabled by default.</p>


<p><a href="http://www.askapache.com/linux/bash-power-prompt.html"><img src="http://uploads.askapache.com/2010/03/bash-power-prompt-ps1.png" alt="bash power prompt PS1" title="bash power prompt PS1" width="513" height="96" /></a></p>


<p><a id="ps1-examples" name="ps1-examples"></a></p>
<h3>More Example Prompts</h3>
<pre>export PS1="\n\e[1;37m[\e[0;32m\u\e[0;35m@\e[0;32m\h\e[1;37m]\e[1;37m[\e[0;31m\w\e[1;37m]\n$ \e[0m"
[user@host][~/bin/tools]
$</pre>

<pre>export PS1="\n[$?]\e[1;37m[\e[0;32m\u\e[0;35m@\e[0;32m\h\e[1;37m]\e[1;37m[\e[0;31m\w\e[1;37m]($SHLVL:\!)\n\[\033[0m\]\$ "
[0][user@host][~/bin/tools](1:2130)</pre>

<pre>export PS1=&#039;\[\033[1;33m\]\u\[\033[1;37m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\$ \[\033[0m\]&#039;
user@host:~/bin/tools $</pre>

<pre>export PS1="\e[1;31m[\h]$NC \W &gt; \[\033]0;\${TERM} [\u@\h] \w\]"
[lifesaver] tools &gt;</pre>




<h2>Benchmarking PROMPT_COMMAND</h2>
<p>When figuring out how resource intensive your prompt_command is (if you choose to do that sort of thing), it's nice to do it like this.  I ended up using  this information from the following test to create the prompt_command used in the first 256-color prompt above.</p>
<pre>#!/bin/bash
&nbsp;
function clean_results()
{
      grep ^real | cut -dm -f2 | sort | uniq -c | sort -n
}
&nbsp;
for i in {0..500};
do
      time sh -c "expr `sed -nu &#039;s/^MemFree:[\t ]\+\([0-9]\+\) kB/\1/Ip&#039; /proc/meminfo`/1024" &amp;&gt;/dev/nulll;
done 2&gt;&amp;1 | clean_results
&nbsp;
# print separating line
printf "%$((${COLUMNS:-`tput cols`} - 10))s\n" &#039; &#039; | sed -u &#039;s/ /-/g&#039;
&nbsp;
for i in {0..500};
do
      time sh -c "echo $(( `sed -nu &#039;s/^MemFree:[\t ]\+\([0-9]\+\) kB/\1/Ip&#039; /proc/meminfo`/1024 ))" &amp;&gt;/dev/null;
done 2&gt;&amp;1 | clean_results
&nbsp;
exit $?</pre>

<p>Generates this output, meaning that using expr takes longer.</p>
<pre>      1 0.011s
      1 0.014s
      2 0.009s
      2 0.012s
      5 0.008s
     12 0.004s
     47 0.007s
    215 0.005s
    216 0.006s
---------------------------------------------------------------------
      1 0.003s
      2 0.007s
     59 0.006s
    196 0.004s
    243 0.005s</pre>




<p><a id="more-reading" name="more-reading"></a></p>
<h3>Additional Links</h3>
<ul>
<li><a href="http://tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html">From Power Up To Bash Prompt - TLDP</a></li>
<li><a href="http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Bash-Prompt-HOWTO.html">Bash Prompt HOWTO -TLDP</a></li>
<li><a href="http://tldp.org/LDP/abs/html/sample-bashrc.html">A Sample .bashrc File - TLDP</a></li>
<li><a href="http://gentoo.linuxhowtos.org/bash/bash_prompt_howto.htm">Gentoo Linux Howtos: bash -> Bash Prompt Howto - Gentoo</a></li>
<li><a href="http://www.debian-administration.org/article/Fancy_Bash_Prompts">Fancy Bash Prompts - Debian Administration</a></li>
</ul><p><a href="http://www.askapache.com/linux/bash-power-prompt.html"></a><a href="http://www.askapache.com/linux/bash-power-prompt.html">Crazy POWERFUL Bash Prompt</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/linux/bash-power-prompt.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Custom bash_profile for Advanced Shell Users</title>
		<link>http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html</link>
		<comments>http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html#comments</comments>
		<pubDate>Mon, 23 Nov 2009 20:32:26 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3183</guid>
		<description><![CDATA[<p>Looking for some <strong>advanced uses for the shell</strong>?  Here is <del>some of</del> my best.  The shell is where 70% of my work takes place, and I have at least one terminal open almost 100% of the time, for viewing tailing color-coded logs, and of course for the SSH Tunnels that I use to route various networking through, like my email.  So I decided that to standardize and create a bash_profile containing the most time-saving and helpful functions that I could use on all the various hosting environments would really be some sweet sugar, so here is my constant Work-in-progress.</p>
<p>It works for all shells I encounter, including BackTrack, Debian, Knoppix, Arch Linux, etc.   Also works for many hosting environments I use including DreamHost, HostGator, WiredTree, and pretty much any linux VPS.</p>
<p>I also rely on this heavily from within shell scripts I write to access all the functions and stuff in this .bash_profile, and to do that I just do like:</p>
<pre>
#!/bin/bash
&#160;
source ~/.bash_profile &#38;amp;&#62;/dev/nulll
&#160;
pm "PM is a function to output nice messages with color"
yn "Are you enjoying the shell" &#38;amp;&#38;amp; pm "Thats great!" &#124;&#124; pm "Perhaps you&#039;re better suited for DOS"
yn "Show Calendar" &#38;amp;&#38;amp; aa_calendar
yn "Show Fortune" &#38;amp;&#38;amp; aa_fortune
</pre>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html"></a><a href="http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html"><cite>AskApache.com</cite></a></p><p>Looking for some <strong>advanced uses for the shell</strong>?  Here is <del>some of</del> my best.  Works for all shells I encounter, including BackTrack, Debian, Knoppix, Arch Linux, etc.   Also works for many hosting environments I use including DreamHost, HostGator, WiredTree, and pretty much any linux VPS.</p>

<p class="anote">Want to get started?  Type the following in your shell to download the script and run it.  You should go over the code first and then you can just save it as your .bash_profile - whenever you want to get updated to the latest version just type aaup, a cool update function that auto dos2unix's and runs via an exec command.</p>
<pre>
curl -O http://static.askapache.com/askapache-bash-profile.txt &amp;&amp; source askapache-bash-profile.txt
Or if you trust me and my hosting provider (and you aren&#039;t on production)
curl -o ~/.bash_profile http://static.askapache.com/askapache-bash-profile.txt &amp;&amp; exec bash -l
</pre>

<p>For those of you power users and server admins that use Bash, ksh, csh, vanilla sh, etc.., or if you are just passionate about shell scripting, because it allows you to get advanced tasks done fast and efficiently, not to mention automated automatically.  I give you my .bash_profile file.   You should edit it to fit your needs, (especially the exported vars like PATH, LDFLAGS, if you don't understand something just comment it out) but it's pretty universal because I work on alot of other people's servers not to mention many different distros and platforms, and when I get hired to do some server work through a shell, I bring this script along for the ride.</p>


<h2>askapache-bash-profile.txt</h2>
<p>You can download the latest version: <a href="http://static.askapache.com/askapache-bash-profile.txt">http://static.askapache.com/askapache-bash-profile.txt</a></p>
<p>The functions and variables below are the way bash sees them, using declare -f, and alias, to make it easier for you to read and understand them.    The actual file at <a href="http://static.askapache.com/askapache-bash-profile.txt">http://static.askapache.com/askapache-bash-profile.txt</a> will always be the most updated version, as I use it personally.  And it has the whole file the way I wrote it, meaning many extra notes and much simpler to follow. Enjoy!</p>


<h2>Gist of the Script..</h2>
<p>I also rely on this heavily from within shell scripts I write to access all the functions and stuff in this .bash_profile, and to do that I just do like:</p>
<pre class='prettyprint'>
#!/bin/bash
&nbsp;
source ~/.bash_profile &amp;&gt;/dev/nulll
&nbsp;
pm "PM is a function to output nice messages with color"
yn "Are you enjoying the shell" &amp;&amp; pm "Thats great!" || pm "Perhaps you&#039;re better suited for DOS"
yn "Show Calendar" &amp;&amp; aa_calendar
yn "Show Fortune" &amp;&amp; aa_fortune
</pre>

<pre>
alias chmod=&#039;command chmod -c&#039;
alias cpr=&#039;command cp -rpv&#039;
alias df=&#039;command df -kTh&#039;
alias df1=&#039;command df -iTa&#039;
alias diff=&#039;diff -up&#039;
alias dsiz=&#039;du -sk * | sort -n --&#039;
alias du=&#039;command du -kh&#039;
alias du1=&#039;echo *|tr " " "\n" |xargs -iFF command du -hs FF|sort&#039;
alias env=&#039;command env | sort&#039;
alias h=&#039;history&#039;
alias inice=&#039;ionice -c3 -n7 nice&#039;
alias j=&#039;jobs -l&#039;
alias la=&#039;command ls -Al --color=auto&#039;
alias lc=&#039;command ls -lAcr --color=auto&#039;
alias less=&#039;vless&#039;
alias lessc=&#039;ccze -A |`type -P less` -R&#039;
alias lk=&#039;command ls -lASr --color=auto&#039;
alias llh=&#039;ll -h&#039;
alias lll=&#039;stat -c %a\ %N\ %G\ %U ${PWD}/*|sort&#039;
alias lr=&#039;command ls -lAR --color=auto&#039;
alias lt=&#039;command ls -lAtr --color=auto&#039;
alias lu=&#039;command ls -lAur --color=auto&#039;
alias lx=&#039;command ls -lAXB --color=auto&#039;
alias mann=&#039;command man -H&#039;
alias n=&#039;/usr/bin/nano3&#039;
alias p=&#039;command ps -HAcl -F S -A f|uniq -w3&#039;
alias path=&#039;echo -e ${PATH//:/\\n}&#039;
alias php=&#039;php -d report_memleaks=1 -d report_zend_debug=1 -d log_errors=0 -d ignore_repeated_errors=0 -d ignore_repeated_source=0 -d error_reporting=30719 -d display_startup_errors=1 -d display_errors=1&#039;
alias pp=&#039;command ps -HAcl -F S -A f&#039;
alias ps1=&#039;command ps -lFA&#039;
alias ps2=&#039;command ps -H&#039;
alias resetw=&#039;echo $&#039;\&#039;&#039;\33[H\33[2J&#039;\&#039;&#039;&#039;
alias subash=&#039;sudo sh -c &#039;\&#039;&#039;export HOME=/root; cd /root; exec bash -l&#039;\&#039;&#039;&#039;
alias top=&#039;top -c&#039;
alias tree=&#039;command tree -Csuflapi&#039;
alias updatedb=&#039;( ( updatedb 2&gt;/dev/null ) &amp; )&#039;
alias vim=&#039;command vim --noplugin&#039;
alias who=&#039;command who -ar -pld&#039;
alias wtf=&#039;watch -n 1 w -hs&#039;
</pre>




<p><a href="http://uploads.askapache.com/2009/08/askapache-bash_profile.png"><img src="http://uploads.askapache.com/2009/08/askapache-bash_profile.png" alt="Custom bash profile for Advanced Shell Users" title="askapache-bash_profile" width="571" height="2879" /></a></p><p><a href="http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html"></a><a href="http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html">Custom bash_profile for Advanced Shell Users</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

