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

<?xml-stylesheet type="text/xsl" href="/templates/2k11/rss.xsl" media="screen" ?>
<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    
    <title>Daniel Lange's blog (Entries tagged as terminal)</title>
    <link>http://daniel-lange.com/</link>
    <description>agrep -pB IT /dev/life</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 2.6.0 - http://www.s9y.org/</generator>
    <pubDate>Thu, 13 Jul 2017 16:09:32 GMT</pubDate>

    <image>
    <url>//daniel-lange.com/uploads/Avatar_Blog_144_234.png</url>
    <title>RSS: Daniel Lange's blog - agrep -pB IT /dev/life</title>
    <link>http://daniel-lange.com/</link>
    <width>144</width>
    <height>234</height>
</image>

<item>
    <title>tail -S (truncating lines to terminal width)</title>
    <link>http://daniel-lange.com/archives/134-tail-S-truncating-lines-to-terminal-width.html</link>
            <category>Open Source</category>
    
    <comments>http://daniel-lange.com/archives/134-tail-S-truncating-lines-to-terminal-width.html#comments</comments>
    <wfw:comment>http://daniel-lange.com/wfwcomment.php?cid=134</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://daniel-lange.com/rss.php?version=2.0&amp;type=comments&amp;cid=134</wfw:commentRss>
    

    <author>nospam@example.com (Daniel Lange)</author>
    <content:encoded>
    &lt;p&gt;The tail command has a quite glaring omission in that it can&#039;t truncate lines.
Thus it wraps long log line into multiple terminal lines regardless. Which makes them very hard to read.&lt;/p&gt;

&lt;p&gt;I used to work around this using &lt;code&gt;less -S&lt;/code&gt; and then hitting the &lt;tt&gt;[F]&lt;/tt&gt; key but that&#039;s interactive. &lt;code&gt;less +F &amp;lt;filename&amp;gt;&lt;/code&gt; is the little known work-around for the interactive issue but that still doesn&#039;t work well with pipes (&lt;code&gt;tail -f logfile | grep &quot;ERROR:&quot;&lt;/code&gt; etc).&lt;/p&gt;

&lt;p&gt;There is a &lt;a href=&quot;https://lists.gnu.org/archive/html/bug-coreutils/2004-12/msg00068.html&quot;&gt;bug report from 2004&lt;/a&gt; against GNU coreutils but that went nowhere.&lt;/p&gt;

&lt;p&gt;So we&#039;re not getting a &lt;code&gt;tail -S&lt;/code&gt; anytime soon.&lt;/p&gt;

&lt;h3&gt;Bash to the rescue: tail -S → tails&lt;/h3&gt;

&lt;p&gt;Hence I wrote this little script, &lt;a href=&quot;http://daniel-lange.com/software/tails&quot; title=&quot;Download the tails script&quot;&gt;&lt;strong&gt;tails&lt;/strong&gt;&lt;/a&gt; [1kB]:&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #666666; font-style: italic;&quot;&gt;#!/bin/bash -i&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #666666; font-style: italic;&quot;&gt;# v2 from 170712: introduce loop to work around GNU coreutils issues with pipe/fifo/isatty&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;#160;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-z&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #007800;&quot;&gt;$COLUMNS&lt;/span&gt;&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#93;&lt;/span&gt; ; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;then&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #007800;&quot;&gt;MYCOL&lt;/span&gt;=$&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#40;&lt;/span&gt;tput cols&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #007800;&quot;&gt;MYCOL&lt;/span&gt;=&lt;span style=&quot;color: #800000;&quot;&gt;${COLUMNS}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;fi&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;tail&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;$@&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;|&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;read&lt;/span&gt; line; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #007800;&quot;&gt;$line&lt;/span&gt;&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;|&lt;/span&gt; expand &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;|&lt;/span&gt; &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;cut&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-c1-&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;${MYCOL:-80}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;done&lt;/span&gt;﻿&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;

&lt;p&gt;Now, there are some interesting bits even in this tiny script:&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;bash -i&lt;/code&gt; results in &lt;code&gt;$COLUMNS&lt;/code&gt; being set within the script on sane Linux bash. Otherwise that variable wouldn&#039;t be available. Because it is a shell variable and not an environment variable. You knew that, right?&lt;/p&gt;

&lt;p&gt;Unfortunately the &lt;code&gt;bash -i&lt;/code&gt; doesn&#039;t get &lt;code&gt;$COLUMNS&lt;/code&gt; set on either MacOS (X) or FreeBSD, so that&#039;s where the &lt;code&gt;tput cols&lt;/code&gt; comes into play. It outputs the column width for the current terminal to stdout.&lt;/p&gt;

&lt;p&gt;If all that fails &lt;strong&gt;tails&lt;/strong&gt; will default to 80 columns.&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;tails -f /var/log/apache/access.log&lt;/code&gt; will now look nice.&lt;/p&gt;

&lt;h3&gt;Corner case: color&lt;/h3&gt;

&lt;p&gt;If you use color codes somewhere (&lt;code&gt;grep --color=always&lt;/code&gt;, &lt;code&gt;dmesg --color=always&lt;/code&gt;) &lt;strong&gt;tails&lt;/strong&gt; will just truncate lines too short so they will still not wrap.&lt;br /&gt;
There is a slight risk that it may cut into half a color code escape sequence and mess up the terminal a bit.
You could change that by removing the &lt;code&gt;-i&lt;/code&gt; from the shebang line and setting $COLUMNS explicitly. But that then needs manual adjustment for each combination of colored lines (=count of ANSI sequences) and terminal width. Better to color after the &lt;strong&gt;tails&lt;/strong&gt; invocation then where possible, e.g. &lt;code&gt;tails -f /var/log/httpd/error.log | grep &#039;:error&#039;&lt;/code&gt; to watch for PHP errors and the like.&lt;/p&gt;

&lt;h3&gt;Mended corner cases: inconsistent tail behaviour&lt;/h3&gt;

&lt;p&gt;A first version of the script didn&#039;t use a loop but just had&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;tail&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;$@&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;|&lt;/span&gt; expand &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;|&lt;/span&gt; &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;cut&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-c1-&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;${MYCOL:-80}&lt;/span&gt;﻿&lt;/div&gt;

&lt;p&gt;This would break &lt;code&gt;tails -f&lt;/code&gt; on Debian (coreutils 8.23) / Ubuntu (coreutils 8.26) while removing the &lt;code&gt;|expand&lt;/code&gt; would make it work. On Fedora 25 (coreutils 8.25) I couldn&#039;t get &lt;code&gt;tails -f&lt;/code&gt; to work at all with that v1. The &lt;code&gt;cut&lt;/code&gt; (so just a single command chained) already broke the pipe &lt;img src=&quot;http://daniel-lange.com/plugins/serendipity_event_emoticate/img/emoticons/sad.png&quot; alt=&quot;:-(&quot; class=&quot;emoticon&quot; /&gt;. And nope, &lt;code&gt;stdbuf&lt;/code&gt; didn&#039;t help.&lt;/p&gt;

&lt;p&gt;If you have a more simple solution to work around the isatty / isfifo mess, please leave a comment!&lt;/p&gt;

&lt;h3&gt;Alternatives&lt;/h3&gt;

&lt;p&gt;If you want to show multiple log tails in parallel, highlight strings etc. &lt;a href=&quot;https://www.vanheusden.com/multitail/&quot;&gt;multitail&lt;/a&gt; is worth a look.&lt;/p&gt;

&lt;p&gt;Depending on what you want to achieve you could also tell your terminal emulator to not wrap lines:&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;setterm&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-linewrap&lt;/span&gt; off; &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;less&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-SR&lt;/span&gt; +F &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;var&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;log&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;apache&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;access.log; &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;setterm&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-linewrap&lt;/span&gt; on&lt;/div&gt;
 
    </content:encoded>

    <pubDate>Wed, 12 Jul 2017 08:08:00 +0000</pubDate>
    <guid isPermaLink="false">http://daniel-lange.com/archives/134-guid.html</guid>
    <category>bash</category>
<category>coreutils</category>
<category>gnu</category>
<category>script</category>
<category>tail</category>
<category>terminal</category>

</item>
<item>
    <title>Fix Umlauts in the XFCE Terminal</title>
    <link>http://daniel-lange.com/archives/44-Fix-Umlauts-in-the-XFCE-Terminal.html</link>
            <category>IT</category>
    
    <comments>http://daniel-lange.com/archives/44-Fix-Umlauts-in-the-XFCE-Terminal.html#comments</comments>
    <wfw:comment>http://daniel-lange.com/wfwcomment.php?cid=44</wfw:comment>

    <slash:comments>7</slash:comments>
    <wfw:commentRss>http://daniel-lange.com/rss.php?version=2.0&amp;type=comments&amp;cid=44</wfw:commentRss>
    

    <author>nospam@example.com (Daniel Lange)</author>
    <content:encoded>
    &lt;p&gt;The XFCE Terminal has the weird issue of sometimes showing question marks (?) instead of German Umlauts (äöüÄÖÜ) although they work fine in any other stock XFCE application (e.g. the default editor &quot;mousepad&quot;).&lt;/p&gt;

&lt;p&gt;The solution to this can be found on the &lt;a href=&quot;http://forum.xfce.org/index.php?topic=3302.0&quot; title=&quot;XFCE Forum thread on Umlauts in Terminal&quot;&gt;XFCE Forums&lt;/a&gt; but it took me quite some time to find it. It was difficult to find a suitable search query to dig out that page. Google turns up a lot of irrelevant stuff on &quot;XFCE Terminal question marks&quot;...&lt;/p&gt;

&lt;div class=&quot;serendipity_imageComment_center&quot; style=&quot;width: 526px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;!-- s9ymdb:525 --&gt;&lt;img class=&quot;serendipity_image_center&quot; width=&quot;526&quot; height=&quot;283&quot;  src=&quot;http://daniel-lange.com/uploads/entries/090430_XFCE_terminal.png&quot; alt=&quot;&quot; /&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;XFCE Editor Umlauts with and without LANG variable set&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The problem with Umlauts (and other 8bit ASCII characters) showing as question marks arises if the user has no LANG variable set.&lt;/p&gt;

&lt;p&gt;A simple&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;export&lt;/span&gt; &lt;span style=&quot;color: #007800;&quot;&gt;LANG&lt;/span&gt;=en_US&lt;/div&gt;

&lt;p&gt;resolves the issue. Put that into &lt;em&gt;~/.bashrc&lt;/em&gt; or any other place suitable in your distribution.&lt;/p&gt;

&lt;p&gt;Gentoo users may want to&lt;/p&gt;

&lt;div class=&quot;bash geshi&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;su&lt;/span&gt; &amp;#160;&lt;span style=&quot;color: #666666; font-style: italic;&quot;&gt;# become root&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;LANG=en_US&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;etc&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;env.d&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;02locale&lt;br /&gt;env-update&lt;br /&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;exit&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;source&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;etc&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;profile&lt;/div&gt;

&lt;p&gt;to set the LANG variable system-wide.&lt;/p&gt;

&lt;p&gt;So keywords, dear Google: &lt;em&gt;Umlaute, deutsch, Fragezeichen, kaputt, falsch, broken, display, zeigt, charset, Zeichensatz&lt;/em&gt; &lt;img src=&quot;http://daniel-lange.com/plugins/serendipity_event_emoticate/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; class=&quot;emoticon&quot; /&gt;&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Fri, 01 May 2009 21:20:00 +0000</pubDate>
    <guid isPermaLink="false">http://daniel-lange.com/archives/44-guid.html</guid>
    <category>bug</category>
<category>charset</category>
<category>gentoo</category>
<category>terminal</category>
<category>umlauts</category>
<category>xfce</category>

</item>

</channel>
</rss>
