<?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>Defective Semantics</title>
	<atom:link href="http://scarff.id.au/feed/" rel="self" type="application/rss+xml" />
	<link>http://scarff.id.au</link>
	<description>Dean Scarff's perpetual struggle with technology, and other anecdotes</description>
	<lastBuildDate>Thu, 03 Nov 2011 22:39:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Window titles in screen and urxvt, from vim</title>
		<link>http://scarff.id.au/blog/2011/window-titles-in-screen-and-urxvt-from-vim/</link>
		<comments>http://scarff.id.au/blog/2011/window-titles-in-screen-and-urxvt-from-vim/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 18:14:14 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Programs]]></category>
		<category><![CDATA[rxvt]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=557</guid>
		<description><![CDATA[<p>I previously posted about generating title escapes for screen and rxvt-unicode from zsh. I&#8217;ve since worked on getting a consistent title from vim, too.  It&#8217;s become complex enough that I&#8217;m spinning it out into a new post.</p>
<p>To set both titles from vim, use its termcap-title options to push the title to screen using the iconstring.  When not running under screen, the right titlestring escapes will be inferred from terminfo.</p>
<pre class="codeblock vimscript">
set title
auto BufEnter * let &#38;titlestring = s:MyTitle()

if &#38;term =~ 'screen\(\.\(xterm\&#124;rxvt\)\(-\(256\)\?color\)\?\)\?'
  " Set the screen title using the vim "iconstring"."
  set t_IS=<u>^[</u>k
  set t_IE=<u>^[</u>\
  set icon
  auto BufEnter * let &#38;iconstring = &#38;titlestring
  " Set the xterm title using the vim "titlestring"."
  set t_ts=<u>^[</u>]2;
  set t_fs=<u>^G</u>
endif
</pre>
<p>where the underlined characters are actual escapes input with ^V, not with literal carets.</p>
<p>As for generating a fancy title string like vim: there are some gotchas.&#8230; <a href="http://scarff.id.au/blog/2011/window-titles-in-screen-and-urxvt-from-vim/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>I previously posted about <a href="/blog/2011/window-titles-in-screen-and-rxvt-from-zsh/">generating title escapes</a> for screen and rxvt-unicode from zsh. I&#8217;ve since worked on getting a consistent title from vim, too.  It&#8217;s become complex enough that I&#8217;m spinning it out into a new post.</p>
<p>To set both titles from vim, use its <a href="http://vimdoc.sourceforge.net/htmldoc/term.html#termcap-title">termcap-title</a> options to push the title to screen using the iconstring.  When not running under screen, the right titlestring escapes will be inferred from terminfo.</p>
<pre class="codeblock vimscript">
set title
auto BufEnter * let &amp;titlestring = s:MyTitle()

if &amp;term =~ 'screen\(\.\(xterm\|rxvt\)\(-\(256\)\?color\)\?\)\?'
  " Set the screen title using the vim "iconstring"."
  set t_IS=<u>^[</u>k
  set t_IE=<u>^[</u>\
  set icon
  auto BufEnter * let &amp;iconstring = &amp;titlestring
  " Set the xterm title using the vim "titlestring"."
  set t_ts=<u>^[</u>]2;
  set t_fs=<u>^G</u>
endif
</pre>
<p>where the underlined characters are actual escapes input with ^V, not with literal carets.</p>
<p>As for generating a fancy title string like vim: there are some gotchas.  The biggest is that vim does not preserve logical directory names, so <code>getcwd()</code> will resolve symlinks, leading to a different location string than generated by zsh&#8217;s <q>%~</q>.  Rather than call <code>pwd -L</code>, we might as well unify the expansion syntax and call zsh.  Of course, it&#8217;s nice to have a fallback, too:</p>
<p><span id="more-557"></span></p>
<pre class="codeblock">
" Perform zsh-like prompt expansion using the template {prompt}.  See
" "EXPANSION OF PROMPT SEQUENCES" in zshmisc(1).
function s:ZshPromptExpn(prompt)
  if &amp;shell == "/bin/zsh"
    return system("print -Pn " . shellescape(a:prompt))
  else
    " Fallback to poor man's prompt expansion.
    " By no means equivalent to zsh.
    let idx = 0
    let result = ''
    let escapere = '%\([%)m]\|\(\(-\?[0-9]\+\)\?[~]\)\)'
    while idx &lt; len(a:prompt)
      let nextesc = match(a:prompt, escapere, idx)
      if nextesc &lt; 0
        let result .= a:prompt[idx :]
        break
      elseif idx &lt; nextesc
        let result .= a:prompt[idx : (nextesc - 1)]
      endif

      let idx = matchend(a:prompt, escapere, nextesc)
      let esc = a:prompt[nextesc : (idx - 1)]
      if esc == '%m'
        let result .= substitute(hostname(), '^\([^.]*\).*', '\1', '')
      elseif esc =~ '%-\?[0-9]*[~]'
        let result .= fnamemodify(getcwd(), ':~')[:-2]
      elseif esc == '%%'
        let result .= '%'
      endif
    endwhile
    return result
endfunction

function s:MyTitle()
  return s:ZshPromptExpn("%m:%-3~ ") .
  \ v:progname . " " . fnamemodify(expand("%:f"), ":.")
endfunction
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2011/window-titles-in-screen-and-urxvt-from-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disabling hyphen substitution in Adium</title>
		<link>http://scarff.id.au/blog/2011/disabling-hyphen-substitution-in-adium/</link>
		<comments>http://scarff.id.au/blog/2011/disabling-hyphen-substitution-in-adium/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 17:06:34 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[adium]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=542</guid>
		<description><![CDATA[<p>By default Adium replaces two hyphens with an em-dash in text you type or paste.  This leads to subtly confusing behaviour when pasting commands:</p>
<pre class="codeblock sh">
foo --bar
</pre>
<p>becomes &#8220;foo —bar&#8221;, which can look very similar to <code>foo --bar</code> if your contact is using a terminal that supports variable-width glyphs for exotic character points.</p>
<p>It&#8217;s a quick fix: stop double-hyphens being transformed to a long dash by right clicking the Adium input field, and unticking Substitutions > Smart Dashes from the menu.</p>
]]></description>
			<content:encoded><![CDATA[<p>By default Adium replaces two hyphens with an em-dash in text you type or paste.  This leads to subtly confusing behaviour when pasting commands:</p>
<pre class="codeblock sh">
foo --bar
</pre>
<p>becomes &#8220;foo —bar&#8221;, which can look very similar to <code>foo --bar</code> if your contact is using a terminal that supports variable-width glyphs for exotic character points.</p>
<p>It&#8217;s a quick fix: stop double-hyphens being transformed to a long dash by right clicking the Adium input field, and unticking Substitutions > Smart Dashes from the menu.</p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2011/disabling-hyphen-substitution-in-adium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>window titles in screen and rxvt, from zsh</title>
		<link>http://scarff.id.au/blog/2011/window-titles-in-screen-and-rxvt-from-zsh/</link>
		<comments>http://scarff.id.au/blog/2011/window-titles-in-screen-and-rxvt-from-zsh/#comments</comments>
		<pubDate>Tue, 17 May 2011 14:47:58 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=534</guid>
		<description><![CDATA[<p>Recently I&#8217;ve been multiplexing work over many urxvt terminals: essential when you&#8217;re monitoring the logging output of several related binaries and managing several git branches related to each.  The sensibilities of awesome have eased the window management, but I&#8217;ve become increasingly reliant on the window title to identify particular sessions.  This is compounded one level further when I&#8217;m using screen; I want a useful identifier to show up in screen&#8217;s windowlist.</p>
<p>Getting nice prompts is a common need and there is plenty of information out there on setting your PS1, but for various reasons I&#8217;ve had problems finding a &#8216;nice&#8217; setup that&#8217;s just worked exactly the way I&#8217;ve wanted it to with titles.  Here are the pertinent parts of my working configuration:</p>
<ul>
<li>I get the working directory and current command in the title</li>
<li>I get the title in the screen windowlist if running in screen</li>
<li>I get the same</li></ul><p>&#8230; <a href="http://scarff.id.au/blog/2011/window-titles-in-screen-and-rxvt-from-zsh/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been multiplexing work over many urxvt terminals: essential when you&#8217;re monitoring the logging output of several related binaries and managing several git branches related to each.  The sensibilities of <a href="http://awesome.naquadah.org/">awesome</a> have eased the window management, but I&#8217;ve become increasingly reliant on the <a href="http://tronche.com/gui/x/icccm/sec-4.html#WM_NAME">window title</a> to identify particular sessions.  This is compounded one level further when I&#8217;m using screen; I want a useful identifier to show up in screen&#8217;s windowlist.</p>
<p>Getting nice prompts is a common need and there is plenty of information out there on setting your PS1, but for various reasons I&#8217;ve had problems finding a &#8216;nice&#8217; setup that&#8217;s just worked exactly the way I&#8217;ve wanted it to with titles.  Here are the pertinent parts of my working configuration:</p>
<ul>
<li>I get the working directory and current command in the title</li>
<li>I get the title in the screen windowlist if running in screen</li>
<li>I get the same title in the WM_NAME of an rxvt or xterm, or the titlebar of an iTerm2, whether or not screen is involved</li>
</ul>
<p><span id="more-534"></span><br />
Here&#8217;s how I set my PS1 in .zshrc:</p>
<pre class="codeblock sh">
case "$TERM" in
  # [skipping some esoteric terminal emulators...]

  screen|screen.rxvt)
     # Set a coloured prompt
     PS1=$'%{\e[00;32m%}%*%{\e[00;34m%}%2~ %# %{\e[00m%}'
     ;;
  rxvt|rxvt-unicode|xterm|xterm-color)
     # Set the title, and a coloured prompt containing some useful info
     PS1=$'%{\e]0;%-3~\a\e\[00;32m%}%*%{\e[00;30m%}!%! %{\e[00;34m%}%2~ %# %{\e[0m%}'
     ;;
esac
</pre>
<p>I want an abbreviated form of the full command line so that it will fit in awesome's tasklist.  I set the titles before a command is run in zsh's <a href="http://zsh.sourceforge.net/Doc/Release/Functions.html#index-preexec">preexec</a> hook.  The screen window title and the xterm title are set with two different escapes.</p>
<pre class="codeblock sh">
function preexec() {
  local a=${${1## *}[(w)1]}  # get the command
  local b=${a##*\/}   # get the command basename
  a="${b}${1#$a}"     # add back the parameters
  a=${a//\%/\%\%}     # escape print specials
  a=$(print -Pn "$a" | tr -d "\t\n\v\f\r")  # remove fancy whitespace
  a=${(V)a//\%/\%\%}  # escape non-visibles and print specials

  case "$TERM" in
    screen|screen.*)
      # See screen(1) "TITLES (naming windows)".
      # "\ek" and "\e\" are the delimiters for screen(1) window titles
      print -Pn "\ek%-3~ $a\e\\" # set screen title.  Fix vim: ".
      print -Pn "\e]2;%-3~ $a\a" # set xterm title, via screen "Operating System Command"
      ;;
    rxvt|rxvt-unicode|xterm|xterm-color|xterm-256color)
      print -Pn "\e]2;%m:%-3~ $a\a"
      ;;
  esac
}
</pre>
<p>This requires the title to be reset for screen (since it&#8217;s not reset by PS1), using zsh&#8217;s <a href="http://zsh.sourceforge.net/Doc/Release/Functions.html#index-precmd">precmd hook</a>:</p>
<pre class="codeblock sh">
function precmd() {
  case "$TERM" in
    screen|screen.rxvt)
      print -Pn "\ek%-3~\e\\" # set screen title
      print -Pn "\e]2;%-3~\a" # must (re)set xterm title
      ;;
  esac
}
</pre>
<p>The beauty of this method (unlike methods that bind screen&#8217;s <a href="http://www.gnu.org/software/termutils/manual/termcap-1.3/html_node/termcap_41.html">status line</a> escapes to xterm Operating System Command escapes) is that no termcapinfo hacks in .screenrc are necessary.</p>
<p><small class="postscript">Update: changed preexec to use zsh subscripting rather than splitting by IFS.  Fixes duplication of 0-argument commands, e.g. &#8220;top top&#8221;.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2011/window-titles-in-screen-and-rxvt-from-zsh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RFC 3825 Geolocation configuration generator tool</title>
		<link>http://scarff.id.au/blog/2010/rfc-3825-geolocation-configuration-generator-tool/</link>
		<comments>http://scarff.id.au/blog/2010/rfc-3825-geolocation-configuration-generator-tool/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 08:15:53 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Programs]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=510</guid>
		<description><![CDATA[<p>While mobile devices (especially those with a GPS) have made people more aware of geolocation/geotagging, you don&#8217;t need a GPS in a device to make it location-aware, nor do you need to resort to IP-based reverse lookups.  Location information can be made available on any network that has a DHCP server using the Location Configuration Information DHCP Option defined in RFC 3825.  It makes sense: for most wired or wireless networks, the engineer responsible for setting up the DHCP server will know at the least where the server or AP is located, and maybe even static information about the locations of each terminal of a wired port.</p>
<p>The Option has a somewhat unorthodox binary format with non-power-of-2-width fixed point reals.  To make generating the DHCP configuration statements easier, I developed a web-based RFC 3825 location configuration generation tool.  It&#8217;s all client-side and even has a Google Maps preview of the&#8230; <a href="http://scarff.id.au/blog/2010/rfc-3825-geolocation-configuration-generator-tool/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>While mobile devices (especially those with a GPS) have made people more aware of geolocation/geotagging, you don&#8217;t need a GPS in a device to make it location-aware, nor do you need to resort to IP-based reverse lookups.  Location information can be made available on any network that has a DHCP server using the <a href="http://tools.ietf.org/html/rfc3825">Location Configuration Information DHCP Option</a> defined in RFC 3825.  It makes sense: for most wired or wireless networks, the engineer responsible for setting up the DHCP server will know at the least where the server or AP is located, and maybe even static information about the locations of each terminal of a wired port.</p>
<p>The Option has a somewhat unorthodox binary format with non-power-of-2-width fixed point reals.  To make generating the DHCP configuration statements easier, I developed a web-based <a href="/tools/rfc-3825-location-configuration.html">RFC 3825 location configuration generation tool</a>.  It&#8217;s all client-side and even has a Google Maps preview of the location!</p>
<p>Copy the configuration to your local DHCP server, grab an appropriate <a href="http://igtk.sourceforge.net/">geolocation library</a>, and you&#8217;re ready to go!  The tool generates a DHCP LCI Option for both dnsmasq and ISC&#8217;s dhcpd.</p>
<p>The lack of fixed point integers in Javascript made the implementation a little trickier than it would have been in, say, C.</p>
<p>Other lessons: Google Maps is <a href="http://freegeographytools.com/2007/positional-accuracy-in-google-maps-my-maps-vs-google-earth">not highly accurate</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2010/rfc-3825-geolocation-configuration-generator-tool/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
