urxvt https://tech.feedyourhead.at/ en The Rule Of Three (Part2) https://tech.feedyourhead.at/content/rule-three-part2 <span class="field field--name-title field--type-string field--label-hidden">The Rule Of Three (Part2)</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>A sysadmin needs his tools.&nbsp; I really need at least 3 tools to be productive:</p> <ol> <li> <div>Terminal-Emulator (or screen/tmux if I am working without X)</div> </li> <li> <div>Shell</div> </li> <li> <div>Editor</div> </li> </ol> <p>This is my <a href="https://en.wikipedia.org/wiki/Rule_of_three_%28writing%29">Rule Of Three.</a> Those 3 tools can make my life much easier. Therefore I have to choose those tools wisely. And of course I have to know them very well, so I can get all the benefits of them. The last time I wrote about <a href="http://tech.feedyourhead.at/content/rule-three-part-1">rxvt(Terminal-Emulator)</a>. In&nbsp; this article I want to introduce one of my "favourite" shells: <a href="http://www.zsh.org/"><em>zsh</em></a></p> <p>I have to say that I like the <a href="https://www.gnu.org/software/bash/">bash</a> too. It is my rootshell and I am very used to the <a href="https://www.gnu.org/software/bash/">bash</a> because I am using it for many years. Zsh on the other side is very customizable and has cool scripting-features, that's why it became my standard usershell.</p> <h2>Customization</h2> <p>What's really great about zsh is that it is highly customizable. The problem with "highly customizable" is mostly that things start to get complex. Luckily, there are frameworks to make this task more easy. One of them is <a href="http://ohmyz.sh/">oh-my-zsh</a>. It's loaded via your .zshrc and comes with lot's of plugins for autocompletion and themes. Just try it, it's great!</p> <h2>Autoload long commands in you editor</h2> <p>If you just typed in a very long command in your shell and you want this command copied in your favourite editor($EDITOR) then just type <strong>&lt;CTRL&gt;+X &lt;CTRL&gt;+E</strong></p> <h2>Builtin Pager</h2> <p>zsh has a builtin pager. If you want to read a (text)file just type:</p> <pre> <code> &lt; sometextfile.txt </code></pre> <h2>History search</h2> <p>Most bash-user know "<strong>&lt;STRG&gt;+&lt;r&gt;</strong>" for recursively search the history.&nbsp; If you want to search the history for a command you can use the <strong>&lt;UP&gt;</strong> key.&nbsp; Let's assume we are looking for one of our last ssh commands, then we can simply type<code> <em>ssh &lt;UP&gt;</em> </code></p> <h2 id="tab-completion-on-cd">Tab completion</h2> <h3>Autocomplete cd</h3> <p>One of the cool things in zsh is tab completion. If you type "cd <strong>&lt;TAB&gt;</strong>" it looks like this:</p> <p><img alt="" src="/sites/tech.feedyourhead.at/files/pictures/zsh_tab_complete.png" style="width: 871px; height: 130px;" /></p> <p>You can navigate using <strong>&lt;TAB&gt;</strong> or any <strong>&lt;ARROW-KEY&gt;</strong> through this menu, or just type the first letter of one directory and press <strong>&lt;TAB&gt;</strong> again...</p> <h3>Smart completion of a path</h3> <p>You can also shortcut a path. Let's assume you have a path like this:</p> <pre> <code> arch/openrisc/kernel </code></pre> <p>Then you can just type:</p> <pre> <code> a/o/k<tab> </tab></code></pre> <p>..hit <strong>&lt;TAB&gt;</strong> and zsh will autocomplete your command, or ask you if there are more than one directories with the same letter.</p> <h3>Autocomplete commands</h3> <p>Zsh can even autocomplete commands and command-line-arguments. Autocompletion is highly configurable but also quite complex. I would recommend to use <a href="http://ohmyz.sh/">oh-my-zsh</a> for this.</p> <p>Some Command-completes I really like are:</p> <ul> <li>This comes with oh-my-zsh: <em>git &lt;TAB&gt;</em>&nbsp; or <em>git co&lt;TAB&gt;</em></li> <li>Get a list of your /etc/hosts: <em>ssh root@&lt;TAB&gt;</em></li> <li>Get a list of arguments of vim: <em>vim -&lt;TAB&gt;</em></li> <li>Get a list of processes to kill: <em>kill &lt;TAB&gt;</em></li> </ul> <h2>Sophisticated Globbing</h2> <p>Globbing means searching files in your filesystem by using wildcards. This will search in your working directory and execute ls with all files(and directories) beginning with z :</p> <pre> <code> ➜ Documentation ls z* zorro.txt zh_CN: arm filesystems magic-number.txt stable_kernel_rules.txt arm64 gpio.txt oops-tracing.txt SubmittingDrivers basic_profiling.txt HOWTO SecurityBugs SubmittingPatches CodingStyle io_ordering.txt sparse.txt video4linux email-clients.txt IRQ.txt stable_api_nonsense.txt volatile-considered-harmful.txt </code></pre> <p>With zsh you can also glob recursively</p> <pre> <code> ➜ linux-4.2.4 ls **/*.pl arch/arm/crypto/bsaes-armv7.pl arch/arm/crypto/sha256-armv4.pl arch/arm/crypto/sha512-armv4.pl Documentation/filesystems/cifs/winucase_convert.pl Documentation/trace/postprocess/trace-pagealloc-postprocess.pl Documentation/trace/postprocess/trace-vmscan-postprocess.pl Documentation/video4linux/extract_xc3028.pl drivers/crypto/vmx/aesp8-ppc.pl drivers/crypto/vmx/ghashp8-ppc.pl drivers/crypto/vmx/ppc-xlate.pl drivers/scsi/script_asm.pl drivers/usb/serial/ezusb_convert.pl scripts/bootgraph.pl scripts/checkincludes.pl scripts/checkpatch.pl scripts/checkstack.pl scripts/checkversion.pl scripts/export_report.pl scripts/get_maintainer.pl scripts/headerdep.pl scripts/headers_check.pl scripts/kconfig/streamline_config.pl scripts/markup_oops.pl scripts/namespace.pl scripts/profile2linkerlist.pl scripts/recordmcount.pl tools/perf/scripts/perl/check-perf-trace.pl tools/perf/scripts/perl/failed-syscalls.pl tools/perf/scripts/perl/rw-by-file.pl tools/perf/scripts/perl/rw-by-pid.pl tools/perf/scripts/perl/rwtop.pl tools/perf/scripts/perl/wakeup-latency.pl tools/testing/ktest/compare-ktest-sample.pl tools/testing/ktest/ktest.pl </code></pre> <h3>Replace find</h3> <p>Sometimes we need to find some files and execute commands using the search-results as arguments. For example find all files with permissions 444 and move them to /tmp:</p> <pre> <code> find . -perm -444 -exec mv {} /tmp \; </code></pre> <p>We can do this in zsh using the following command:</p> <pre> <code> mv **/*(rAR) /tmp </code></pre> <p>r means "u+r", A means "g+r" and R means "o+r".</p> <p>Finding files owned by root:</p> <pre> <code> ls **/*(u:root:) </code></pre> <p>Finding files owned by root and with user-executable set:</p> <pre> <code>ls -l **/*(u:root:x) </code></pre> <p>A complete list of available expansion-commands can be found in the manual page:</p> <pre> <code> man zshexpn </code></pre> <h2>Scripting</h2> <p>Zsh has lots of modules which can be loaded, it supports arrays and has lots of nice builtin features. A good point to get some overview are <a href="http://grml.org/zsh/zsh-lovers.html">zsh-lovers</a>.</p> <h2>Make&nbsp; zsh bash-compatible</h2> <p>By default zsh is not compatible with bash. if you need it bash-compatible just type:</p> <pre> <code> emulate sh </code></pre> <h2>Builtin Tetris</h2> <p>Last but not least: zsh has it's builtin tetris!!! Type the following commands:</p> <pre> <code> autoload -U tetris zle -N tetris bindkey ^h tetris </code></pre> <p>.. and hit <ctrl>&lt;CTRL&gt;+h</ctrl></p> <h2>Conclusion</h2> <p>Zsh is fully customizable and very handy. Whenever I open its manual pages, i'll find new cool features. Zsh improves my workflows, that's why I love using it.&nbsp;</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Oct 25 2015</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruleofthree" hreflang="en">RuleOfThree</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/urxvt" hreflang="en">urxvt</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/terminalemulator" hreflang="en">TerminalEmulator</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/shell" hreflang="en">Shell</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/zsh" hreflang="en">Zsh</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/bash" hreflang="en">Bash</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=124&amp;2=comment&amp;3=comment" token="nJC6mOX0qsDV806ohRO6NLteDJ1Aoc5Dvj1HDKy6_Gc"></drupal-render-placeholder> </section> Sun, 25 Oct 2015 11:48:27 +0000 Hoti 124 at https://tech.feedyourhead.at The Rule Of Three (Part 1) https://tech.feedyourhead.at/content/rule-three-part-1 <span class="field field--name-title field--type-string field--label-hidden">The Rule Of Three (Part 1)</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>A sysadmin needs his tools.&nbsp; I really need at least 3 tools to be productive:</p> <ol> <li> <div>Terminal-Emulator (or screen/tmux if I am working without X)</div> </li> <li> <div>Shell</div> </li> <li> <div>Editor</div> </li> </ol> <p>This is my <a href="https://en.wikipedia.org/wiki/Rule_of_three_%28writing%29">Rule Of Three.</a> Those 3 tools can make my life much easier. Therefore I have to choose those tools wisely. And of course I have to know them very well, so I can get all the benefits of them. In this article I want to introduce my favourite terminal emulator: <a href="http://sourceforge.net/projects/rxvt/">urxvt</a></p> <h4>I expect some things of my terminal emulator:</h4> <ol> <li>It should be lightweight</li> <li>It should have a nice Look&amp;Feel</li> <li>It should be customizable</li> <li>It should make my work easier</li> <li>It should support utf8</li> </ol> <h3>Lightweight and fast</h3> <p>One of those applications that I open and close the most, is the terminal emulator. That's why I really appreciate if those windows are fast and if they don't need much resources. urxvt can be started in daemon-mode in order to save resources. This could be a line of a $HOME/.xsession:</p> <pre> <code> urxvtd -q -f -o </code></pre> <p>Now we can start urxvt in client-mode:</p> <pre> <code> urxvtc </code></pre> <p>This client starts with the process-id of the daemon:</p> <pre> <code> urxvtd(4225)─┬─cmus(4305)─┬─{cmus}(4306) │ ├─{cmus}(4307) │ ├─{cmus}(4308) │ ├─{threaded-ml}(4309) │ └─{threaded-ml}(4313) ├─zsh(4226) ├─zsh(4254)───pstree(4336) └─zsh(4281)───htop(4301) </code></pre> <p>There is a wrapper called <em>urxvtcd</em> which starts the daemon first if it isn't already running. This wrapper is a nice alternative for starting the daemon in the beginning of a xsession.</p> <p>Be aware: if you kill(xkill) one of the terminals, you will loose all your terminals at once! If you don't want to open rxvt with a daemon, you can just run it normal using the command: <em>urxvt</em></p> <h3>Look&amp;Feel</h3> <p>By default urxvt looks quite ugly:</p> <p><img alt="" src="http://tech.feedyourhead.at/sites/tech.feedyourhead.at/files/pictures/rxvt_ugly.jpg" /></p> <p>After some modifications it looks fancy:</p> <p><img alt="" src="http://tech.feedyourhead.at/sites/tech.feedyourhead.at/files/pictures/rxvt_nice.jpg" /></p> <p>&nbsp;</p> <h3>Customizing urxvt</h3> <p>urxvt can be customized by command-line or just via .Xresources (or $HOME/.Xdefaults). That's my $HOME/.Xdefaults:</p> <pre> <code> URxvt*termName: rxvt-unicode URxvt*geometry: 100x30 URxvt*loginShell: true URxvt*scrollColor: #777777 URxvt*scrollstyle: plain URxvt*scrollTtyKeypress: true URxvt*scrollTtyOutput: false URxvt*scrollWithBuffer: false URxvt*secondaryScreen: true URxvt*secondaryScroll: true URxvt*scrollBar: true URxvt*scrollBar_right: true URxvt*scrollBar_floating: true URxvt*fading: 30 URxvt*utmpInhibit: false URxvt*urgentOnBell: false URxvt*visualBell: true URxvt*mapAlert: true URxvt*mouseWheelScrollPage: true URxvt*background: Black URxvt*foreground: White URxvt*colorUL: yellow URxvt*underlineColor: yellow URxvt*font: -xos4-terminus-medium-*-*-*-20-*-*-*-*-*-iso8859-15,xft:terminus:pixelsize:12 URxvt*boldFont: -xos4-terminus-bold-*-*-*-20-*-*-*-*-*-iso8859-15,xft:terminus:bold:pixelsize:12 URxvt*italicFont: xft:Bitstream Vera Sans Mono:italic:autohint=true:pixelsize=12 URxvt*boldItalicFont: xft:Bitstream Vera Sans Mono:bold:italic:autohint=true:pixelsize=12 URxvt*saveLines: 20000 URxvt*buffered: true URxvt*hold: false URxvt*internalBorder: URxvt*print-pipe: cat &gt; $HOME/$(echo urxvt.dump.$(date +'%Y%M%d%H%m%S')) URxvt*reverseVideo: false URxvt*perl-ext-common : default,matcher,selection-to-clipboard URxvt*url-launcher : firefox URxvt*matcher.button : 1 </code></pre> <h3>Make my work easier</h3> <p>urxvt is very customizable by using perl-extensions.&nbsp; those plugins were shipped with urxvt:</p> <pre> <code> ls /usr/lib/urxvt/perl background keysym-list readline selection-to-clipboard bell-command kuake remote-clipboard tabbed block-graphics-to-ascii macosx-clipboard searchable-scrollback urxvt-popup clipboard-osc macosx-clipboard-native selection xim-onthespot confirm-paste matcher selection-autotransform digital-clock option-popup selection-pastebin example-refresh-hooks overlay-osc selection-popup </code></pre> <p>A very nice one is matcher:</p> <blockquote> <p>"match strings in terminal output and change their rendition"</p> </blockquote> <p>In that way all my web-urls are underlined and if I click they will be opened by firefox.</p> <p>Another very useful extension is searchable-scrollback:</p> <blockquote> <p>"searchable-scrollback&lt;hotkey&gt; - incremental scrollback search (enabled by default)"</p> </blockquote> <p>This extension allows me to search in my scrollback using the shortcut Ctrl+Mod+s</p> <p>I can defenitely recommend to have a look at the plugins in /usr/lib/urxvt/perl</p> <h3>Last but not least: utf8</h3> <p>urxvt(rxvt-unicode) is the unicode version of rxvt and therefor it does support utf8.</p> <h3>Conclusion</h3> <p>urxvt is an amazing tool. It's fast, it's customizable and has all the features I expect of a terminal emulator. If someone want's to know more about urxvt, I would recommend <a href="https://wiki.archlinux.org/index.php/Rxvt-unicode">the article at the arch-linux-wiki</a>.</p> <p>&nbsp;</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Sep 28 2015</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruleofthree" hreflang="en">RuleOfThree</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/urxvt" hreflang="en">urxvt</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/terminalemulator" hreflang="en">TerminalEmulator</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/shell" hreflang="en">Shell</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=113&amp;2=comment&amp;3=comment" token="ORNd7PpLBNTMDvQ1_p9Z0sEOIi0heEJTbdJqM8NK7Ms"></drupal-render-placeholder> </section> Mon, 28 Sep 2015 21:50:47 +0000 Hoti 113 at https://tech.feedyourhead.at