<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Zsh on Miek Gieben</title>
    <link>https://miek.nl/tags/zsh/</link>
    <description>Recent content in Zsh on Miek Gieben</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <copyright>© Copyright 2007-2024 Miek Gieben</copyright>
    <lastBuildDate>Mon, 12 Aug 2019 07:24:27 +0000</lastBuildDate>
    <atom:link href="https://miek.nl/tags/zsh/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>My Terminal Setup</title>
      <link>https://miek.nl/2019/august/12/my-terminal-setup/</link>
      <pubDate>Mon, 12 Aug 2019 07:24:27 +0000</pubDate>
      <guid>https://miek.nl/2019/august/12/my-terminal-setup/</guid>
      <description>&lt;p&gt;Every so often I tweak my setup which includes the shell, terminal, mutt, Vim and their color&#xA;configuration. Currently I&amp;rsquo;m using a setup that I&amp;rsquo;ve tweaked a couple of &lt;strong&gt;years&lt;/strong&gt; back - it seems I&#xA;like this one. The color setup between my often used application are all unified, giving everything&#xA;a consistent look.&lt;/p&gt;&#xA;&lt;p&gt;As for colors; I like contrast: I have a black background terminal and the main text is white.&#xA;I&amp;rsquo;m also using a &lt;em&gt;minimal&lt;/em&gt; color scheme, just a few tints here and there. Most of the text is just&#xA;white.&lt;/p&gt;</description>
    </item>
    <item>
      <title>lean prompt (for zsh)</title>
      <link>https://miek.nl/2015/november/24/lean-prompt-for-zsh/</link>
      <pubDate>Tue, 24 Nov 2015 17:36:00 +0000</pubDate>
      <guid>https://miek.nl/2015/november/24/lean-prompt-for-zsh/</guid>
      <description>&lt;p&gt;After having used &lt;a href=&#34;https://github.com/sindresorhus/pure&#34;&gt;prompt pure&lt;/a&gt; for about&#xA;a year, I felt that a two-line prompt was not for me. Also not utilizing the&#xA;right side of the terminal seemed a missed opportunity. Still there is much to&#xA;like: the elapsed time of a process, the coloring of the prompt if the exit code&#xA;of the process isn&amp;rsquo;t 0, git integration and the stay out of my way. So I took&#xA;&amp;ldquo;pure&amp;rdquo;, mixed in my ideas of what a prompt should look like and came up with&#xA;&amp;ldquo;lean&amp;rdquo; - a 1 line prompt that stays out of your face.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Make me a sandwich, MAKE me a sandwich</title>
      <link>https://miek.nl/2013/january/30/make-me-a-sandwich-make-me-a-sandwich/</link>
      <pubDate>Wed, 30 Jan 2013 23:17:00 +0000</pubDate>
      <guid>https://miek.nl/2013/january/30/make-me-a-sandwich-make-me-a-sandwich/</guid>
      <description>&lt;p&gt;We all know this comic:&lt;/p&gt;&#xA;&lt;img src=&#34;http://imgs.xkcd.com/comics/sandwich.png&#34; /&gt;&#xA;&lt;p&gt;And now in &lt;code&gt;zsh&lt;/code&gt;!&lt;/p&gt;&#xA;&lt;p&gt;With the following snippet all commands that are started with an uppercase word&#xA;will be prefixed with &lt;code&gt;sudo &lt;/code&gt; and then executed.&lt;/p&gt;&#xA;&lt;p&gt;So &lt;em&gt;MAKE me a sandwich&lt;/em&gt;, becomes &lt;em&gt;sudo make me a sandwich&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;accept-line() {&#xA;    local B&#xA;    B=(${=BUFFER})&#xA;    if [[ &amp;quot;$B[1]&amp;quot; != [A-Z]* ]]; then&#xA;        zle .accept-line&#xA;        return&#xA;    fi&#xA;    if [[ $B[1] != &amp;quot;&amp;quot; &amp;amp;&amp;amp; $B[1] == $B[1]:u ]]; then&#xA;        BUFFER=&amp;quot;sudo $B[1]:l $B[2,-1]&amp;quot;&#xA;    fi&#xA;    zle .accept-line&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And activate with:&lt;/p&gt;</description>
    </item>
    <item>
      <title>color me, color you</title>
      <link>https://miek.nl/2011/september/18/color-me-color-you/</link>
      <pubDate>Sun, 18 Sep 2011 09:50:00 +0000</pubDate>
      <guid>https://miek.nl/2011/september/18/color-me-color-you/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;https://miek.nl/2011/september/11/xoria256m_color_scheme/index.html&#34;&gt;the xoria256m post&lt;/a&gt;,&#xA;I introduced my xoria256 like color scheme. Again, inspired by&#xA;&lt;a href=&#34;http://ethanschoonover.com/solarized&#34;&gt;solarized&lt;/a&gt;, I extended&#xA;this to other applications. So now I use this in the following apps:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;vim (see that previous post);&lt;/li&gt;&#xA;&lt;li&gt;mutt (idem);&lt;/li&gt;&#xA;&lt;li&gt;zsh;&lt;/li&gt;&#xA;&lt;li&gt;dircolors;&lt;/li&gt;&#xA;&lt;li&gt;git (a bit).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h1 id=&#34;zsh&#34;&gt;zsh&lt;/h1&gt;&#xA;&lt;p&gt;See this file&#xA;&lt;a href=&#34;https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/spectrum.zsh&#34;&gt;to setup the colors&lt;/a&gt;.&#xA;Then in my prompt I have stuff like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;PS1=$&#39;${vcs_info_msg_0_}$FG[067]%(1j.$myjobs% $FX[reset].$FX[reset])$FG[179]%#$FX[reset] &#39;&#xA;RPS1=&amp;quot;$RPSL%$MAXMID&amp;lt;...&amp;lt;$mypath$RPSR$FG[239]$FX[bold]$__ZH$FX[reset]${vcs_info_msg_1_}&amp;quot;&#xA;RPSR=$&#39;$FX[reset]$FG[009]%(0?.$FG[reset]. $E)$FX[reset]&#39;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;For zsh I have two files that make up my prompt:&lt;/p&gt;</description>
    </item>
    <item>
      <title>My f() function in Zsh (and maybe Bash)</title>
      <link>https://miek.nl/2010/january/05/my-f-function-in-zsh-and-maybe-bash/</link>
      <pubDate>Tue, 05 Jan 2010 20:04:00 +0000</pubDate>
      <guid>https://miek.nl/2010/january/05/my-f-function-in-zsh-and-maybe-bash/</guid>
      <description>&lt;p&gt;Familiar with the following?&lt;/p&gt;&#xA;&lt;p&gt;You are aware of (shell)file which contains a interesting line and&#xA;you think: &amp;ldquo;I want to execute this line on the command prompt&amp;rdquo;. Most&#xA;people will do the following:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;% more &amp;lt;file&amp;gt;&#xA;[select interesting bit with your mouse]&#xA;[paste]&amp;lt;enter&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And the code gets executed.&lt;/p&gt;&#xA;&lt;p&gt;I propose the following function: &lt;code&gt;f()&lt;/code&gt;, which does the following:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;It opens the file in $EDITOR (:= &lt;code&gt;vim&lt;/code&gt; of course);&lt;/li&gt;&#xA;&lt;li&gt;You delete everything you &lt;em&gt;don&amp;rsquo;t&lt;/em&gt; want to execute;&lt;/li&gt;&#xA;&lt;li&gt;What&amp;rsquo;s left gets executed;&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;And&lt;/em&gt; it is added to your shell&amp;rsquo;s history.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The code of the function looks like this:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Case insensitive cd</title>
      <link>https://miek.nl/2009/july/21/case-insensitive-cd/</link>
      <pubDate>Tue, 21 Jul 2009 00:10:00 +0000</pubDate>
      <guid>https://miek.nl/2009/july/21/case-insensitive-cd/</guid>
      <description>&lt;p&gt;Do I want this?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;% ls -ld Joe_Cocker_-_The_Definitive_Collection &#xA;drwxr-xr-x 2 miekg admin 4.0K Jul 20 22:20 Joe_Cocker_-_The_Definitive_Collection/&#xA;% cd *joe*&#xA;cd: no such file or directory: *joe*&#xA;% unsetop case_glob &#xA;% cd *joe*&#xA;% pwd&#xA;/shared/vol/music/J/Joe_Cocker_-_The_Definitive_Collection&#xA;&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    <item>
      <title>Zsh prompt updates</title>
      <link>https://miek.nl/2009/may/22/zsh-prompt-updates/</link>
      <pubDate>Fri, 22 May 2009 18:13:00 +0000</pubDate>
      <guid>https://miek.nl/2009/may/22/zsh-prompt-updates/</guid>
      <description>&lt;p&gt;I wanted some &lt;code&gt;git&lt;/code&gt; information in the prompt I currently have.&#xA;While thinking and googling about this, a quote on&#xA;&lt;a href=&#34;http://www.jukie.net/~bart&#34;&gt;Bart&amp;rsquo;s log&lt;/a&gt; got me thinking. I don&amp;rsquo;t need&#xA;to see my current host, nor do I need to see my current user name.&lt;/p&gt;&#xA;&lt;p&gt;I always login under my own account (&lt;code&gt;miekg&lt;/code&gt;) and if I &lt;em&gt;do&lt;/em&gt; change&#xA;accounts, I probably will be forced to use &lt;code&gt;bash&lt;/code&gt;. So showing the current user name&#xA;is quite useless.&lt;/p&gt;</description>
    </item>
    <item>
      <title>The builtin test operator</title>
      <link>https://miek.nl/2009/february/05/the-builtin-test-operator/</link>
      <pubDate>Thu, 05 Feb 2009 15:16:00 +0000</pubDate>
      <guid>https://miek.nl/2009/february/05/the-builtin-test-operator/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;http://www.gnu.org/software/bash&#34;&gt;bash&lt;/a&gt; (and other shells) you&#xA;can use the [[ construct&lt;/p&gt;&#xA;&lt;p&gt;From the bash manpage:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;[[ expression ]]&#xA;          Return a status of 0 or 1 depending on  the  evaluation  of  the&#xA;          conditional  expression expression.  Expressions are composed of&#xA;          the primaries described  below  under  CONDITIONAL  EXPRESSIONS.&#xA;&#xA;          Word  splitting  and pathname expansion are not performed on the&#xA;&#xA;          words between the [[ and  ]];  tilde  expansion,  parameter  and&#xA;          variable  expansion, arithmetic expansion, command substitution,&#xA;          process substitution, and quote removal are  performed.   Condi‐&#xA;          tional operators such as -f must be unquoted to be recognized as&#xA;          primaries.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So no &lt;em&gt;word splitting&lt;/em&gt; and &lt;em&gt;pathname expansion&lt;/em&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>ssh&#39;s ControlMaster with zsh</title>
      <link>https://miek.nl/2008/december/31/sshs-controlmaster-with-zsh/</link>
      <pubDate>Wed, 31 Dec 2008 18:25:00 +0000</pubDate>
      <guid>https://miek.nl/2008/december/31/sshs-controlmaster-with-zsh/</guid>
      <description>&lt;p&gt;You are using the &lt;a href=&#34;http://www.linux.com/feature/54498&#34;&gt;ControlMaster&lt;/a&gt;&#xA;feature of &lt;code&gt;ssh&lt;/code&gt; and you are having problems remembering&#xA;which shell is the master?&lt;/p&gt;&#xA;&lt;p&gt;That&amp;rsquo;s why I&amp;rsquo;ve made &lt;code&gt;zsh&lt;/code&gt; display this in the prompt.&#xA;You get a &lt;code&gt;m@&lt;/code&gt; when a connection is a master connection and&#xA;an &lt;code&gt;@&lt;/code&gt; if it is a slave.&lt;/p&gt;&#xA;&lt;h1 id=&#34;setting-up&#34;&gt;setting up&lt;/h1&gt;&#xA;&lt;p&gt;The check if we are a master works by creating a file&#xA;which has &lt;code&gt;$SSH_CLIENT&lt;/code&gt; as the name, as the following snippet shows.&lt;/p&gt;</description>
    </item>
    <item>
      <title>updated gitvi script</title>
      <link>https://miek.nl/2008/december/30/updated-gitvi-script/</link>
      <pubDate>Tue, 30 Dec 2008 10:29:00 +0000</pubDate>
      <guid>https://miek.nl/2008/december/30/updated-gitvi-script/</guid>
      <description>&lt;p&gt;The script in&#xA;&lt;a href=&#34;https://miek.nl/2008/december/27/using_git_and_vi_together/index.html&#34;&gt;using git and vi&#xA;together&lt;/a&gt;&#xA;was a little bit borked, as too many git repo&amp;rsquo;s were created. Hence a&#xA;new and improved version. This one will look up the directory tree to&#xA;spot an existing git repository - is nothing found a new one will be&#xA;created in &lt;code&gt;$PWD&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h1 id=&#34;code&#34;&gt;code&lt;/h1&gt;&#xA;&lt;pre&gt;&lt;code&gt;#!/bin/zsh&#xA;# a wrapper around git and vi&#xA;# expands $Hash$ to $Hash: file short_hash epoch committer $&#xA;# git checkout HEAD $file? when would I need this&#xA;# TODO: spaces in filename&#xA;&#xA;[[ ! -x =git ]] &amp;amp;&amp;amp; exit 1&#xA;&#xA;who=$SUDO_USER&#xA;who=${who:-$LOGNAME}&#xA;&#xA;function search_git_dir {&#xA;    gpath=&amp;quot;$1&amp;quot;&#xA;&#xA;    [[ -d &amp;quot;$gpath/.git&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;$gpath&amp;quot; &amp;amp;&amp;amp; return&#xA;    [[ -z &amp;quot;$gpath&amp;quot; ]] &amp;amp;&amp;amp; echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; return&#xA;&#xA;    # strip that last path component and try again&#xA;    search_git_dir &amp;quot;${gpath%/*}&amp;quot;&#xA;}&#xA;&#xA;for file in &amp;quot;$@&amp;quot;; do&#xA;dir=$(dirname $file); cd $dir&#xA;base=$(basename $file)&#xA;&#xA;if [[ -z $(search_git_dir $PWD) ]]; then&#xA;    # make a new one in $PWD&#xA;    git init || exit 1&#xA;else&#xA;    #echo FOUND ONE&#xA;fi&#xA;chmod +w $base 2&amp;gt; /dev/null&#xA;&#xA;if vi $base; then&#xA;    [[ ! -e $base ]] &amp;amp;&amp;amp; exit 0&#xA;    git add $base&#xA;    # collapse $Hash: id $ line&#xA;    sed -i -e &#39;s/\$Hash:.*\$/$Hash$/&#39; $base&#xA;    git commit $base&#xA;fi&#xA;&#xA;id=$(git-show -s --pretty=format:$base\ %h\ %ct\ $who%n -- $base) &#xA;[[ -z $id ]] &amp;amp;&amp;amp; exit 1&#xA;&#xA;# re-add $Hash: sha1hash$ line&#xA;sed -i -e &#39;s/\$Hash\$&#39;/\$Hash:\ $id\ \$/ $base&#xA;&#xA;chmod a-w $base 2&amp;gt; /dev/null&#xA;done&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;manpage&#xA;And ofcourse the manpage.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using GIT and VI together</title>
      <link>https://miek.nl/2008/december/27/using-git-and-vi-together/</link>
      <pubDate>Sat, 27 Dec 2008 20:15:00 +0000</pubDate>
      <guid>https://miek.nl/2008/december/27/using-git-and-vi-together/</guid>
      <description>&lt;p&gt;A long while back I used &lt;code&gt;vi&lt;/code&gt; together with &lt;code&gt;rcs&lt;/code&gt; to manage files&#xA;in &lt;code&gt;/etc&lt;/code&gt;. This worked, but I found &lt;code&gt;rcs&lt;/code&gt; to be clunky. So welcome&#xA;to the 21st century and my &lt;code&gt;git&lt;/code&gt; + &lt;code&gt;vi&lt;/code&gt; script.&lt;/p&gt;&#xA;&lt;p&gt;It is a wrapper around &lt;code&gt;git&lt;/code&gt;, which will create a new&#xA;git repository, add the file and commit it when changed.&lt;/p&gt;&#xA;&lt;p&gt;The script will also expand &lt;code&gt;$Hash$&lt;/code&gt; to&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;$Hash: basename-of-file short-commit-hash epoch committer`&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;a typical example is&lt;/p&gt;</description>
    </item>
    <item>
      <title>f()</title>
      <link>https://miek.nl/2008/july/10/f/</link>
      <pubDate>Thu, 10 Jul 2008 14:23:00 +0000</pubDate>
      <guid>https://miek.nl/2008/july/10/f/</guid>
      <description>&lt;p&gt;You all, of course, know about the &lt;code&gt;fc&lt;/code&gt; command. From bash&amp;rsquo;s help system:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;fc: fc [-e ename] [-nlr] [first] [last] or fc -s [pat=rep] [cmd]&lt;/p&gt;&#xA;&lt;p&gt;fc is used to list or edit and re-execute commands from the history list.&#xA;FIRST and LAST can be numbers specifying the range, or FIRST can be a&#xA;string, which means the most recent command beginning with that&#xA;string.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Now I had the following problem: you have a file with shell commands in&#xA;it. Next you want to select a few lines from this file to be executed in&#xA;your running shell. A way to do this is:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
