<?xml version="1.0" encoding="iso-8859-1"?>
        <?xml-stylesheet type="text/css" href="http://www.miek.nl/blog/"?>
<rss version="2.0"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:admin="http://webns.net/mvcb/"
 xmlns:atom="http://www.w3.org/2005/Atom"
>
<channel>
<title>Filed under: zsh | Miek</title>
<atom:link href="http://www.miek.nl/blog/archives/zsh/index-rss.xml" rel="self" type="application/rss+xml" />
<link>http://www.miek.nl/blog</link>
<description>Thoughts on (technical) stuff</description>
<dc:language>en-us</dc:language>
<dc:creator>Miek Gieben</dc:creator>
<dc:date>2012-02-04T04:15:11+01:00</dc:date>
<admin:generatorAgent rdf:resource="http://nanoblogger.sourceforge.net" />

<item>
<link>http://www.miek.nl/blog/archives/2011/09/18/color_me_color_you/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2011/09/18/color_me_color_you/index.html</guid>
<title>color me, color you</title>
<dc:date>2011-09-18T09:50:03+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> zsh, linux</dc:subject>
<description><![CDATA[<p>In <a href="http://www.miek.nl/blog/archives/2011/09/11/xoria256m_color_scheme/index.html">the xoria256m post</a>, 
I introduced my xoria256 like color scheme. Again, inspired by 
<a href="http://ethanschoonover.com/solarized">solarized</a>, I extended
this to other applications. So now I use this in the following apps:</p>

<ul>
<li>vim (see that previous post);</li>
<li>mutt (idem);</li>
<li>zsh;</li>
<li>dircolors;</li>
<li>git (a bit).</li>
</ul>

<h2>zsh</h2>

<p>See this file 
<a href="https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/spectrum.zsh">to setup the colors</a>. 
Then in my prompt I have stuff like:</p>

<pre><code>PS1=$'${vcs_info_msg_0_}$FG[067]%(1j.$myjobs% $FX[reset].$FX[reset])$FG[179]%#$FX[reset] '
RPS1="$RPSL%$MAXMID&lt;...&lt;$mypath$RPSR$FG[239]$FX[bold]$__ZH$FX[reset]${vcs_info_msg_1_}"
RPSR=$'$FX[reset]$FG[009]%(0?.$FG[reset]. $E)$FX[reset]'
</code></pre>

<p>For zsh I have two files that make up my prompt:</p>

<ul>
<li><a href="http://www.miek.nl/downloads/2011/zprompt">zprompt</a>, primary prompt setup;</li>
<li><a href="http://www.miek.nl/downloads/2011/zvcs">zvcs</a>, version control <code>vcs_info</code> stuff.</li>
</ul>

<p>Also see <a href="http://www.miek.nl/blog/archives/2008/02/20/my_zsh_prompt_setup/index.html">this older blog post</a> on this setup. 
This leads to a prompt looking like this (click for larger):</p>

<p>The normal prompt is very plain. Almost nothing is shown, left the
prompt <code>%</code> and on the right the PWD <code>~</code>:
<a href="http://miek.nl/gfx/2011/prompt-local.png"><img width="600px"
src="http://miek.nl/gfx/2011/prompt-local.png" title="Zsh " /></a></p>

<p>When logging in to a remote server, the hostname appears on the
right:
<a href="http://miek.nl/gfx/2011/prompt-remote.png"><img width="600px"
src="http://miek.nl/gfx/2011/prompt-remote.png" title="Zsh " /></a></p>

<p>When a program ends abnormally the exitcode is shown, in words (<code>-INT</code>)
and red when it isn't zero:
<a href="http://miek.nl/gfx/2011/prompt-exitcode.png"><img width="600px"
src="http://miek.nl/gfx/2011/prompt-exitcode.png" title="Zsh " /></a></p>

<p>When you background an app. the number of bg jobs appear in blue. The
one with the <code>+</code> is the current job. Multiple jobs are separated with commas:
<a href="http://miek.nl/gfx/2011/prompt-background.png"><img width="600px"
src="http://miek.nl/gfx/2011/prompt-background.png" title="Zsh " /></a></p>

<p>When you enter a git/svn/hg directory, the right side shows the type
(git, svn, hg) and on the left you get the current branch. 
<a href="http://miek.nl/gfx/2011/prompt-git.png"><img width="600px"
src="http://miek.nl/gfx/2011/prompt-git.png" title="Zsh " /></a></p>

<h1>dircolors</h1>

<p>Modified from Solarized, not quite finished, but certainly looks nice (IMHO).
See <a href="http://www.miek.nl/downloads/2011/dircolors">this dircolors file</a>, I use
it like:</p>

<pre><code>eval $(dircolors ./dircolors)
</code></pre>

<h1>git</h1>

<p>The <code>alias</code> section from my <code>.gitconfig</code>:</p>

<pre><code>[alias]
        st = status
        ci = commit
        br = branch
        co = checkout
        df = diff
        lg = log -p
        pl = pull
        ps = push
        timeline = log --graph \"--pretty=format:%C(192)%h%Creset by %C(bold 239)%an%Creset (%ar)%C(182)%d%Creset%n%s%n%b\" --all
</code></pre>

<p>The colors are selected with <code>%C(number)</code>.</p>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2010/01/05/my_f_function_in_zsh_and_maybe_bash/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2010/01/05/my_f_function_in_zsh_and_maybe_bash/index.html</guid>
<title>My f() function in Zsh (and maybe Bash)</title>
<dc:date>2010-01-05T20:04:17+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> zsh</dc:subject>
<description><![CDATA[<p>Familiar with the following?</p>

<p>You are aware of (shell)file which contains a interesting line and
you think: "I want to execute this line on the command prompt". Most
people will do the following:</p>

<pre><code>% more &lt;file&gt;
[select interesting bit with your mouse]
[paste]&lt;enter&gt;
</code></pre>

<p>And the code gets executed.</p>

<p>I propose the following function: <code>f()</code>, which does the following:</p>

<ol>
<li>It opens the file in $EDITOR (:= <code>vim</code> of course);</li>
<li>You delete everything you <em>don't</em> want to execute;</li>
<li>What's left gets executed;</li>
<li><em>And</em> it is added to your shell's history.</li>
</ol>

<p>The code of the function looks like this:</p>

<div class="nbcode">
<pre>
<span class="lnr">1 </span><span class="Type">int</span> main(<span class="Type">int</span> c) {
<span class="lnr">2 </span>    printf(<span class="Constant">&quot;This is nice&quot;</span>);
<span class="lnr">3 </span>    exit(<span class="Constant">1</span>);
<span class="lnr">4 </span>}
</pre>
</div>

<p>It should either be possible to use this verbatim in <code>bash</code> or make it
work with a few tweaks.</p>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2009/08/10/string_multiplication_in_zsh/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2009/08/10/string_multiplication_in_zsh/index.html</guid>
<title>String multiplication in zsh</title>
<dc:date>2009-08-10T19:46:31+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> perl, zsh</dc:subject>
<description><![CDATA[<p>In Perl you have this:</p>

<pre><code>% perl -e 'print "a" x 5, "\n"'
aaaaa
</code></pre>

<p>With that you can easily create a separator string
consisting out of 60 spaces.</p>

<p>I always missed this in my shell - until now.</p>

<p>In Zsh have the following expansion:</p>

<blockquote>
  <p>l:expr::string1::string2:</p>

<pre><code>Pad the resulting words on the left. Each word will be truncated if
required and placed in a field expr characters wide.
</code></pre>
</blockquote>

<p>See <a href="http://zsh.dotsrc.org/Doc/Release/Expansion.html">zsh.dotsrc.org</a>.
There is also a <code>r:</code> variant which operates in the same way.</p>

<p>And lo and behold:</p>

<pre><code>% echo ${(r:40::-:)A}
----------------------------------------
</code></pre>

<p>No more:</p>

<pre><code>A="------------------------------------"
</code></pre>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2009/07/21/case_insensitive_cd/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2009/07/21/case_insensitive_cd/index.html</guid>
<title>Case insensitive cd </title>
<dc:date>2009-07-21T00:10:43+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> zsh</dc:subject>
<description><![CDATA[<p>Do I want this?</p>

<pre><code>% ls -ld Joe_Cocker_-_The_Definitive_Collection 
drwxr-xr-x 2 miekg admin 4.0K Jul 20 22:20 Joe_Cocker_-_The_Definitive_Collection/
% cd *joe*
cd: no such file or directory: *joe*
% unsetop case_glob 
% cd *joe*
% pwd
/shared/vol/music/J/Joe_Cocker_-_The_Definitive_Collection
</code></pre>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2009/05/22/zsh_prompt_updates/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2009/05/22/zsh_prompt_updates/index.html</guid>
<title>Zsh prompt updates</title>
<dc:date>2009-05-22T18:13:49+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> zsh</dc:subject>
<description><![CDATA[<p>I wanted some <code>git</code> information in the prompt I currently have.
While thinking and googling about this, a quote on 
<a href="http://www.jukie.net/~bart">Bart's log</a> got me thinking. I don't need
to see my current host, nor do I need to see my current user name. </p>

<p>I always login under my own account (<code>miekg</code>) and if I <em>do</em> change
accounts, I probably will be forced to use <code>bash</code>. So showing the current user name
is quite useless.</p>

<p>Showing the host you are logged into is also <em>only</em> worth showing
when you <code>ssh</code>-ing to a remote host. </p>

<p>So my default prompt now only shows the prompt (<code>%</code>) on the left and
the current directory (<code>~</code>) on the right, like this:</p>

<p><img src="/gfx/2009/default-prompt.png" alt="Default zsh prompt" title="" /></p>

<p>Very clean.</p>

<p>When logging into a remote system, the hostname of the system
is added (in grey) to the right side of the prompt, like so:
(I'm <code>ssh</code>-ing to my other host called <code>elektron</code>, which is
electron in Dutch)</p>

<p><img src="/gfx/2009/remote-prompt.png" alt="Remote zsh prompt" title="" /></p>

<p>The code to do this:</p>

<pre><code>[[ -n "$SSH_CLIENT" ]] &amp;&amp; __ZH=$HOST
</code></pre>

<p>if <code>$SSH_CLIENT</code> is set, set <code>$__ZH</code> to the current hostname, then use
<code>$__ZH</code> in your prompt.</p>

<p>Next I wanted some <code>git</code> support in my prompt, there are 
<a href="http://github.com/jcorbin/zsh-git/blob/fca801c9978e17d7fba536e5461ade4d1238a046/functions/zgitinit">lots of sites</a>
which can help you. I stole code from <em>all</em> of them :)</p>

<p>There was however one annoying thing. I store my <em>entire</em> home directory
in <code>git</code>, but I don't want to see git information about it all the time.
So I created the following function to detect if my the current git
repository was the one from my home directory:</p>

<pre><code>zsh_git_home() {
# I have my homedir in git, quite annoying to see 'master' all the time
git_dir=$(git rev-parse --git-dir 2&gt; /dev/null)
[[ -z "$git_dir" ]] &amp;&amp; return 0
[[ $(realpath "$git_dir") == $HOME/.git ]] &amp;&amp; return 0
return 1
}
</code></pre>

<p>If I enter a <code>git</code> repository the current branch is put into the prompt
at the left side, here I enter a repository with the <code>master</code> branch.
(Note: as the window is very small my path is truncated)</p>

<p><img src="/gfx/2009/branch-prompt.png" alt="Branch zsh prompt" title="" /></p>

<p>Code is from <a href="http://www.jukie.net/~bart/blog/zsh-git-branch">Bart</a>.</p>

<p>One other thing I added is that if the working directory is not clean
(i.e. you have made some changes) an exclamation mark is added. Like so:</p>

<p><img src="/gfx/2009/branch-change-prompt.png" alt="Branch change zsh prompt" title="" /></p>

<p>The code for this can be found on the sites listed above.</p>

<p>Of course my other prompt features still work. Here is a shot
with one background job. Notice that <code>^Z</code> suspends this program
and leaves an exit code of 20, which is shown in red:</p>

<p><img src="/gfx/2009/all-prompt.png" alt="Showing all" title="" /></p>

<p>I'm still figuring out ways to get even <em>more</em> colors in the prompt :)</p>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2009/02/05/the__operator/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2009/02/05/the__operator/index.html</guid>
<title>The [[ operator</title>
<dc:date>2009-02-05T15:16:00+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> zsh, programming</dc:subject>
<description><![CDATA[<p>In <a href="http://www.gnu.org/software/bash">bash</a> (and other shells) you
can use the [[ construct</p>

<p>From the bash manpage:</p>

<pre><code>[[ expression ]]
          Return a status of 0 or 1 depending on  the  evaluation  of  the
          conditional  expression expression.  Expressions are composed of
          the primaries described  below  under  CONDITIONAL  EXPRESSIONS.

          Word  splitting  and pathname expansion are not performed on the

          words between the [[ and  ]];  tilde  expansion,  parameter  and
          variable  expansion, arithmetic expansion, command substitution,
          process substitution, and quote removal are  performed.   Condi‐
          tional operators such as -f must be unquoted to be recognized as
          primaries.
</code></pre>

<p>So no <em>word splitting</em> and <em>pathname expansion</em>.</p>

<h2>A little example</h2>

<p>First we have some setting up to do</p>

<pre><code>$ mkdir ~/tmp/zz
$ touch ~/tmp/zz/111
$ echo ~/tmp/zz/*
/home/miekg/tmp/zz
</code></pre>

<p>Well, lets test [[</p>

<pre><code>$ if [[  tmp/zz/* = tmp/zz/111 ]]; then echo OK; else echo NOK; fi
NOK
</code></pre>

<p>NOK - that's correct, because [[ will not do pathname expansion.</p>

<p>The other way around</p>

<pre><code>$ if [[  tmp/zz/111 = tmp/zz/* ]]; then echo OK; else echo NOK; fi
OK
</code></pre>

<p>Huh, <code>OK</code>?</p>

<h2>Why</h2>

<p>To see why bash behaves as it does, the best explanation comes from
the <code>ksh</code> manual. Yes, the <a href="http://www.kornshell.com/">K shell</a>. 
In the section 'Conditional Expressions' of ksh's manual page</p>

<pre><code>string = pattern        True, if string matches pattern.
</code></pre>

<p>Aha, so the right side of a <code>=</code> test is a <em>pattern</em> and a such
it <em>is</em> expanded <em>even though</em> we put it in a [[ construct.</p>

<p>In the bash manual we just have</p>

<pre><code>string1 == string2
True if the strings are equal.  = may be used
in place of == for strict POSIX compliance.
</code></pre>

<p>Which is not <em>entirely</em> correct.</p>

<p>In <a href="http://http://www.zsh.org/">zsh</a> (which is of course <em>the</em> shell) in the section
'CONDITIONAL EXPRESSIONS' it is also correct</p>

<pre><code>string = pattern
string == pattern
    true if string matches pattern.  The ‘==’ form is the  preferred
    one.   The  ‘=’ form is for backward compatibility and should be
    considered obsolete.
</code></pre>

<p>So this might be something worth considering.</p>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2008/12/31/sshs_controlmaster_with_zsh/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2008/12/31/sshs_controlmaster_with_zsh/index.html</guid>
<title>ssh's ControlMaster with zsh</title>
<dc:date>2008-12-31T18:25:13+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> zsh</dc:subject>
<description><![CDATA[<p>You are using the <a href="http://www.linux.com/feature/54498">ControlMaster</a>
feature of <code>ssh</code> and you are having problems remembering
which shell is the master? </p>

<p>That's why I've made <code>zsh</code> display this in the prompt.
You get a <code>m@</code> when a connection is a master connection and 
an <code>@</code> if it is a slave.</p>

<h1>setting up</h1>

<p>The check if we are a master works by creating a file
which has <code>$SSH_CLIENT</code> as the name, as the following snippet shows.</p>

<pre><code># ssh stuff
# check if we are the master or a slave connection
# this must be sourced before .zprompt is

# print @-sign before the hostname if we got into this host via SSH
if [ -z $SSH_TTY ]; then
ZSSH=
else
if [[ ! -e ~/.ssh/${SSH_CLIENT// /_} ]]; then
    # file does not exist, we are a master
    touch ~/.ssh/${SSH_CLIENT// /_}
    ZSSH="m@"
else
    # slave connection
    ZSSH="@"
fi
fi
</code></pre>

<h1>tearing down</h1>

<p>Make <code>zsh</code> remove the file when it exits.</p>

<pre><code>TRAPEXIT() {
echo $PWD &gt; ~/.zpwd
# $ZSSH has @ for slaves and M@ for masters
[[ $ZSSH == "m@" ]] &amp;&amp; rm ~/.ssh/${SSH_CLIENT// /_}
}
</code></pre>

<p>You can now use <code>$ZSSH</code> in your prompt.</p>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2008/12/30/updated_gitvi_script/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2008/12/30/updated_gitvi_script/index.html</guid>
<title>updated gitvi script</title>
<dc:date>2008-12-30T10:29:21+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> zsh, linux</dc:subject>
<description><![CDATA[<p>The script in
<a href="http://www.miek.nl/blog/archives/2008/12/27/using_git_and_vi_together/index.html">using git and vi
together</a>
was a little bit borked, as too many git repo's were created. Hence a
new and improved version. This one will look up the directory tree to
spot an existing git repository - is nothing found a new one will be
created in <code>$PWD</code>.</p>

<h2>code</h2>

<pre><code>#!/bin/zsh
# a wrapper around git and vi
# expands $Hash$ to $Hash: file short_hash epoch committer $
# git checkout HEAD $file? when would I need this
# TODO: spaces in filename

[[ ! -x =git ]] &amp;&amp; exit 1

who=$SUDO_USER
who=${who:-$LOGNAME}

function search_git_dir {
    gpath="$1"

    [[ -d "$gpath/.git" ]] &amp;&amp; echo "$gpath" &amp;&amp; return
    [[ -z "$gpath" ]] &amp;&amp; echo "" &amp;&amp; return

    # strip that last path component and try again
    search_git_dir "${gpath%/*}"
}

for file in "$@"; do
dir=$(dirname $file); cd $dir
base=$(basename $file)

if [[ -z $(search_git_dir $PWD) ]]; then
    # make a new one in $PWD
    git init || exit 1
else
    #echo FOUND ONE
fi
chmod +w $base 2&gt; /dev/null

if vi $base; then
    [[ ! -e $base ]] &amp;&amp; exit 0
    git add $base
    # collapse $Hash: id $ line
    sed -i -e 's/\$Hash:.*\$/$Hash$/' $base
    git commit $base
fi

id=$(git-show -s --pretty=format:$base\ %h\ %ct\ $who%n -- $base) 
[[ -z $id ]] &amp;&amp; exit 1

# re-add $Hash: sha1hash$ line
sed -i -e 's/\$Hash\$'/\$Hash:\ $id\ \$/ $base

chmod a-w $base 2&gt; /dev/null
done
</code></pre>

<h2>manpage</h2>

<p>And ofcourse the manpage.</p>

<pre><code>'\" t
.TH GITVI 1 "27 Dec 2008" "0.1.0" "gitvi"

.SH NAME
gitvi \- a wrapper around git and vi(m)

.SH SYNOPSIS
gitvi [\fIFILE\fR]

.SH DESCRIPTION
Edit files and commit them to a git repository. If FILE is not
given nothing is done.

All the directories from the current one up to the root are
search for a previous .git directory. If no directory is found
a new git repository is created in the current directory. A
new repository will never be created in the root directory.
.PP
The special sequence $Hash$ is expanded by \fBgit-vi\fR to 

.RS
$Hash: sha1hash filename epoch committer $
.RE
.PP
This expanded $Hash$ syntax is \fInot\fR commited to git, this
is done after the commit has taken place.

.SH OPTIONS
There are no options as of yet.

.SH AUTHOR
Miek Gieben &lt;miek@miek.nl&gt;

.SH SEE ALSO
vim(1), git(1).
</code></pre>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2008/12/27/using_git_and_vi_together/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2008/12/27/using_git_and_vi_together/index.html</guid>
<title>Using GIT and VI together</title>
<dc:date>2008-12-27T20:15:29+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> zsh, linux</dc:subject>
<description><![CDATA[<p>A long while back I used <code>vi</code> together with <code>rcs</code> to manage files
in <code>/etc</code>. This worked, but I found <code>rcs</code> to be clunky. So welcome
to the 21st century and my <code>git</code> + <code>vi</code> script.</p>

<p>It is a wrapper around <code>git</code>, which will create a new
git repository, add the file and commit it when changed.</p>

<p>The script will also expand <code>$Hash$</code> to  </p>

<pre><code>$Hash: basename-of-file short-commit-hash epoch committer`
</code></pre>

<p>a typical example is</p>

<pre><code>$Hash: motd.tail 2ebb8e9 1230404370 miekg $
</code></pre>

<p>This is somewhat the same as the <code>$Id$</code> tag from <code>svn/CVS</code>, but with a
different tag. I always found this tagging from subversion useful, esp.
when you -- as a human -- needs to tell if a file is under version
control.</p>

<p>To avoid accidental edits the file is set to read-only.</p>

<p>I think I'm gonna dump <code>cfengine</code> and just use this script, <code>cfengine</code> is
great, but somewhat of a overkill for my home setup.</p>

<h2>Sourcecode of the script</h2>

<p>The script uses <code>zsh</code>, but can be easily converted to <code>bash</code> or any
other shell.</p>

<pre><code>#!/bin/zsh
# a wrapper around git and vi
# expands $Hash$ to $Hash: file short_hash epoch committer $
# git checkout HEAD $file? when would I need this

[[ ! -x =git ]] &amp;&amp; exit 1

who=$SUDO_USER
who=${who:-$LOGNAME}

for file in "$@"; do

dir=$(dirname $file); cd $dir

chmod +w $file 2&gt; /dev/null

if [[ ! -d .git ]]; then
    git init || exit 1
fi

if vi $file; then
    [[ ! -e $file ]] &amp;&amp; exit 0
    git add $file
    # collapse $Hash: id $ line
    sed -i -e 's/\$Hash:.*\$/$Hash$/' $file
    git commit $file
fi

id=$(git-show -s --pretty=format:$(basename $file)\ %h\ %ct\ $who%n -- $file) 
[[ -z $id ]] &amp;&amp; exit 1

# re-add $Hash: sha1hash$ line
sed -i -e 's/\$Hash\$'/\$Hash:\ $id\ \$/ $file

chmod a-w $file 2&gt; /dev/null
done
</code></pre>

<h1>update</h1>

<p>I just thought of something, what if there already <em>is</em> a git repository
in a higher directory....Hmmm. This means the script should look for a
<code>git</code> repository higher up and work from there....</p>]]></description>

</item>
<item>
<link>http://www.miek.nl/blog/archives/2008/09/14/bash_loadable_modules/index.html</link>
<guid isPermaLink="true">http://www.miek.nl/blog/archives/2008/09/14/bash_loadable_modules/index.html</guid>
<title>Bash loadable modules</title>
<dc:date>2008-09-14T20:24:08+01:00</dc:date>
<dc:creator>Miek Gieben</dc:creator>
<dc:subject> nanoblogger, zsh, linux</dc:subject>
<description><![CDATA[<p>Or how to create new builtins for use in <code>bash</code>. Short answer: you can,
but it is not enabled by default (at least on my distribution, Ubuntu)</p>

<p>This is also something that is done much better in <code>zsh</code>.</p>

<p>Why do want this? <em>SPEED</em>! </p>

<p>Shell scripting is a very easy
way to program, but forking all these helper programs takes
a lot of time. So one way to speed up your shell program is
to load these programs into the shell and making them a <em>builtin</em>.</p>

<h2>bash</h2>

<p>I needed the bash source for this to work. So download it and
compile it. Then in the <code>examples/loadables</code> you have some
new builtins, like <code>cat</code>, <code>cut</code>, <code>head</code> and then some.</p>

<p>Making <code>cat</code> a builtin, you need the <code>enable</code> command</p>

<pre><code>$ type cat
cat is /bin/cat

$ enable -f /tmp/bash-3.2/examples/loadables/cat cat
$ cat type
cat is a shell builtin
</code></pre>

<p>Same goes for other executables. When updating my site with
<code>nanoblogger</code>, using <code>cat</code> and others as builtins made the
update much quicker. I shaved off some 20 seconds on a total
of 250 seconds; so it may be worth the effort.</p>

<h2>zsh</h2>

<p>Here everything worked out of the box, but there is currently
no <code>cat</code> builtin for zsh (I created one). But there are
other interesting builtins.</p>

<p>What you need: <code>man zshmodules</code> and <code>zmodload</code>. With zmodload
you can create new builtins. </p>

<p>For example, I made a <code>cat</code> builtin. Next I copy the <code>cat.so</code> to
<code>/usr/lib/zsh/4.3.4/zsh</code></p>

<pre><code>% type cat
cat is /bin/cat

% zmodload zsh/cat
% type cat
cat is a shell builtin
</code></pre>

<p>Unload with <code>zmodload -u</code>. Works like a charm.</p>]]></description>

</item>
</channel>
</rss>

