<?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>soledad penadés &#187; bash</title>
	<atom:link href="http://soledadpenades.com/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://soledadpenades.com</link>
	<description>repeat 4[fd 100 rt 90]</description>
	<lastBuildDate>Sun, 29 Jan 2012 23:03:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>244 days with Vim, 2 days with gVim: introducing dotvim</title>
		<link>http://soledadpenades.com/2011/07/03/244-days-with-vim-2-days-with-gvim-introducing-dotvim/</link>
		<comments>http://soledadpenades.com/2011/07/03/244-days-with-vim-2-days-with-gvim-introducing-dotvim/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 10:06:04 +0000</pubDate>
		<dc:creator>sole</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[color schemes]]></category>
		<category><![CDATA[customising]]></category>
		<category><![CDATA[gvim]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://soledadpenades.com/?p=3555</guid>
		<description><![CDATA[Things have changed since I published my &#8220;Two weeks with Vim&#8221; post. At that time, I was desperately mad &#8211;thanks to Eclipse. I even began learning about VTE, the Terminal-like GTK widget&#8211;in order to build my own Vim+command line based Android &#8220;IDE&#8221;. Yes, that&#8217;s how irritated I was with Eclipse. But then I found about [...]]]></description>
			<content:encoded><![CDATA[<p>Things have changed since I published my &#8220;<a href="http://soledadpenades.com/2010/11/15/two-weeks-with-vim/">Two weeks with Vim</a>&#8221; post. At that time, I was desperately mad &#8211;thanks to Eclipse. I even began learning about <a href="http://developer.gnome.org/vte/">VTE</a>, the Terminal-like GTK widget&#8211;in order to build my own Vim+command line based Android &#8220;IDE&#8221;. Yes, that&#8217;s how irritated I was with Eclipse.</p>
<p>But then I found about IntelliJ IDEA, and quickly forgot about all the pains I had experienced with Eclipse. Now that was a wonderful, intelligent, productive environment in which to program. So I dismissed my <em>grandeur</em> dreams of a DIY IDE.</p>
<p>However, I didn&#8217;t stop using Vim! I have been using it for everything else. Mostly Python, but a bit of C too. I like it specially when I&#8217;m on my laptop. Firstly, because I can&#8217;t seem to get to speed with the button-less touchpad in the new Macbooks, so I&#8217;d rather avoid using the touchpad. Secondly, because the battery lasts like <em>forever</em> when using Vim only and not a full-blown IDE such as IntelliJ.<br />
<span id="more-3555"></span><br />
As an example, I wrote <a href="https://github.com/sole/pommed-fork/commit/b0534125db3c3e522817279ddc065c19506f04b6">the patch for pommed on newer Macbooks</a> on the plane from London to Valencia, which takes two hours and a bit. When I arrived, I still spent a day or two testing and dabbling with the pommed code until I had to plug-in the charger again.</p>
<p>I still have much to learn about Vim, but one of the things <strong>I wanted to solve was that I had to manually sync my Vim settings</strong> between my laptop and my desktop. I noticed some people were publishing their .vim directories in github, and I thought that it was a terrific idea: that way I could keep everything in the famous cloud but still have a local backup (with history) if the cloud was blown away!</p>
<p>And after studying other people&#8217;s github .vim repositories, here&#8217;s my <em>imaginatively</em> named repository: <a href="https://github.com/sole/dotvim">dotvim</a>.</p>
<h3>How it works</h3>
<p>Vim stores each user&#8217;s settings in a <strong>.vim</strong> directory, in the user&#8217;s home directory. In my case, that is <strong>/home/sole/.vim</strong>, but that depends on each operating system and distribution. It might be <strong>/Users/sole</strong> in Mac, if I remember correctly.</p>
<p>So as everything is in a directory, it&#8217;s an ideal situation for a git repository. We can place all our favourite plug-ins, color schemes and etc inside that directory and they will just be a <em>git clone</em> away when needed.</p>
<p>The problem is that the file Vim reads when starting up, and where all the personal settings are stored and scripts are launched for a user is <strong>not</strong> inside .vim, but <em>at the same level</em> than .vim: on the user&#8217;s home directory. So in my case, its full path is <strong>/home/sole/.vimrc</strong></p>
<p>How do we version a single file with git? Well, I found the answer in <a href="http://blog.vgod.tw/">Tsung-Hsiang Chang</a>&#8216;s .vim <a href="https://github.com/vgod/vimrc">repository</a>: <strong>you don&#8217;t</strong>. Instead, you place it inside the versioned <strong>.vim</strong> directory, and make a symlink to it. That way it&#8217;s kept in the repository along with the rest of vim-thingies:</p>
<div class="syhi_block"><code><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> ~<span style="color: #000000; font-weight: bold;">/</span>.vim<span style="color: #000000; font-weight: bold;">/</span>vimrc ~<span style="color: #000000; font-weight: bold;">/</span>.vimrc</code></div>
<p>Doing all this manually is a hassle. It really demands automation! And someone had thought of that already: <a href="http://nvie.com/">Vincent Driessen</a> devised both an .sh script for cloning his <strong>.vim</strong> dir and making the symlinks, and also a nifty one-line which does all the work if you&#8217;re in a brand new setup with no <strong>.vim</strong> or <strong>.vimrc</strong> on it:</p>
<div class="syhi_block"><code><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-O</span> - https:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>nvie<span style="color: #000000; font-weight: bold;">/</span>vimrc<span style="color: #000000; font-weight: bold;">/</span>raw<span style="color: #000000; font-weight: bold;">/</span>master<span style="color: #000000; font-weight: bold;">/</span>autoinstall.sh <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sh</span></code></div>
<p>I liked that idea, but I splitted it into <a href="https://github.com/sole/dotvim/blob/master/install.sh">install.sh</a>, which sets up symlinks and updates the git submodules, and <a href="https://github.com/sole/dotvim/blob/master/superfastinstall.sh">superfastinstall.sh</a> which clones the git repository and then calls <strong>install.sh</strong> in order to complete the installation. This was more modular (and easier to test).</p>
<p>And that&#8217;s roughly how the setup is done.</p>
<h3>But&#8230; gVim?</h3>
<p>One of the aspects that annoys me of most editors is the colours. It looks like people either don&#8217;t care or their tastes are diametrically opposed to mine, and Vim was no exception. I tried all the color schemes but I liked none. <strong>So I decided to finally learn how to make my own color scheme&#8230; only to find that it&#8217;s a bit tricky!</strong></p>
<p><strong>Due to Vim&#8217;s longevity, it has to cover a lot of use cases</strong>: running on an <em>ancient</em> terminal, on a colour terminal, on a proper colour terminal, and on &#8220;the gui&#8221;. &#8220;The gui&#8221; are gVim, MacVim and all the other versions of Vim surrounded by nice menus for opening and closing files and copying and pasting. The ancient terminals&#8211;well, I haven&#8217;t had the opportunity of experimenting with those, so I&#8217;ll just assume it&#8217;s something clunky and left to collect dust in a storage basement, or it&#8217;s what banks and flight companies use to keep track of our movements. So that leaves us mere mortals with the colour terminals, and you might be wondering what&#8217;s the distinction between them and the &#8220;proper colour&#8221; terminals.</p>
<p>But wait&#8211;<strong>we don&#8217;t <em>really</em> use colour terminals</strong>. We use <strong>terminal emulators</strong>! Physical colour terminals are apparently limited by hardware to a fixed set of colours associated with numeric codes: a <strong>palette</strong>. Thus, the emulators follow this behaviour as well. So if you ask an emulator to show this or that colour, it will look up the corresponding colour in the palette. This means that you can define different &#8220;profiles&#8221; which modify the palette, amongst other aspects, and the same program can look different depending on the profile you&#8217;re using.</p>
<p>With this scenario set, you can safely anticipate that <strong>building a color scheme based on a palette that can be arbitrarily changed is going to be a mess</strong>, or at least <em>difficult</em>.</p>
<p>Vim works around this by allowing you to specify different colour values depending of the context Vim is running on. So you can say: <q>I want the &#8220;Normal&#8221; text to be &#8220;Black&#8221; on a simple terminal and on a colour terminal, and slightly off dark grey in a gui, and I want the background to be a &#8220;Light Grey&#8221;</q>. That, in Vim, is done this way:</p>
<div class="syhi_block"><code>highlight &nbsp; &nbsp; &nbsp; Normal&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctermbg=LightGray &nbsp; &nbsp; &nbsp; ctermfg=Black &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; guibg=LightGray &nbsp; &nbsp; &nbsp; &nbsp; guifg=#111111</code></div>
<p>If I tell you that <em>ctermfg</em> means <em>colour terminal foreground</em>, I think you can safely deduct the rest.</p>
<p>And generally, <em>Black</em> is black in the terminal profiles I&#8217;ve tested, but sometimes I specified other colours and got either something completely different, or just no change, like there were some hardware incompatibilities that the emulator was also following to the letter, and maybe it couldn&#8217;t show bold yellow over grey but could instead show bold magenta over grey.</p>
<p>I finally found that this was happening because <strong>apparently the GNOME Terminal that ships with Ubuntu is not capable of showing more than 15 colours</strong>. You&#8217;ve got to do &#8220;stuff&#8221; to get it to show more colours. The &#8220;stuff&#8221; was recompiling, according to some sources, or changing some values, according to other sources, or both, according to yet other sources.</p>
<p>At the end I just decided I&#8217;d focus on making a colour scheme that was &#8220;OK&#8221; when running on the default Ubuntu+GNOME terminal and &#8220;nice&#8221; when running on gVim (which <em>does</em> obey my colour indications and also allows to use RGB values!). It&#8217;s the colour scheme that I&#8217;m using on my .vimrc, <a href="https://github.com/sole/dotvim/blob/master/colors/sole.vim">sole.vim</a>, and that is still in its infancy since it&#8217;s missing definitions for many values O:-)</p>
<p><strong>Unfortunately gVim had an annoying quirk</strong>: I could paste something from the GNOME clipboard with <em>Shift+Control+V</em> when running Vim on a terminal, but that didn&#8217;t work on gVim. Instead, I had to use something as <em>intuitive</em> as <strong>&#8220;+gP</strong>. But guess what? I found a way to remap Control+C and Control+V to perform copy and paste:</p>
<div class="syhi_block"><code>nmap &lt;C-V&gt; &quot;+gP<br />
imap &lt;C-V&gt; &lt;ESC&gt;&lt;C-V&gt;i<br />
vmap &lt;C-C&gt; &quot;+y</code></div>
<p>And while I was at that, I thought I would change the font face too. I settled on <a href="http://www.levien.com/type/myfonts/inconsolata.html">Inconsolata</a>, as recommended by <a href="http://mrdoob.com">mrdoob</a>. I also changed the status bar to something a bit more <em>spiced</em> (thanks to Tsung-Hsiang&#8217;s vimrc again), followed a <a href="http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/">tutorial</a> to make Vim more suited to Python programming, and made sure that NERDTree was included as a git submodule, so that it would always be available whenever I installed my .vim in a computer.</p>
<p>So this is how gVim looks like currently (after removing the toolbar!):</p>
<p><img src="/imgs/2011/gvim.png" alt="My gVim" /></p>
<p>And as I wanted the same settings and scripts available both when using vim or gvim, I symlinked both .vimrc and .gvimrc (which is what gVim uses) to the same file. <del datetime="2011-07-04T06:27:26+00:00">I&#8217;m not sure if this is the best practice but it&#8217;ll stay this way for now.</del> <strong>Update:</strong> it&#8217;s <em>not</em> the best practice, as Andy Todd lets me know in the comment below! gVim reads first .vimrc and then reads .gvimrc, so I&#8217;ve created a .gvimrc file containing gui stuff only, and updated the install script that creates the symlinks too. It&#8217;s updated in my repo already :D</p>
<p>Finally, one for the curious: this is how I calculated how many days had elapsed since I started using Vim (taking my first Vim post as time reference).</p>
<div class="syhi_block"><code>sole@soletis:~$ python<br />
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) <br />
[GCC 4.4.5] on linux2<br />
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br />
&gt;&gt;&gt; import datetime<br />
&gt;&gt;&gt; t1 = datetime.datetime(year=2010, month=11, day=15)<br />
&gt;&gt;&gt; t2 = datetime.datetime(year=2011, month=7, day=3)<br />
&gt;&gt;&gt; (t2-t1).days + 14 # two weeks<br />
244</code></div>
<p> You wouldn&#8217;t expect me to add the days up manually, would you!? ;)</p>
 <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=3555&amp;md5=87de4e812ab5231d2770293e669c0d1f" title="Flattr" target="_blank"><img src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://soledadpenades.com/2011/07/03/244-days-with-vim-2-days-with-gvim-introducing-dotvim/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Coding nightmares</title>
		<link>http://soledadpenades.com/2009/06/15/coding-nightmares/</link>
		<comments>http://soledadpenades.com/2009/06/15/coding-nightmares/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 20:09:54 +0000</pubDate>
		<dc:creator>sole</dc:creator>
				<category><![CDATA[Common life]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[nightmares]]></category>

		<guid isPermaLink="false">http://soledadpenades.com/?p=1040</guid>
		<description><![CDATA[Upon reading the title, I think I&#8217;m right in assuming you probably thought I was going to write about a set of bad practices, or a series of horrible things one could find when refactoring code written by someone else. None of that, this time I&#8217;m referring to real, literally speaking, nightmares. I think it [...]]]></description>
			<content:encoded><![CDATA[<p>Upon reading the title, I think I&#8217;m right in assuming you probably thought I was going to write about a set of <q>bad practices</q>, or a series of horrible things one could find when refactoring code written by someone else. None of that, this time I&#8217;m referring to real, literally speaking, nightmares.</p>
<p>I think it happened for the first time almost 10 years ago. I had to implement a little shell in C for a university assignment and brave me hadn&#8217;t a better idea than printing parts of the code from <a href="http://www.gnu.org/software/bash/bash.html">bash</a> and examining it to get an idea of how the real stuff worked. It was all fine and dandy when reading the code at a train (apart from the odd looks that I got from people sitting near me, of course), but it proved to be a very bad idea to keep reading right before going to sleep. That night was the prelude of a long series of bad nights. I spent the whole night dreaming about pointers, structures, functions, loops, assignments, switch statements, case&#8217;s, mallocs&#8230; you get the point. When I woke up, my brain was totally wasted. It was just like if I hadn&#8217;t slept at all.</p>
<p>I thought that had only been a single event and wouldn&#8217;t happen again, but boy, wasn&#8217;t I wrong! It didn&#8217;t happen again, though, until I began to work in web development, and the main cause this time was the Horror. Of course, I&#8217;m referring to Internet <del datetime="2009-06-15T19:38:28+00:00">Explorer</del> Exploder. I have lost count of the number of nights I spent suffering horrible nightmares where things work properly in Firefox and Opera and blah but aren&#8217;t properly aligned in IE, or do not show where they should&#8230; Anyone who has had to develop for IE will for sure know what I mean.</p>
<p>The easiest way of avoiding these nightmares (for me) is to consciously focus on something completely unrelated before going to sleep. For example, to read something non-technical, like a fiction book where the action preferably happens in a time and place where the most advanced piece of technology is a ball pen.</p>
<p>But over time, there are days where I can&#8217;t but get super excited about something code wise, and continue coding right until my eyelids feel so heavy I can hardly keep my eyes open. Those are the nights I go to sleep scared in advance, because I know my brain is totally obsessed with the piece of code I&#8217;m working with, and as Bette Davis <a href="http://www.imdb.com/title/tt0042192/quotes#qt0481833">would say</a>, <q>&#8230; it&#8217;s going to be a bumpy night!</q> :D</p>
<p>And you? Do you have <em>real</em> coding nightmares? And if you have, how do you avoid them?</p>
]]></content:encoded>
			<wfw:commentRss>http://soledadpenades.com/2009/06/15/coding-nightmares/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Find out the full referrer (with the shell)</title>
		<link>http://soledadpenades.com/2006/10/03/find-out-the-full-referrer-with-the-shell/</link>
		<comments>http://soledadpenades.com/2006/10/03/find-out-the-full-referrer-with-the-shell/#comments</comments>
		<pubDate>Tue, 03 Oct 2006 20:18:16 +0000</pubDate>
		<dc:creator>sole</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://www.soledadpenades.com/2006/10/03/find-out-the-full-referrer-with-the-shell/</guid>
		<description><![CDATA[Are you fed up with Google Analytics not showing the full referrer url and just showing something like http://www.example.com/forum/viewtopic.php? I also do, I love to know who&#8217;s linking me (yeah I&#8217;m curious!). My hosting compresses access_logs which reach a certain size, so when I downloaded the access logs files I get a bunch of .gz [...]]]></description>
			<content:encoded><![CDATA[<p>Are you fed up with Google Analytics not showing the full referrer url and just showing something like http://www.example.com/forum/viewtopic.php? I also do, I love to know who&#8217;s linking me (yeah I&#8217;m curious!).</p>
<p>My hosting compresses access_logs which reach a certain size, so when I downloaded the access logs files I get a bunch of .gz files which I&#8217;m not going to manually uncompress&#8230; So I went to the terminal and once in the folder where the log files are, I type</p>
<blockquote><p>find . -name &#8220;*.gz&#8221; -exec gunzip {} \;</p></blockquote>
<p>Now I have lots of files like access_log.20060929, access_log.20060930, etc. For searching let&#8217;s say a referrer called example.com which I see in GA, I do:</p>
<blockquote><p>cat * | grep example.com</p></blockquote>
<p>and that will return you the apache log lines where the term appears.</p>
<p>For example:</p>
<blockquote><p>81.39.91.97 &#8211; - [26/Sep/2006:11:27:47 +0000] &#8220;GET /index.php HTTP/1.1&#8243; 200 9562 &#8220;http://example.com/viewtopic.php?t=747&#8243; &#8220;Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7&#8243;</p></blockquote>
<p>It&#8217;s a bit of brute force approach as it&#8217;s searching in all the files (now that I realize it&#8217;s even searching <em>in the compressed files</em> since I didn&#8217;t remove they yet, haha!). But it&#8217;s very fast even though!</p>
<p>With a bit more of love this could be a rudimentary stats script but I&#8217;m not that much into shell scripting (and I&#8217;m trying to force myself into really learning regular expressions to do that stats script with ruby instead).<br />
Oh and I forgot to say this works for any decent shell &#8211; linux, mac&#8230; I think I also could do it with a windows box with unxutils installed (so that you get the funky stuff like grep, find, cat, etc).</p>
]]></content:encoded>
			<wfw:commentRss>http://soledadpenades.com/2006/10/03/find-out-the-full-referrer-with-the-shell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

