The git repo behind my blog.

local-notifications-for-weechat-and-urxvt.html 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <link href='https://phyks.me/theme/stylesheet/fonts.css' rel='stylesheet' type='text/css'>
  5. <link rel="stylesheet" type="text/css" href="https://phyks.me/theme/stylesheet/style.min.css">
  6. <link rel="stylesheet" type="text/css" href="https://phyks.me/theme/pygments/monokai.min.css">
  7. <link rel="stylesheet" type="text/css" href="https://phyks.me/theme/font-awesome/css/font-awesome.min.css">
  8. <link href="https://phyks.me/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Phyks' blog Atom">
  9. <link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon">
  10. <link rel="icon" href="/images/favicon.ico" type="image/x-icon">
  11. <meta charset="utf-8" />
  12. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  13. <meta name="HandheldFriendly" content="True" />
  14. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  15. <meta name="robots" content="index, follow" />
  16. <!-- Chrome, Firefox OS and Opera -->
  17. <meta name="theme-color" content="#333">
  18. <!-- Windows Phone -->
  19. <meta name="msapplication-navbutton-color" content="#333">
  20. <!-- iOS Safari -->
  21. <meta name="apple-mobile-web-app-capable" content="yes">
  22. <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  23. <!-- Microsoft EDGE -->
  24. <meta name="msapplication-TileColor" content="#333">
  25. <meta name="author" content="Phyks" />
  26. <meta name="description" content="After moving from irssi to weechat, I decided to look for a way to have local notifications for IRC messages. The problem is that I run weechat through a screen on my server, which I access thanks to SSH. Thus, I need to find a way to allow weechat to …" />
  27. <meta name="keywords" content="">
  28. <meta property="og:site_name" content="Phyks' blog"/>
  29. <meta property="og:title" content="Local notifications for Weechat and UrXVT"/>
  30. <meta property="og:description" content="After moving from irssi to weechat, I decided to look for a way to have local notifications for IRC messages. The problem is that I run weechat through a screen on my server, which I access thanks to SSH. Thus, I need to find a way to allow weechat to …"/>
  31. <meta property="og:locale" content="en_US.UTF-8"/>
  32. <meta property="og:url" content="https://phyks.me/2014/02/local-notifications-for-weechat-and-urxvt.html"/>
  33. <meta property="og:type" content="article"/>
  34. <meta property="article:published_time" content="2014-02-20 20:57:00+01:00"/>
  35. <meta property="article:modified_time" content=""/>
  36. <meta property="article:author" content="https://phyks.me/author/phyks.html">
  37. <meta property="article:section" content="ConfigPorn"/>
  38. <meta property="og:image" content="/images/profile.png">
  39. <title>Phyks' blog &ndash; Local notifications for Weechat and UrXVT</title>
  40. </head>
  41. <body>
  42. <aside>
  43. <div>
  44. <a href="https://phyks.me">
  45. <img src="/images/profile.png" alt="Phyks" title="Phyks">
  46. </a>
  47. <h1><a href="https://phyks.me">Phyks</a></h1>
  48. <p>I write about dev, FOSS, DIY and more, in French and English.</p>
  49. <ul class="social">
  50. <li><a class="sc-rss" href="feeds/all.atom.xml" target="_blank"><i class="fa fa-rss"></i></a></li>
  51. <li><a class="sc-envelope-o" href="mailto:phyks+blog@phyks.me" target="_blank"><i class="fa fa-envelope-o"></i></a></li>
  52. <li><a class="sc-github" href="http://github.com/phyks/" target="_blank"><i class="fa fa-github"></i></a></li>
  53. <li><a class="sc-gitlab" href="https://git.phyks.me/phyks" target="_blank"><i class="fa fa-gitlab"></i></a></li>
  54. </ul>
  55. </div>
  56. </aside>
  57. <main>
  58. <nav>
  59. <a href="https://phyks.me">Home</a>
  60. <a href="https://links.phyks.me">Bookmarks</a>
  61. <a href="/pages/hosted-tools.html">Tools</a>
  62. <a href="/archives.html">Archives</a>
  63. <a href="/pages/memo-autohebergement.html">Autohébergement</a>
  64. <a href="https://phyks.me/feeds/all.atom.xml">Atom</a>
  65. </nav>
  66. <article class="single">
  67. <header>
  68. <h1 id="local-notifications-for-weechat-and-urxvt">Local notifications for Weechat and&nbsp;UrXVT</h1>
  69. <p>
  70. Posted on February 20, 2014 in <a href="https://phyks.me/category/configporn.html">ConfigPorn</a>
  71. &#8226; 2 min read
  72. </p>
  73. </header>
  74. <div>
  75. <p>After moving from irssi to weechat, I decided to look for a way to have
  76. local notifications for <span class="caps">IRC</span> messages. The problem is that I run weechat
  77. through a screen on my server, which I access thanks to <span class="caps">SSH</span>. Thus, I
  78. need to find a way to allow weechat to communicate to my local terminal
  79. and send&nbsp;notifications.</p>
  80. <p>I found many solutions on the web which were using a local server or a
  81. pipe file. But these aren&#8217;t fitted to my needs, as they need an external
  82. program running on my machine, which I don&#8217;t want. I was quite sure
  83. there could be a way to do it, with nothing more than my terminal
  84. emulator and weechat plugins, and I finally found it. My solution is
  85. based on
  86. <a href="http://artisan.karma-lab.net/ajouter-notification-a-urxvt">karma-lab</a>&#8216;s
  87. one&nbsp;[French].</p>
  88. <p>The idea is to use the Bell signal which corresponds to the <span class="caps">ASCII</span> escape
  89. sequence 7 to raise attention (beep signal). The following steps work
  90. fine with UrXVT and weechat in a screen session. It may be possible to
  91. adapt this to other terminal emulators or terminal multiplexers (such as
  92. tmux) but I don&#8217;t use them and can&#8217;t help you much with it. We will
  93. define our own escape sequence, that will be interpreted by an UrXVT
  94. plugin and will spawn a notification with the <span class="caps">IRC</span>&nbsp;message.</p>
  95. <p>First of all, you will have to modify your <code>~/.Xdefaults</code>
  96. or your <code>~/.Xresources</code> to tell UrXVT to listen for bell
  97. signals. In order to do so, just add the following&nbsp;line:</p>
  98. <div class="highlight"><pre><span></span>URxvt*urgentOnBell: true
  99. </pre></div>
  100. <p>Then, reload&nbsp;it:</p>
  101. <div class="highlight"><pre><span></span><span class="gp">$</span> xrdb -load ~/.Xdefaults
  102. </pre></div>
  103. <p>Your UrXVT terminal now listens to bell signals. But we&#8217;d like them to
  104. spawn real local notifications. For this, I used libnotify, which is
  105. built-in in gnome. The main idea is to enhance our bell signal with a
  106. more complete escape sequence to include a message to display (using the
  107. so-called osc sequences). Thus, the sequence sent to UrXVT will look
  108. like <code>\[ESC\]777;notify;TITRE;MESSAGEBELL\]</code>. Just add the
  109. following plugin (written by
  110. <a href="http://artisan.karma-lab.net/ajouter-notification-a-urxvt">Karma-lab</a>[French]
  111. and slightly modified by me to enhance security) to your UrXVT and you
  112. are ready to go. So, you should put <a href="https://pub.phyks.me/scripts/urxvt/notify">this
  113. plugin</a> in
  114. <code>/usr/lib/urxvt/perl/notify</code>.</p>
  115. <p>To test that everything worked correctly, you can use the following&nbsp;command:</p>
  116. <div class="highlight"><pre><span></span><span class="gp">$</span> <span class="nb">echo</span> -ne <span class="s2">&quot;\033]777;notify;Moi;Hello World\007\007&quot;</span>
  117. </pre></div>
  118. <p>which should spawn an &#8220;Hello World&#8221; notification on your&nbsp;desktop.</p>
  119. <p>Finally, if the previous example is working fine, let&#8217;s integrate it to
  120. Weechat. We&#8217;ll need another plugin for weechat, to make him write this
  121. escape sequence when needed to send notifications. This plugin is also
  122. from karma-labs, but as my weechat is running in a <code>screen</code>
  123. session, I had to tweak it a bit. I improved security of the plugin as
  124. well, to prevent any unauthorized code execution. Concerning
  125. <code>screen</code>, it is “consuming” the escape sequences for itself,
  126. and you have to tweak it a bit to make it pass through
  127. <code>screen</code>. The python script to load in your Weechat can be
  128. found <a href="https://pub.phyks.me/scripts/weechat/screen_away.py">here</a>.</p>
  129. <p>Have fun with <span class="caps">IRC</span> and your brand new notifications&nbsp;!</p>
  130. </div>
  131. <div class="tag-cloud">
  132. <p>
  133. </p>
  134. </div>
  135. <div class="addthis_relatedposts_inline">
  136. </article>
  137. <footer>
  138. <p>
  139. &copy; 2017 - This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>
  140. </p>
  141. <p>Powered by <a href="http://getpelican.com" target="_blank">Pelican</a> - <a href="https://github.com/alexandrevicenzi/flex" target="_blank">Flex</a> theme by <a href="http://alexandrevicenzi.com" target="_blank">Alexandre Vicenzi</a></p><p>
  142. <a rel="license"
  143. href="http://creativecommons.org/licenses/by-nc-sa/4.0/"
  144. target="_blank">
  145. <img alt="Creative Commons License"
  146. title="Creative Commons License"
  147. style="border-width:0"
  148. src="https://phyks.me/theme/img/cc/by-nc-sa.png"
  149. width="80"
  150. height="15"/>
  151. </a>
  152. </p> </footer>
  153. </main>
  154. <script type="application/ld+json">
  155. {
  156. "@context" : "http://schema.org",
  157. "@type" : "Blog",
  158. "name": " Phyks' blog ",
  159. "url" : "https://phyks.me",
  160. "image": "/images/profile.png",
  161. "description": "I write about dev, FOSS, DIY and more, in French and English."
  162. }
  163. </script>
  164. </body>
  165. </html>