<?xml version="1.0" encoding="utf-8" ?>

<rss version="0.91" >
<channel>
<title>Refining Linux</title>
<link>http://www.refining-linux.org/</link>
<description>Take your Linux to the next level</description>
<language>en</language>
<image>
        <url>http://media.refining-linux.org/design/tux_painting.png</url>
        <title>RSS: Refining Linux - Take your Linux to the next level</title>
        <link>http://www.refining-linux.org/</link>
        <width>144</width>
        <height>93</height>
    </image>

<item>
    <title>A new appearance</title>
    <link>http://www.refining-linux.org/archives/61/A-new-appearance/</link>

    <description>
        &lt;p&gt;Yay, Refining Linux got a face-lift!

&lt;p&gt;This blog has now been up for a good one and a half year and nothing has changed much since it started. Now it&#039;s time to give it a redesign (if you ask me, this was long overdue). While the main appearance stays the same, the details have changed significantly. Let me walk you through the new goodies.

&lt;h2&gt;Responsive design&lt;/h2&gt;
&lt;p&gt;The most awesome feature first: the whole design is now completely responsive and can be viewed at any size. The old desktop-only design has been replaced by a brand-new flexible design for any kind of device, be it a small smartphone, a bigger tablet or a giant 30&quot; display. Refining Linux has it all.

&lt;p&gt;If you like, you can test this. Just resize your browser window and see how great the new design adapts to the new width. The minimum size I consider looking well is about 240 pixels, but there is no upper limit. It just might start looking a bit ridiculous if you project a tiny page onto your 5k display wall. &lt;img src=&quot;/templates/reflinux-2012/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;

&lt;figure class=&quot;thumbnail&quot;&gt;
&lt;a href=&quot;../../../uploads/content-img/redesign-00-responsive-design-fs8.png&quot;&gt;&lt;img src=&quot;../../../uploads/content-img/redesign-00-responsive-design-fs8.thumb.png&quot; width=&quot;580&quot; height=&quot;373&quot; alt=&quot;The new layout looks great on both large and very small screens such as mobile browsers.&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2&gt;Nicer typography&lt;/h2&gt;
&lt;p&gt;Although Georgia and Verdana are not the worst choices I made in my life, they don&#039;t look very pretty. They&#039;re old veterans of the web-safe fonts battalion and have gotten a bit long in the tooth. Nothing against these fonts in general, but it was time for something different. I mean, we live in the age of web fonts, don&#039;t we?

&lt;p&gt;The new choices are &lt;a href=&quot;http://new.myfonts.com/fonts/open-window/clarendon-paint/&quot;&gt;&lt;i&gt;Clarendon Paint&lt;/i&gt;&lt;/a&gt; and &lt;a href=&quot;http://www.fontsquirrel.com/fonts/Aller&quot;&gt;&lt;i&gt;Aller&lt;/i&gt;&lt;/a&gt;, two fresh fonts for the new look and feel of Refining Linux. I like both and think they support the overall painted appearance.

&lt;figure class=&quot;thumbnail&quot;&gt;
&lt;a href=&quot;../../../uploads/content-img/redesign-01-typography-fs8.png&quot;&gt;&lt;img src=&quot;../../../uploads/content-img/redesign-01-typography-fs8.thumb.png&quot; width=&quot;580&quot; height=&quot;373&quot; alt=&quot;The Refining Linux typography has changed to a heading font with a painted look and a cleaner body text font.&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2&gt;Improved Header&lt;/h2&gt;
&lt;p&gt;Not only the body has been refurbished, also the header has been pimped. It was actually the last thing I took care of, but that doesn&#039;t mean it&#039;s not important. It is. Our little painting Tux has become a bit more lifelike, the background painting a bit more realistic. I also took care of the main menu. It got some more detail, less straight edges and some subtle CSS gradients for the hover effect.

&lt;p&gt;In general I haven&#039;t modified much in the header, but again, the details have changed. It&#039;s perfectly possible that some things in the header might still be tweaked from time to time, but for now I leave it as that.

&lt;figure class=&quot;thumbnail&quot;&gt;
&lt;a href=&quot;../../../uploads/content-img/redesign-02-revamped-header-fs8.png&quot;&gt;&lt;img src=&quot;../../../uploads/content-img/redesign-02-revamped-header-fs8.thumb.png&quot; width=&quot;580&quot; height=&quot;373&quot; alt=&quot;The Tux header image has got some more fine detail as well as the navigation links and the header background.&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2&gt;Redesigned comments section&lt;/h2&gt;
&lt;p&gt;The comments section has especially been taken care of. It looks very different now and much better in my opinion. The speech bubbles make a lot more sense this way and the overall look is much cleaner and more pleasing to the eye. I hope you like it as well.

&lt;p&gt;The amount of indentation has grown a bit with the redesign, so I have limited the maximum number of indents to four (plus the root level, i.e. five). Comments already being submitted at a higher nesting level retain their position in the database but their display is linearized at the fifth level.

&lt;p&gt;Also the comments form (and the contact form as well) has been redesigned slightly. It also looks a lot cleaner now and I put in some nice HTML5 form validation features there (more on that in a second).

&lt;figure class=&quot;thumbnail&quot;&gt;
&lt;a href=&quot;../../../uploads/content-img/redesign-03-improved-comments-fs8.png&quot;&gt;&lt;img src=&quot;../../../uploads/content-img/redesign-03-improved-comments-fs8.thumb.png&quot; width=&quot;580&quot; height=&quot;373&quot; alt=&quot;The comments section has been redesigned completely, avatars are now next to the comments with speech bubble beaks pointing to them. Also little shadows have been added to give the comments more depth.&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2&gt;Better syntax highlighting&lt;/h2&gt;
&lt;p&gt;The syntax highlighting has much been improved. Instead of &lt;a href=&quot;http://shjs.sourceforge.net/&quot;&gt;&lt;i&gt;SH_JS&lt;/i&gt;&lt;/a&gt; I&#039;m now using &lt;a href=&quot;http://softwaremaniacs.org/soft/highlight/en/&quot;&gt;Highlight.js&lt;/a&gt; which gives me way more accurate highlighting and particularly more control. Especially for the last Advent series I created a special ZSH highlighting scheme. I couldn&#039;t really do that in &lt;i&gt;SH_JS&lt;/i&gt; without having to learn &lt;a href=&quot;http://www.gnu.org/s/src-highlite/&quot;&gt;&lt;i&gt;GNU Source Highlight&lt;/i&gt;&lt;/a&gt; (I&#039;m too lazy for that).

&lt;p&gt;The new color scheme for the syntax highlighting is based on Ethan Schoonover&#039;s famous &lt;a href=&quot;http://ethanschoonover.com/solarized&quot;&gt;Solarized theme&lt;/a&gt;. Personally I don&#039;t like Solarized too much for my editor (the colors are too muted to my taste), but for the website, I believe, the bright theme is great.

&lt;p&gt;Yes, there are still some glitches here and there in the highlighting, but I guess I will be able to fix them over time. The highlighting as it is now is already tremendously better than it was ever before.

&lt;figure class=&quot;thumbnail&quot;&gt;
&lt;a href=&quot;../../../uploads/content-img/redesign-04-better-highlighting-fs8.png&quot;&gt;&lt;img src=&quot;../../../uploads/content-img/redesign-04-better-highlighting-fs8.thumb.png&quot; width=&quot;580&quot; height=&quot;373&quot; alt=&quot;The syntax highlighting has got a more suble and muted background color, a nicer color scheme as such and much more precise highlighting rules.&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2&gt;HTML5 rewrite&lt;/h2&gt;
&lt;p&gt;The whole page has been rewritten in HTML5. This wasn&#039;t necessary, but I did it in the process of making the whole thing responsive. It now uses semantic HTML5 markup and of course also goodies like HTML5 input type validation for the comments form, a new Canvas tag cloud (replacing the old and ugly Flash tag cloud) and much more.

&lt;p&gt;The tag cloud, by the way, should be completely accessible as it is based on a normal list of links. Users with very small screens, touch based devices or disabled JavaScript will get that version instead. Also screen readers should be able to access the fallback version.

&lt;figure class=&quot;thumbnail&quot;&gt;
&lt;a href=&quot;../../../uploads/content-img/redesign-05-html5-rewrite-fs8.png&quot;&gt;&lt;img src=&quot;../../../uploads/content-img/redesign-05-html5-rewrite-fs8.thumb.png&quot; width=&quot;580&quot; height=&quot;373&quot; alt=&quot;The HTML code now consists of semantic HTML5 elements instead of a large div soup.&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2&gt;Better legacy IE support&lt;/h2&gt;
&lt;p&gt;Although I don&#039;t care much, a nice side-effect of the responsive design and its “mobile-first” approach is that the support for IE6, 7 and 8 is much better now. IE9 renders everything fine and just lacks support of some minor things such as gradients without SVG. IE8 and older, however, does horrible things to the layout, especially with the new unknown HTML5 elements which I can only get to work with JavaScript. But with the mobile fallback and a few minor fixes I got a more or less decent but at least working version for old IEs. With JavaScript enabled it looks a little less horrible, with JavaScript turned off a little more. But overall it&#039;s all working and the two IE users I have will get a very rough but usable basic version of the website (actually, it&#039;s a bit more. I have about 7-8% of IE users here of which about a quarter uses IE 9 or above. In December the IE rate was even as low as 5.7%).

&lt;figure class=&quot;thumbnail&quot;&gt;
&lt;a href=&quot;../../../uploads/content-img/redesign-06-better-ie-support-fs8.png&quot;&gt;&lt;img src=&quot;../../../uploads/content-img/redesign-06-better-ie-support-fs8.thumb.png&quot; width=&quot;580&quot; height=&quot;373&quot; alt=&quot;Users of old IEs still get a big warning that their browser is outdated, but the overall visual experience has improved a little in those browsers.&quot;&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2&gt;Enjoy!&lt;/h2&gt;
&lt;p&gt;I hope you enjoy the redesign as much as I do. If you like, you can help me a little by doing some browser testing. Although I have tested this on Linux and Windows in many browsers, there might still be some glitches here and there. If you find some, please let me know.

&lt;p&gt;Have fun! &lt;img src=&quot;/templates/reflinux-2012/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;    </description>
</item>
<item>
    <title>SOPA blackout</title>
    <link>http://www.refining-linux.org/archives/60/SOPA-blackout/</link>

    <description>
        &lt;p&gt;Tomorrow this blog will be blacked out for 12 hours starting at 1400 CET (1300 UTC or 8 AM EST).
&lt;p&gt;With this initiative Refining Linux is following the &lt;a href=&quot;http://americancensorship.org/&quot;&gt;protests&lt;/a&gt; against the &lt;b&gt;Stop Online Piracy Act&lt;/b&gt; (SOPA) and the &lt;b&gt;PROTECT IP Act&lt;/b&gt; (PIPA) proposed by US legislators and the media industry. Many huge Internet companies and organizations such as &lt;a href=&quot;http://blog.reddit.com/2012/01/stopped-they-must-be-on-this-all.html&quot;&gt;Reddit&lt;/a&gt; and &lt;a href=&quot;http://wikimediafoundation.org/wiki/English_Wikipedia_anti-SOPA_blackout&quot;&gt;Wikipedia&lt;/a&gt;  participate in these protests. Also companies such as Google, Amazon, Facebook and of course non-profit organizations such as Mozilla and many smaller groups support the protests against SOPA and PIPA.

&lt;h2&gt;Why is this so important?&lt;/h2&gt;
&lt;p&gt;These two bills have the goal to give law enforcement agencies more power to fight against “rogue websites” and copyright infringements in a way that highly endangers free speech and open communication infrastructure. As supporters of open source initiatives and democratic processes we have to intervene and prevent these bills from becoming applicable law.

&lt;p&gt;Fortunately at least the DNS filtering parts of both these bills &lt;a href=&quot;http://www.eweek.com/c/a/Security/White-House-Opposes-DNS-Blocking-in-SOPA-314876/&quot;&gt;have been suspended for now&lt;/a&gt; due to massive protest from all over the country and around the world, but many evenly dangerous parts persists and the idea behind the whole proposed law isn&#039;t dead at all. In fact, it is very much alive and similar attempts are being made behind closed doors in other countries as well. One example is the &lt;a href=&quot;http://www.stopp-acta.info/english&quot;&gt;Anti-Counterfeiting Trade Agreement&lt;/a&gt; (ACTA) which is currently negotiated by many countries in the European Union.

&lt;p&gt;Therefore this is not just a matter of US citizens, it is a matter of people around the world.

&lt;h2&gt;Why are so many big companies against SOPA and PIPA?&lt;/h2&gt;
&lt;p&gt;The simple question is: because the Internet is their business. Other than the entertainment industry, which mainly supports SOPA, these companies depend on the Internet. Should these bills become law, they could be held responsible for any third party content appearing on their websites. That means in an extreme case a single search result pointing to an illegal website could be reason enough to sanction Google. The same applies to any other website with user contributed content such as Wikipedia, Reddit, Facebook, any online community, even your private web forum. All posts made to these website had to be checked and approved manually before they appear publicly. That is impossible to do and a massive restraint of free speech and open communication.

&lt;p&gt;The same applies to ACTA and any similar proposed agreement that abuses legal forces to destroy the freedom of people in the name of fighting online delicts.

&lt;h2&gt;You should participate as well&lt;/h2&gt;
&lt;p&gt;Refining Linux protests for a free Internet and so should you. As Sue Gardener wrote in the Wikimedia&#039;s announcement to black out Wikipedia (which I linked above):

&lt;blockquote&gt;“The reality is that we don’t think SOPA is going away, and PIPA is still quite active. Moreover, SOPA and PIPA are just indicators of a much broader problem. All around the world, we&#039;re seeing the development of legislation intended to fight online piracy, and regulate the Internet in other ways, that hurt online freedoms. Our concern extends beyond SOPA and PIPA: they are just part of the problem. We want the Internet to remain free and open, everywhere, for everyone.”&lt;/blockquote&gt;

&lt;p&gt;This is absolutely true. Even if you&#039;re not a US citizen (like me) this affects you. Bills like SOPA, PIPA or ACTA must not pass legislation. They destroy open communication around the world and change the Internet in a way we really don&#039;t want it to be.

&lt;p&gt;So please sign the petitions against &lt;a href=&quot;http://americancensorship.org/&quot;&gt;SOPA&lt;/a&gt; or &lt;a href=&quot;https://www.accessnow.org/page/s/just-say-no-to-acta&quot;&gt;ACTA&lt;/a&gt; or call your representatives.

&lt;p&gt;Thank you&lt;br&gt;
Janek


&lt;h2&gt;Update 01/19/2012 0100 UTC:&lt;/h2&gt;
&lt;p&gt;Refining Linux is back. Thanks to all who showed their support.    </description>
</item>
<item>
    <title>ZSH Gem #24: ZSH frameworks</title>
    <link>http://www.refining-linux.org/archives/59/ZSH-Gem-24-ZSH-frameworks/</link>

    <description>
        &lt;aside class=&quot;advent&quot;&gt;This article is part of the 2011 Advent calendar series “24 Outstanding ZSH Gems”. Each day between December 1st and December 24th an article will be published as part of this series showing one awesome feature of the Z Shell. Some of the features can of course also be found in other shells such as Bash, but the ZSH implementation is often superior.&lt;/aside&gt;

&lt;p&gt;I have shown you many things about ZSH throughout this series, but there is much more you can do with it than I could cover here. And of course there is also much more to configure, many more options I couldn&#039;t tell you about, many more tips and tricks, tweaks and optimizations.&lt;/p&gt;

&lt;p&gt;Generally, it&#039;s a long way to go before you have your shell set up as you like. Especially ZSH needs a lot of configuration before it becomes very user-friendly. You can do all this configuration by hand or you can use a framework for that. Yes, there are frameworks for ZSH (and for Bash as well, in case you didn&#039;t know) and as a completion of this Advent series I&#039;ll show you two of them.&lt;/p&gt;

&lt;h2&gt;oh-my-zsh&lt;/h2&gt;
&lt;p&gt;Probably the most advanced and mighty ZSH framework is &lt;a href=&quot;https://github.com/robbyrussell/oh-my-zsh&quot;&gt;&lt;em&gt;oh-my-zsh&lt;/em&gt;&lt;/a&gt;. oh-my-zsh provides lots of extra features, special plugins with additional functions and completion definitions for certain command line tools and many, many themes for modifying the appearance of your shell, particularly the prompt.&lt;/p&gt;

&lt;p&gt;To use oh-my-zsh, download it to a directory of your choice (e.g. &lt;code&gt;~/.oh-my-zsh&lt;/code&gt;) and load it from within your &lt;code&gt;.zshrc&lt;/code&gt;:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;# Path to your oh-my-zsh installation (the framework won&#039;t work without this setting)
ZSH=$HOME/.oh-my-zsh

# Load oh-my-zsh
source $ZSH/oh-my-zsh.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&#039;s basically it. You&#039;ve successfully loaded the framework. But until now it doesn&#039;t do much except changing the default prompt to something a bit more meaningful and configuring some basic stuff such as enabling &lt;code&gt;ls&lt;/code&gt; colors. But you can customize the framework. For example to disable &lt;code&gt;ls&lt;/code&gt; colors again, write the following in your &lt;code&gt;.zshrc&lt;/code&gt; before the line where the framework is loaded:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;DISABLE_LS_COLORS=&quot;true&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To set another theme modify the parameter &lt;code&gt;$ZSH_THEME&lt;/code&gt;:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;ZSH_THEME=&quot;candy&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now when you re-source your current shell instance you have the &lt;code&gt;candy&lt;/code&gt; theme activated. For a full list of available themes have a look at the &lt;code&gt;themes&lt;/code&gt; folder inside your oh-my-zsh folder. An even better overview can be found in the &lt;a href=&quot;https://github.com/robbyrussell/oh-my-zsh/wiki/Themes&quot;&gt;oh-my-zsh wiki&lt;/a&gt; on GitHub.&lt;/p&gt;

&lt;p&gt;Next let&#039;s come to the plugins. By default, no plugins are loaded, but that can be changed. Similar to ZSH&#039;s &lt;code&gt;$fpath&lt;/code&gt; array, oh-my-zsh has a special &lt;code&gt;$plugins&lt;/code&gt; array which contains all the names of all the plugins to load when initializing the framework. For instance:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;plugins=(git github perl svn)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;for loading the plugins &lt;code&gt;git&lt;/code&gt;, &lt;code&gt;github&lt;/code&gt;, &lt;code&gt;perl&lt;/code&gt; and &lt;code&gt;svn&lt;/code&gt; which will provide extra functions and completion features for the corresponding applications. For instance, the &lt;code&gt;git&lt;/code&gt; plugins adds many advanced completion features for working with Git repositories and the shell function &lt;code&gt;current_branch&lt;/code&gt; as a shorthand for displaying the branch you&#039;re currently working on without any additional meta data or formatting stuff.&lt;/p&gt;

&lt;p&gt;oh-my-zsh is pretty mighty and you can have a lot of fun with it. Just be aware, that even though ZSH provides an &lt;a href=&quot;/archives/46/ZSH-Gem-12-Autoloading-functions/&quot;&gt;autoloading mechanism&lt;/a&gt; for functions, loading too many plugins can slow down your shell. It can be very annoying when you always have to wait 10 seconds after opening a new shell instance.&lt;/p&gt;

&lt;p&gt;If you&#039;re not quite sure how to start with oh-my-zsh, have a look at the example &lt;code&gt;.zshrc&lt;/code&gt; in the &lt;code&gt;templates&lt;/code&gt; folder.&lt;/p&gt;

&lt;h2&gt;zshuery&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/myfreeweb/zshuery&quot;&gt;&lt;em&gt;zshuery&lt;/em&gt;&lt;/a&gt; is another framework for ZSH which is much smaller. It&#039;s more something like a micro-framework. The name is derived from &lt;em&gt;jQuery&lt;/em&gt; and the idea behind it is to provide a simple and flexible yet fast framework. zshuery doesn&#039;t have lots of plugins. It&#039;s just one single file which provides some extra functionality and does the basic ZSH configuration for you. That&#039;s it. Compared to oh-my-zsh, zshuery is a stub but that&#039;s why I like this framework and prefer it over the more powerful oh-my-zsh. It&#039;s just what it wants to be: a simple framework which makes working on the shell easier without blowing you away with feature you probably never need. With some extra configuration in my &lt;code&gt;.zshrc&lt;/code&gt; this framework is exactly what I need.&lt;/p&gt;

&lt;p&gt;But first things first. Loading zshuery is pretty much straightforward. Just download the framework to an arbitrary folder and reference it in your &lt;code&gt;.zshrc&lt;/code&gt;:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;# Load zshuery
source ${HOME}/.zshuery/zshuery.sh&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That loads the framework. Now to let zshuery set some default options, aliases and autocorrection for you, call the following functions:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;load_defaults
load_aliases
load_correction&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I told you that zshuery doesn&#039;t come with plugins and that is true. However, it provides an easy way to load additional completion functions from the &lt;a href=&quot;https://github.com/zsh-users/zsh-completions&quot;&gt;&lt;code&gt;zsh-completions&lt;/code&gt;&lt;/a&gt; Git repository. These are autocompletion functions which might not yet be in the official ZSH release. To include them, clone the repository (preferably to a directory somwhere inside your zshuery folder) and call the following zshuery function:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;load_completion ${HOME}/.zshuery/completion&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(provided the path to your copy of the &lt;code&gt;zsh-completion&lt;/code&gt; repository is &lt;code&gt;~/.zshuery/completion&lt;/code&gt;)&lt;/p&gt;

&lt;h2&gt;And finally my Christmas gift for you…&lt;/h2&gt;
&lt;p&gt;zshuery is a great framework for pimping your Z Shell without overloading it. And because it&#039;s my favorite ZSH framework and because Christmas is just around the corner, I give you a commented version of my &lt;code&gt;.zshrc&lt;/code&gt; in which I use this framework with some slight modifications:&lt;/p&gt;
&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;# Load zshuery
source ${HOME}/.zshuery/zshuery.sh
load_defaults
load_aliases
load_correction

# Colorize ls output
alias ls=&quot;ls --color=auto&quot;

# Redefine ls colors and load completion definitions
export LS_COLORS=&quot;no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:&quot;
load_completion ${HOME}/.zshuery/completion

# Modify key bindings to make certain keys such as DEL, HOME, END, PAGE UP and PAGE DOWN work
eval &quot;$(sed -n &#039;s/^/bindkey /; s/: / /p&#039; /etc/inputrc)&quot; &gt; /dev/null
bindkey &quot;\e[5~&quot; beginning-of-history    # Page Up
bindkey &quot;\e[6~&quot; end-of-history          # Page Down

# Colorize STDERR (enable if needed, might cause issues with password prompts or escape sequences)
#exec 2&gt;&gt;(while read line; do; print &#039;\e[91m&#039;${(q)line}&#039;\e[0m&#039; &gt; /dev/tty; print -n $&#039;\0&#039;; done)

# Enable menu select
zstyle &#039;:completion:*&#039; menu select

# Enable tree view for kill completion
zstyle &#039;:completion:*:*:kill:*:processes&#039; command &#039;ps --forest -e -o pid,user,tty,cmd&#039;

# Modify zshuery correction prompt
SPROMPT=&quot;Correct $fg[red]%R$reset_color to $fg[green]%r?$reset_color (Yes, No, Abort, Edit) &quot;

# Load fancy prompt (works on Gentoo Linux only)
autoload -U promptinit
promptinit
prompt gentoo

# Non-Gentoo users might configure their prompt manually.
# The default Gentoo prompt from above would look like this:
#PROMPT=&quot;%B%{$fg[green]%}%n@%m%k%{$reset_color%} %B%{$fg[blue]%}%1~ %# %b%f%k%{$reset_color%}&quot;

# Set options
setopt complete_in_word
setopt path_dirs

# Load modules
zmodload zsh/regex
zmodload zsh/pcre

# Update terminal CWD once and then on every CWD change
update_terminal_cwd
function chpwd() {
        update_terminal_cwd
}

# Extend $PATH
PATH=&quot;${HOME}/.local/bin:${HOME}/.local/opt/bin:${PATH}&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Use it for whatever purpose you want. Modify it, extended it, republish it, whatever comes to your mind. You can also use it together with oh-my-zsh or no framework at all if you like that better. Just alter the lines where the framework is loaded or used.&lt;/p&gt;

&lt;aside class=&quot;advent closing&quot;&gt;
    &lt;p&gt;That concludes this year&#039;s Advent series. I hope, you enjoyed the series as much as I did and that you learned a bit from it. Many thanks to all of you. At least the response was overwhelming. Much more than I expected. Also many thanks to the people from &lt;a href=&quot;http://linux.slashdot.org/story/11/12/01/2312241/linux-advent-calendar-24-outstanding-zsh-gems&quot;&gt;Slashdot&lt;/a&gt; who decided that this Advent series is worth a run. Never seen so many people here. &lt;img src=&quot;/templates/reflinux-2012/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;/p&gt;
    &lt;p&gt;I wish you all a Merry Christmas and a Happy New Year and I hope to see you guys here again in 2012.&lt;/p&gt;
    &lt;p&gt;Thanks for all!&lt;br&gt;
    Janek&lt;/p&gt;
&lt;/aside&gt;    </description>
</item>
<item>
    <title>ZSH Gem #23: Working with extended regular expressions</title>
    <link>http://www.refining-linux.org/archives/58/ZSH-Gem-23-Working-with-extended-regular-expressions/</link>

    <description>
        &lt;aside class=&quot;advent&quot;&gt;This article is part of the 2011 Advent calendar series “24 Outstanding ZSH Gems”. Each day between December 1st and December 24th an article will be published as part of this series showing one awesome feature of the Z Shell. Some of the features can of course also be found in other shells such as Bash, but the ZSH implementation is often superior.&lt;/aside&gt;

&lt;p&gt;There are two ZSH modules which allow you to easily work with POSIX extended regular expressions (POSIX ERE) or with Perl compatible regular expressions (PCRE) which are even more advanced than POSIX ERE. These two modules are &lt;code&gt;zsh/regex&lt;/code&gt; and &lt;code&gt;zsh/pcre&lt;/code&gt;. You can use either one of them or both at the same time. That&#039;s entirely up to you. I&#039;ll show you both.&lt;/p&gt;

&lt;p&gt;First let me illustrate &lt;code&gt;zsh/regex&lt;/code&gt; a bit which is the simpler one of both. &lt;code&gt;zsh/regex&lt;/code&gt; provides, once loaded, the new conditional expression &lt;code&gt;-regex-match&lt;/code&gt; which can be used in combination with the &lt;code&gt;[[&lt;/code&gt; command (e.g. in &lt;code&gt;if&lt;/code&gt; conditions or loops):&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;# Load module
zmodload zsh/regex

# Execute POSIX ERE
[[ &quot;foobar_123&quot; -regex-match &quot;^([a-zA-Z0-9]+)_([0-9]+)$&quot; ]] &amp;amp;&amp;amp; echo match || echo no match&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The condition returns true if the expressions matches, otherwise false. If there are any matches, the whole matching part is stored in the &lt;code&gt;$MATCH&lt;/code&gt; parameter and if there are any substrings in parentheses, these parts will be available in the array &lt;code&gt;$match&lt;/code&gt; (here in our example you&#039;d have an array with two elements containing &lt;code&gt;foobar&lt;/code&gt; and &lt;code&gt;123&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Now that I&#039;ve shown you &lt;code&gt;zsh/regex&lt;/code&gt; let&#039;s come to the more complex &lt;code&gt;zsh/pcre&lt;/code&gt;. &lt;code&gt;zsh/pcre&lt;/code&gt; also provides a new conditional expression called &lt;code&gt;-pcre-match&lt;/code&gt; which works about the same as &lt;code&gt;-regex-match&lt;/code&gt; except that it accepts Perl compatible regular expressions. So we could rewrite our example from above as follows:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;# Load module
zmodload zsh/pcre

# Execute PCRE
[[ &quot;foobar_123&quot; -pcre-match &quot;^(\w+)_(\d+)$&quot; ]] &amp;amp;&amp;amp; echo match || echo no match
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&#039;s a little less to write. But &lt;code&gt;zsh/pcre&lt;/code&gt; also provides a few new commands besides the conditional expression &lt;code&gt;-pcre-match&lt;/code&gt;. The most important ones to know are &lt;code&gt;pcre_compile&lt;/code&gt; and &lt;code&gt;pcre_match&lt;/code&gt;. With the first one you compile a regular expression from a string and with the second one you use this compiled regular expression on other strings. That means you always need to use both in combination.&lt;/p&gt;

&lt;p&gt;Both commands provide several flag parameters. The most important ones for &lt;code&gt;pcre_compile&lt;/code&gt; are &lt;code&gt;-m&lt;/code&gt; which will match multi-line patterns, &lt;code&gt;-s&lt;/code&gt; which makes the dot pattern (&lt;code&gt;.&lt;/code&gt;) match whitespace as well and &lt;code&gt;-i&lt;/code&gt; which makes the pattern case-insensitive.&lt;/p&gt;

&lt;p&gt;The most important flags for &lt;code&gt;pcre_match&lt;/code&gt; are &lt;code&gt;-v&lt;/code&gt; and &lt;code&gt;-a&lt;/code&gt; which let you set different names for the match variable containing the whole matching part and the match array containing all the substrings from enclosing parentheses (which are again &lt;code&gt;$MATCH&lt;/code&gt; and &lt;code&gt;$match&lt;/code&gt; by default).&lt;/p&gt;

&lt;p&gt;Our example from above with &lt;code&gt;pcre_compile&lt;/code&gt; and &lt;code&gt;pcre_match&lt;/code&gt; would look like this:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;pcre_compile &quot;^(\w+)_(\d+)$&quot;
pcre_match &quot;foobar_123&quot; &amp;amp;&amp;amp; echo match || echo no match&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sometimes it may be more to write, but it also gives you some more flexibility due to the arguments both commands can take. For example, the following simple case-insensitive regular expression&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;pcre_compile -i &quot;^foobar\s+\d+$&quot;
pcre_match &quot;fOoBaR   123&quot; &amp;amp;&amp;amp; echo match || echo no match&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;would need such a monster expression if just performed with &lt;code&gt;-pcre-match&lt;/code&gt;:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;[[ &quot;fOoBaR   123&quot; -pcre-match &quot;^[fF][oO]{2}[bB][aA][rR]\s+\d+$&quot; ]] &amp;amp;&amp;amp; echo match || echo no match&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this case the second variant is not just more to type (yes, that&#039;s true, count the characters), the first one is also much easier to read and less error-prone so I&#039;d prefer that one.&lt;/p&gt;

&lt;p&gt;Whichever variant you take and whether you prefer POSIX regular expressions or PCRE always depends on the situation. But all of them give you the full power of regular expressions. So use them!&lt;/p&gt;

&lt;p&gt;Read more about zsh/regex and zsh/pcre:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module&quot;&gt;zsh.sf.net: The zsh/regex Module&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fpcre-Module&quot;&gt;zsh.sf.net: The zsh/pcre Module&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html&quot;&gt;zsh.sf.net: Conditional Expressions&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Regular_expression&quot;&gt;Wikipedia.org: Regular expression&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;    </description>
</item>
<item>
    <title>ZSH Gem #22: Accessing and editing files with mapfile</title>
    <link>http://www.refining-linux.org/archives/57/ZSH-Gem-22-Accessing-and-editing-files-with-mapfile/</link>

    <description>
        &lt;aside class=&quot;advent&quot;&gt;This article is part of the 2011 Advent calendar series “24 Outstanding ZSH Gems”. Each day between December 1st and December 24th an article will be published as part of this series showing one awesome feature of the Z Shell. Some of the features can of course also be found in other shells such as Bash, but the ZSH implementation is often superior.&lt;/aside&gt;

&lt;p&gt;Working on the shell is often working with files and sometimes you need to read or edit their contents. Normally you&#039;d do that with the command line editor of your choice (e.g. nano, vi, vim or emacs), but sometimes you need to write the output of a command or a pipe to a file or feed programs with contents from the hard disk. That&#039;s usually done by using the input and output redirection operators, but ZSH gives you one more tool which can sometimes make things easier. This module is called &lt;code&gt;mapfile&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;mapfile&lt;/code&gt; is a ZSH module you need to enable it before you can use it:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;zmodload zsh/mapfile&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once the module is loaded, you get the magic associative array &lt;code&gt;$mapfile&lt;/code&gt; which gives you direct access to any file when you specify its name as the name of the array key. For example, to &lt;code&gt;echo&lt;/code&gt; the contents of the file &lt;code&gt;examplefile&lt;/code&gt; run &lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;echo $mapfile[examplefile]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can also write to files by assigning values to an entry of the array. The value will then be written to disk. If the file does not exist yet, it will be created. To write the string &lt;em&gt;Hello World&lt;/em&gt; to our file, run &lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;$mapfile[examplefile]=&quot;Hello World&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&#039;s the basics and about everything &lt;code&gt;mapfile&lt;/code&gt; can do. How do we make use of it? &lt;code&gt;mapfile&lt;/code&gt; can sometimes be a nice thing when you need to work with contents of a file in a very simple way. By using &lt;code&gt;mapfile&lt;/code&gt; you can avoid piping the contents through chains of commands or doing stuff like this:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;filecontents=$(cat file)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;mapfile&lt;/code&gt; also enables you to do some basic filtering and editing directly when accessing the file by using ZSH&#039;s parameter expansion operators. For example if you need the contents of a file converted to all lowercase, the only thing you need to do do is &lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;echo ${(L)mapfile[file]}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or if you need the contents of a file or a fallback value in case the file doesn&#039;t exist, &lt;code&gt;mapfile&lt;/code&gt; should be the easiest way to go:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;echo ${mapfile[file]:-Fallback value}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or if you need to do some initial search and replace:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;echo ${mapfile[file]//search/replace}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Of course, you can also write the edited contents back to disk:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;mapfile[file]=${mapfile[file]//search/replace}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;No big deal. Another thing you could do is to get the length of a textfile in characters (i.e. bytes):&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;echo ${#mapfile[file]}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Whatever you want! You can also use &lt;code&gt;mapfile&lt;/code&gt; in combination with &lt;code&gt;vared&lt;/code&gt; to let the user edit files interactively:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;vared mapfile[file]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Of course, you could also open some more advanced editor such as vim, but at least as a fallback, &lt;code&gt;mapfile&lt;/code&gt; in combination with &lt;code&gt;vared&lt;/code&gt; becomes a valuable tool because no external program is required.&lt;/p&gt;

&lt;p&gt;You see, under some circumstances, &lt;code&gt;mapfile&lt;/code&gt; can really save your neck. But you should also be aware, that it may also consume a lot of memory, particularly with large files. So use it with caution.&lt;/p&gt;

&lt;p&gt;Read more about mapfile:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fmapfile-Module&quot;&gt;zsh.sf.net: The zsh/mapfile Module&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://grml.org/zsh/zsh-lovers.html#_zsh_mapfile_require_zmodload_zsh_mapfile&quot;&gt;ZSH-LOVERS: zsh/mapfile&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion&quot;&gt;zsh.sf.net: Parameter Expansion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;    </description>
</item>
<item>
    <title>ZSH Gem #21: Completion of abbreviated filenames</title>
    <link>http://www.refining-linux.org/archives/56/ZSH-Gem-21-Completion-of-abbreviated-filenames/</link>

    <description>
        &lt;aside class=&quot;advent&quot;&gt;This article is part of the 2011 Advent calendar series “24 Outstanding ZSH Gems”. Each day between December 1st and December 24th an article will be published as part of this series showing one awesome feature of the Z Shell. Some of the features can of course also be found in other shells such as Bash, but the ZSH implementation is often superior.&lt;/aside&gt;

&lt;p&gt;Yesterday I told you about how to use the &lt;a href=&quot;/archives/55/ZSH-Gem-20-Changing-directories-the-pros-way/&quot;&gt;full potential of the &lt;code&gt;cd&lt;/code&gt; command&lt;/a&gt;. Today I want to go one step further and show you how you can reduce the number of characters to type even more.&lt;/p&gt;

&lt;p&gt;As I&#039;ve already shown you several times throughout this series, ZSH is very capable of completing things when hitting the TAB key. Today I&#039;ll show you two more features concerning completion of abbreviated or incomplete pathnames.&lt;/p&gt;

&lt;p&gt;The first feature I want to present you with enables you to complete incomplete parts of a filename. It can be activated with the option &lt;code&gt;COMPLETE_IN_WORD&lt;/code&gt;. You can set the option as usual with &lt;code&gt;setopt&lt;/code&gt; (as always, make sure the completion engine is loaded):&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;autoload -U compinit &amp;amp;&amp;amp; compinit
setopt complete_in_word&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So now that it&#039;s enabled, how do we use this feature? Well, it&#039;s very simple. Imagine, you want to switch to the directory &lt;code&gt;/home/johndoe&lt;/code&gt;. You type:&lt;/p&gt;

&lt;pre class=&quot;input&quot;&gt;&lt;samp&gt;% &lt;kbd&gt;cd /hme/john&lt;/kbd&gt;&lt;/samp&gt;&lt;/pre&gt;

&lt;p&gt;But before you finish the word &lt;code&gt;johndoe&lt;/code&gt; you realize that you didn&#039;t get the first part of the pathname right and forgot the &lt;kbd&gt;o&lt;/kbd&gt; in &lt;kbd&gt;home&lt;/kbd&gt; (maybe your keyboard is a bit older and some keys have become a little stiff). You could now hit the arrow keys to go back, fill in the missing &lt;kbd&gt;o&lt;/kbd&gt;, jump back again to the end (either with the arrow keys or with the &lt;kbd&gt;END&lt;/kbd&gt; key) and then write the rest of the name (or use the normal TAB completion). That&#039;s a relatively long procedure. But with &lt;code&gt;COMPLETE_IN_WORD&lt;/code&gt; you can save some time. Just use the arrow keys to go back until the cursor is on the &lt;code&gt;m&lt;/code&gt; right after the missing character and then hit &lt;kbd&gt;TAB&lt;/kbd&gt;. ZSH will automatically complete &lt;code&gt;hme&lt;/code&gt; to &lt;code&gt;home&lt;/code&gt; and also fill in the rest of the name and set your cursor back to the end of it. So you end up with &lt;code&gt;/home/johndoe/&lt;/code&gt; and the cursor after the last slash, ready to type in more words.&lt;/p&gt;

&lt;p&gt;Quick and easy! Can&#039;t we always use something like this to save some characters? Of course we can and we don&#039;t even need &lt;code&gt;COMPLETE_IN_WORD&lt;/code&gt; for it. We just need to enable the completion engine (see above). Once this is done, we can use abbreviated path names where we want. For example to switch to &lt;code&gt;/home/johndoe/Documents&lt;/code&gt; write&lt;/p&gt;

&lt;pre class=&quot;input&quot;&gt;&lt;kbd&gt;cd /ho/jo/Do&lt;/kbd&gt;&lt;kbd class=&quot;keystroke&quot;&gt;&amp;lt;TAB&amp;gt;&lt;/samp&gt;&lt;/pre&gt;

&lt;p&gt;The TAB key completes the path and the only thing left to do is to press enter to execute the &lt;code&gt;cd&lt;/code&gt; command. As long as you specify the first (!) few characters of each directory level, ZSH will be able to complete the whole path.&lt;/p&gt;

&lt;p&gt;But what does ZSH do when there is more than one possible match? First of all, ZSH evaluates the whole path which makes ambiguous paths very unlikely. For instance, if you enter &lt;kbd&gt;/ho/jo/Images&lt;kbd class=&quot;keystroke&quot;&gt;&amp;lt;TAB&amp;gt;&lt;/kbd&gt;&lt;/kbd&gt; and there is a directory &lt;code&gt;/home/johndoe&lt;/code&gt; and a directory &lt;code&gt;/home/johnwayne&lt;/code&gt; but no directory &lt;code&gt;/home/johnwayne/Images*&lt;/code&gt; then ZSH will automatically complete to &lt;code&gt;/home/johndoe/Images&lt;/code&gt;. If there is still more than one possibility, ZSH will complete up to the first ambiguous match and place the cursor at its position. Just enter a few more characters there and hit TAB again. ZSH will then continue the completion with the additional information it just got from you.&lt;/p&gt;

&lt;p&gt;In my opinion, these two filename completion features make switching directories very fast and convenient. If you haven&#039;t already tried them out, now is the time. &lt;img src=&quot;/templates/reflinux-2012/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Read more about filename completion:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/FAQ/zshfaq04.html&quot;&gt;zsh.sf.net: The mysteries of completion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;    </description>
</item>
<item>
    <title>ZSH Gem #20: Changing directories the pro's way</title>
    <link>http://www.refining-linux.org/archives/55/ZSH-Gem-20-Changing-directories-the-pros-way/</link>

    <description>
        &lt;aside class=&quot;advent&quot;&gt;This article is part of the 2011 Advent calendar series “24 Outstanding ZSH Gems”. Each day between December 1st and December 24th an article will be published as part of this series showing one awesome feature of the Z Shell. Some of the features can of course also be found in other shells such as Bash, but the ZSH implementation is often superior.&lt;/aside&gt;

&lt;p&gt;I guess, the &lt;code&gt;cd&lt;/code&gt; command is the most often neglected command. Nobody really cares about what this command can do, but in fact, ZSH has added some magic to it, which makes it worth a more thorough look.&lt;/p&gt;

&lt;p&gt;I told you about &lt;a href=&quot;/archives/51/ZSH-Gem-17-Changing-directories-with-auto_cd/&quot;&gt;&lt;code&gt;AUTO_CD&lt;/code&gt;&lt;/a&gt; before, a shorthand syntax for the &lt;code&gt;cd&lt;/code&gt; command. But that&#039;s not the only thing ZSH has done to &lt;code&gt;cd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The first exciting feature I want to tell you about is changing directories by replacing parts of the current path name. That sounds abstract, but let me explain. It&#039;s actually quite simple. Imagine, you are in your home directory &lt;code&gt;/home/johndoe&lt;/code&gt; and you need to change to the home directory &lt;code&gt;/home/janedoe&lt;/code&gt;. You could easily do that with &lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;cd ../janedoe&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or with &lt;code&gt;AUTO_CD&lt;/code&gt; enabled &lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;../janedoe&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&#039;s already nice and short, but have a look at this:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;cd john jane&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you like, you could even omit the j as it&#039;s the same in both names and run just &lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;cd ohn ane&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What the command does is obvious: it replaces the first occurrence of the first string in the current path name with the second string. The string can appear anywhere in the path name. As long as the newly generated path is a valid directory, it will work. If a replacement is ambiguous (e.g. if there is also a home directory &lt;code&gt;/home/janetdoe&lt;/code&gt; where &lt;code&gt;cd john jane&lt;/code&gt; could either switch to Jane&#039;s or Janet&#039;s home directory), the match which comes first in the alphabet is taken.&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;cd johndoe/john janedoe/jane&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;switches from &lt;code&gt;/home/johndoe/john&lt;/code&gt; to &lt;code&gt;/home/janedoe/jane&lt;/code&gt; and for instance&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;cd usr usr/local&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;can change from something like &lt;code&gt;/usr/share/applications&lt;/code&gt; to &lt;code&gt;/usr/local/share/applications&lt;/code&gt; without typing any unnecessary characters.&lt;/p&gt;

&lt;p&gt;That is the first &lt;code&gt;cd&lt;/code&gt; pro feature I want to show you. The second one is working with the directory stack. Just like Bash, ZSH has a so called directory stack. That&#039;s a list of directories you can work with. The top-most entry is always the current working directory. You can view the current directory stack with &lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;dirs -v&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To work with the directory stack, you can use &lt;code&gt;pushd DIR&lt;/code&gt; to change to the directory &lt;code&gt;DIR&lt;/code&gt; and place it on top of the stack or &lt;code&gt;popd&lt;/code&gt; to remove the top-most entry from the stack and automatically change to it. &lt;code&gt;popd&lt;/code&gt; can also take an argument &lt;code&gt;+n&lt;/code&gt; or &lt;code&gt;-n&lt;/code&gt; where &lt;code&gt;n&lt;/code&gt; is a number defining a specific entry counting from the top or the bottom.&lt;/p&gt;

&lt;p&gt;That&#039;s all the same Bash as in ZSH and to be honest: I&#039;ve never worked with it because using &lt;code&gt;popd&lt;/code&gt; and &lt;code&gt;pushd&lt;/code&gt; is quite cumbersome and I&#039;m faster without (defining aliases for frequently used directories is more convenient). As I told you, the top-most entry is always the current working directory, but normally when you &lt;code&gt;cd&lt;/code&gt; to another directory, the new working directory isn&#039;t put on top of the stack. Instead it replaces the last entry for the CWD. To really add directories to the stack you have to do it explicitly with &lt;code&gt;pushd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, in ZSH you can work with the directory stack directly with &lt;code&gt;cd&lt;/code&gt;. If the option &lt;code&gt;AUTO_PUSHD&lt;/code&gt; is set, the current working directory is automatically added permanently to the stack. That means, the stack contains the whole history of all the directories you&#039;ve been in during this session. To prove that, make sure &lt;code&gt;AUTO_PUSHD&lt;/code&gt; is set, navigate through some directories as you&#039;d normally do and then enter &lt;code&gt;dirs -v&lt;/code&gt;. You should see all the directories you just skipped through in the stack (directories you entered twice are not saved again but moved to the top of the stack).&lt;/p&gt;

&lt;p&gt;Now that you have the stack, you can use &lt;code&gt;cd&lt;/code&gt; to navigate between its entries. Use the normal &lt;code&gt;popd&lt;/code&gt; argument syntax for it:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;cd +4&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;cd&lt;/code&gt;&#039;s to the fourth entry from the top.&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;cd -2&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;goes to the second entry from the bottom. No need for manual &lt;code&gt;pushd&lt;/code&gt; or &lt;code&gt;popd&lt;/code&gt; calls. Just use &lt;code&gt;cd {+|-}n&lt;/code&gt; to switch between the entries and let ZSH handle the stack by itself. Don&#039;t bother about that anymore.&lt;/p&gt;

&lt;p&gt;Read more about cd and directory stacks:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html#Shell-Builtin-Commands&quot;&gt;zsh.sf.net: Shell Builtin Commands&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.cs.elte.hu/zsh-manual/zsh_16.html&quot;&gt;zsh.sf.net: Options&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.acm.uiuc.edu/workshops/zsh/dir_stack.html&quot;&gt;The Directory Stack&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;    </description>
</item>
<item>
    <title>ZSH Gem #19: Global aliases</title>
    <link>http://www.refining-linux.org/archives/53/ZSH-Gem-19-Global-aliases/</link>

    <description>
        &lt;aside class=&quot;advent&quot;&gt;This article is part of the 2011 Advent calendar series “24 Outstanding ZSH Gems”. Each day between December 1st and December 24th an article will be published as part of this series showing one awesome feature of the Z Shell. Some of the features can of course also be found in other shells such as Bash, but the ZSH implementation is often superior.&lt;/aside&gt;

&lt;p&gt;I guess each shell implementation knows something like aliases. With aliases you can give commands different names which might be more convenient for you. That&#039;s nothing new, but ZSH has a feature called &lt;em&gt;global aliases&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;An example of a normal alias would be to create a shorter name for the &lt;code&gt;rename&lt;/code&gt; command:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;alias rn=&quot;rename&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you are able to call the &lt;code&gt;rename&lt;/code&gt; command via the short name &lt;code&gt;rn&lt;/code&gt;. You can also redefine commands with frequently used options:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;alias ls --color=auto&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But that&#039;s nothing you couldn&#039;t do in Bash as well. But let&#039;s come to the so called global aliases. To define a global alias you need to option &lt;code&gt;-g&lt;/code&gt; of the alias command. Global aliases are not limited to command names and can be used as a replacement of (nearly) any part of the syntax. For example if you often pipe things to grep and you don&#039;t always want to write &lt;code&gt;| grep -i&lt;/code&gt; you can define an alias for that:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;alias -g gp=&quot;| grep -i&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;From now on you only have to write &lt;code&gt;gp&lt;/code&gt; instead of &lt;code&gt;| grep -i&lt;/code&gt;. For example:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;echo &#039;Foo bar&#039; gp foo&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and you get all lines containing &lt;em&gt;foo&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;As I said before: with global aliases you can give nearly everything on the shell an alias name. Even globbing patterns:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;alias -g asterisk=&quot;*&quot;
ls asterisk&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&#039;s particularly useful if you have a very complex globbing pattern that you need more than once. Just define an alias name for that. To demonstrate that even better, let&#039;s use our monster globbing pattern from the &lt;a href=&quot;/archives/37/ZSH-Gem-2-Extended-globbing-and-expansion/&quot;&gt;extended globbing article&lt;/a&gt; and define an alias name for it:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;alias -g monsterglob=&quot;**/([^A-Z[:digit:]])##(#q.x^X^u1002Lm+30mM-1)&quot;
ls -l monsterglob&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I guess you see how extremely convenient and powerful this is and any why you should always use the &lt;code&gt;-U&lt;/code&gt; parameter when auto loading functions. You can even define aliases for variables:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;alias -g p=&#039;$PATH&#039;
echo p&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Okay, that doesn&#039;t look very expedient, but imagine what you could do when combining that with other expressions such as parameter expansion:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;alias -g nlpath=&#039;${PATH//:/
}&#039;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That defines an alias which expands to a newline-separated list of all entries in &lt;code&gt;$PATH&lt;/code&gt;. In Bash you could only define such an alias together with a command. Such a command would look like this:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;alias nlpath=&#039;echo -e ${PATH//:/&quot;\n&quot;}&#039;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The advantage of the ZSH alias is obvious: you can use the alias anywhere where you could use a variable. The Bash alias, however, always needs to be piped to STDIN of another command in order to do further processing because it is an alias for a command, not an alias for some arbitrary part of the syntax.&lt;/p&gt;

&lt;p&gt;Besides extended globbing and all the other completion and expansion features, global aliases are the reason why I love ZSH and I hope, I could enthuse you as well. If not, then hopefully with one of the following articles before this series is over. &lt;img src=&quot;/templates/reflinux-2012/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Read more about global aliases:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Intro/intro_8.html&quot;&gt;zsh.sf.net: Aliasing&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://grml.org/zsh/zsh-lovers.html#_examples&quot;&gt;ZSH-LOVERS: Examples for global aliases&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;    </description>
</item>
<item>
    <title>ZSH Gem #18: Regexp search and replace on parameters</title>
    <link>http://www.refining-linux.org/archives/52/ZSH-Gem-18-Regexp-search-and-replace-on-parameters/</link>

    <description>
        &lt;aside class=&quot;advent&quot;&gt;This article is part of the 2011 Advent calendar series “24 Outstanding ZSH Gems”. Each day between December 1st and December 24th an article will be published as part of this series showing one awesome feature of the Z Shell. Some of the features can of course also be found in other shells such as Bash, but the ZSH implementation is often superior.&lt;/aside&gt;

&lt;p&gt;In ZSH you can easily perform regexp search and replace operations on shell parameters. The only function you need for this is &lt;code&gt;regexp-replace&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Regexp search and replace can be very useful when writing shell scripts which need to process input data, directory names, process trees etc. You assign the string which you need to work on to a parameter and then run the replace function on it. But before you can do anything, you need to load the function first:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;autoload -U regexp-replace&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The syntax of &lt;code&gt;regexp-replace&lt;/code&gt; is as follows:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;regexp-replace VARNAME REGEXP REPLACE&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;where &lt;code&gt;VARNAME&lt;/code&gt; is the name of the variable, &lt;code&gt;REGEXP&lt;/code&gt; the regular expression and &lt;code&gt;REPLACE&lt;/code&gt; the replace string.&lt;/p&gt;

&lt;p&gt;As an example of how to use &lt;code&gt;regexp-replace&lt;/code&gt; let us replace all occurrences of &lt;code&gt;/foo/bar&lt;/code&gt; in the &lt;code&gt;$PATH&lt;/code&gt; variable. So let&#039;s add that first of all:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;PATH=&quot;$PATH:/foo/bar&quot;
echo $PATH&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There we have it. Now let us remove that entry again:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;regexp-replace PATH &#039;:/foo/bar&#039; &#039;&#039;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That will replace our newly added string with an empty string. Of course this was a very basic pattern. But we can use the full POSIX extended regexp syntax and if we enable the option &lt;code&gt;RE_MATCH_PCRE&lt;/code&gt;&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;setopt re_match_pcre&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;we can even use full Perl compatible regular expressions (provided ZSH was built with PCRE support). Let&#039;s do that and replace all entries starting with &lt;code&gt;/usr/&lt;/code&gt; with &lt;code&gt;foo&lt;/code&gt;:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;regexp-replace PATH &#039;(^|:)/usr/[^:]*&#039; &#039;:foo&#039;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Unfortunately there is no direct way to use back references for each parenthesis expression in the replace pattern, but there are at least some special variables: &lt;code&gt;$MATCH&lt;/code&gt; contains the matched portion, &lt;code&gt;$1&lt;/code&gt; contains the variable name and &lt;code&gt;$2&lt;/code&gt; contains the pattern. For instance to append &lt;code&gt;/subdir&lt;/code&gt; to the paths starting with &lt;code&gt;/usr&lt;/code&gt; instead of replacing the whole thing, we could write &lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;regexp-replace PATH &#039;(^|:)/usr/[^:]*&#039; &#039;$MATCH/subdir&#039;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Mind the single quotes! &lt;code&gt;$MATCH&lt;/code&gt; is not an actual shell parameter but rather a placeholder which is replaced by the &lt;code&gt;regexp-replace&lt;/code&gt; function. If you would use double quotes or even no quotes, you&#039;d get an empty string (except &lt;code&gt;$MATCH&lt;/code&gt; already has some value assigned to it, but normally that&#039;s not what you want anyways). The same applies to &lt;code&gt;$1&lt;/code&gt; and &lt;code&gt;$2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;regexp-replace&lt;/code&gt; is a nice addition to ZSH&#039;s &lt;a href=&quot;/archives/47/ZSH-Gem-13-Parameter-expansion/&quot;&gt;parameter expansion patterns&lt;/a&gt;. It&#039;s easy to use and in most cases more than sufficient.&lt;/p&gt;

&lt;p&gt;Read more about regexp-replace:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#index-regexp_002dreplace&quot;&gt;zsh.sf.net: User Contributions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;    </description>
</item>
<item>
    <title>ZSH Gem #17: Changing directories with auto_cd</title>
    <link>http://www.refining-linux.org/archives/51/ZSH-Gem-17-Changing-directories-with-auto_cd/</link>

    <description>
        &lt;aside class=&quot;advent&quot;&gt;This article is part of the 2011 Advent calendar series “24 Outstanding ZSH Gems”. Each day between December 1st and December 24th an article will be published as part of this series showing one awesome feature of the Z Shell. Some of the features can of course also be found in other shells such as Bash, but the ZSH implementation is often superior.&lt;/aside&gt;

&lt;p&gt;This is probably the shortest tip of this series. I only want to show you a ZSH-specific shorthand for changing directories.&lt;/p&gt;

&lt;p&gt;The ZSH option &lt;code&gt;AUTO_CD&lt;/code&gt; makes it possible to change directories by just writing their names without using &lt;code&gt;cd&lt;/code&gt;. This might be interesting for those of you who always want to type as few characters as possible. If you are one of those, just activate the option:&lt;/p&gt;

&lt;pre class=&quot;sourcecode&quot;&gt;&lt;code class=&quot;language-zsh&quot;&gt;setopt auto_cd&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You will still be able to use the normal &lt;code&gt;cd&lt;/code&gt; syntax, but now you can also switch the directories by writing the directory name only. For instance, to change to the parent directory, just write &lt;code&gt;..&lt;/code&gt;, hit enter and there you go. To go into the subdirectory &lt;em&gt;bar&lt;/em&gt; inside the subdirectory &lt;em&gt;foo&lt;/em&gt;, write &lt;code&gt;foo/bar&lt;/code&gt;. Pretty easy. it&#039;s the same as &lt;code&gt;cd&lt;/code&gt; just without &lt;code&gt;cd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Personally, I use this syntax rarely, but that&#039;s not because I don&#039;t find it useful. It&#039;s just that I&#039;m used to write &lt;code&gt;cd&lt;/code&gt; and I often have already typed these two characters before I remember that I wanted to use the shorter syntax. But I guess, some of you might do better and speed their workflow up a little by using this shorthand directory switching syntax extensively. &lt;img src=&quot;/templates/reflinux-2012/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Read more about auto_cd:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://zsh.sourceforge.net/Intro/intro_16.html&quot;&gt;zsh.sf.net: Options&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;    </description>
</item>

</channel>
</rss>

