Use External Editor for ZSH

ZSH has a built-in function called edit-command-line which allows you to edit the current command with an external editor (defined by the environment variable $EDITOR). To enable this feature, add the following to your ZSH startup scripts:

1
2
3
4
autoload edit-command-line
zle -N edit-command-line
bindkey '^Xe' edit-command-line

For the interested, this article lists some useful keyboard shortcuts in ZSH.

Gist Extras in Habari

Gist Extras embeds gists in post content, and allows for the use of custom CSS.

Unfortunately, the author has not updated the plug-in for Habari 0.7 - where plug-in information now resides in a separate XML file. To address this, make the following changes to gistextras.plugin.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
*** user/plugins/gistextras/gistextras.plugin.php.orig 2010-06-26 22:11:59.777117173 +0800
--- user/plugins/gistextras/gistextras.plugin.php 2010-06-26 22:11:32.328366681 +0800
***************
*** 2,20 ****
class GistExtras extends Plugin
{
- public function info()
- {
- return array(
- 'url' => 'http://andrewhutchings.com',
- 'name' => 'Gist Extras',
- 'description' => 'Embeds gists in post content, and allows for the use of custom CSS.',
- 'license' => 'Apache License 2.0',
- 'author' => 'Andrew Hutchings',
- 'authorurl' => 'http://andrewhutchings.com',
- 'version' => '0.0.2'
- );
- }
-
public function action_update_check()
{
Update::add( 'GistExtras', 'A6A9D42C-2F4F-11DE-BB63-026155D89593', $this->info->version );
--- 2,7 ----

You’ll also need to create gistextras.plugin.xml:

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="utf-8" ?>
<pluggable type="plugin">
<name>Gist Extras</name>
<license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license>
<url>http://andrewhutchings.com</url>
<author url="http://andrewhutchings.com">Andrew Hutchings</author>
<version>0.0.2</version>
<description><![CDATA[Embeds gists in post content, and allows for the use of custom CSS.]]></description>
<copyright>2009</copyright>
</pluggable>

Print to Clipboard in Putty

From Diomidis Spinellis - Puttyclip, Putty can be patched to use the clipboard as a printer device:

A tiny shell script, winclip, can utilize this capability to allow remote (e.g. Unix) programs to pipe their output to the local Windows clipboard, or to copy remote files to the Windows clipboard.

While left-mouse-button-select, and middle-mouse-button-paste (or shift-insert) interact with Windows’ clipboard in much the same way, this patch allows you to pipe remote command output directly to the local clipboard.

While the original patch was authored for an outdated version of Putty, there has since been another to address newer versions.

You can easily patch and build Putty from source - Putty’s build requirements in Windows (as detailed in the [README](http://svn.tartarus.org/sgt/putty/README?revision=8609&view=markup) file) are minimal.

The patch can be viewed here, and can be downloaded from here.

Extending the Habari Sidebar

Habari’s sidebar (in K2) is very minimal. The following plug-ins provide much needed site-navigation:

Fluffytag shows a fluffy cloud of tags.
monthly_archives shows archives grouped by month.

To display output from both plug-ins, make the following changes to sidebar.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
*** system/themes/k2/sidebar.php 2010-06-21 22:15:10.587118909 +0800
--- user/themes/k2/sidebar.php 2010-06-26 14:52:35.928366633 +0800
***************
*** 13,18 ****
--- 13,28 ----
<?php $theme->area( 'sidebar' ); ?>
+ <div class="sb-archives">
+ <h2><?php _e('Archives'); ?></h2>
+ <?php $theme->monthly_archives ( '0','N' ); ?>
+ </div>
+
+ <div class="sb-tags">
+ <h2><?php _e('Tags'); ?></h2>
+ <?php $theme->fluffytag(); ?>
+ </div>
+
<div class="sb-user">
<h2><?php _e('User'); ?></h2>
<?php $theme->display ( 'loginform' ); ?>

Fluffytag’s appearance was slightly modified with the following changes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Index: fluffytag.css
===================================================================
--- fluffytag.css (revision 3226)
+++ fluffytag.css (working copy)
@@ -7,11 +7,10 @@
#fluffytag li a {
margin: 0px;
line-height: 34px;
- color: #000;
+ color: #CCCCCC;
}
#fluffytag li a:hover {
- background: #000;
- color: #fff;
+ color: #444444;
}
#fluffytag .step-1 a {
font-size: 1.0em;
@@ -42,4 +41,4 @@
}
#fluffytag .step-10 a {
font-size: 2.8em;
-}
\ No newline at end of file
+}

Code in Habari

Using <code>, I can post short code snippets without relying on Github. e.g,

// my first program in C++
#include 
using namespace std;
int main ()
{
  cout << "Hello World!";
  return 0;
}

Habari has two plug-ins that cater especially to code snippets:

google-code-prettify allows syntax highlighting of source code snippets.

code_escape runs htmlspecialchars() on any code blocks in your post.

Whilst in user/plugins, fetch both plug-ins from their subversion repositories:

$ svn checkout http://svn.habariproject.org/habari-extras/plugins/google-code-prettify/trunk google-code-prettify $ svn checkout http://svn.habariproject.org/habari-extras/plugins/code_escape/trunk code_escape

Make the following changes to plugins/code_escape/code_escape.plugin.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Index: code_escape.plugin.php
===================================================================
--- code_escape.plugin.php (revision 3226)
+++ code_escape.plugin.php (working copy)
@@ -4,7 +4,7 @@
public function filter_post_content_out ( $content, $post ) {
- $content = preg_replace_callback('/<code>(.*?)<\/code>/s', array( 'self', 'escape_code' ), $content);
+ $content = preg_replace_callback('/<code class="prettyprint">(.*?)&lt;\/code&gt;/s', array( 'self', 'escape_code' ), $content);
return $content;
@@ -16,7 +16,7 @@
$string = htmlspecialchars( $string );
- $string = '&lt;code&gt;' . $string . '</code>';
+ $string = '<code class="prettyprint">' . $string . '</code>';
return $string;
@@ -30,4 +30,4 @@
}
-?>
\ No newline at end of file
+?>

Filter Habari Pages by Tags

Habari’s pages, while taggable, aren’t filtered; Habari’s content filters only apply to entries. This can be easily addressed by modifying the theme - for example, with K2, make the following changes to themes/k2/theme.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
*** system/themes/k2/theme.php 2010-06-21 22:15:10.587118909 +0800
--- user/themes/k2/theme.php 2010-06-23 20:00:35.488368879 +0800
***************
*** 46,51 ****
--- 46,70 ----
* template. So the values here, unless checked, will overwrite any existing
* values.
*/
+
+ /**
+ * Filter the parameters being passed to Posts::get()
+ *
+ * @param array $filters The parameters to be passed to Posts::get()
+ *
+ * @return array The updated parameters
+ */
+ public function filter_template_where_filters( $filters )
+ {
+
+ if( isset( $filters['content_type'] ) ) {
+ $types = Utils::single_array( $filters->offsetGet( 'content_type' ) );
+ $types[] = Post::type( 'page' );
+ $filters->offsetSet( 'content_type', $types );
+ }
+ return $filters;
+ }
+
public function add_template_vars()
{
//Theme Options

Upgrade to Habari Trunk

To upgrade Habari to the latest development snapshot, read this. Be mindful of the format changes mentioned in Upgrade Notes here.

Move your existing set of plug-ins (at user/plugins/) to user/plugins_prev/ for safe-keeping.

Issue the following command from a MySQL shell to deactivate all active plug-ins:

mysql> DELETE from habari__options WHERE name = "active_plugins";

To update the plug-ins, you will need to search Habari’s plug-ins index for replacement versions 0.7.x.y or trunk.

Smoother Fonts in Debian

To display smoother fonts on an LCD in Debian, as root:

# dpkg-reconfigure fontconfig-config

In the dialog windows that follow, have:

1
2
3
4
Font tuning method for screen: Autohinter
Enable subpixel rendering for screen: Automatic
Enable bitmapped fonts by default? No

Gravatar in Habari

Gravatar adds a comment author’s Gravatar by adding <img src="gravatar ?>"> to the relevant file(s) in your theme.

For the K2 theme, make the following changes to themes/k2/comments.php:

1
2
3
4
5
6
7
8
9
10
11
*** system/themes/k2/comments.php 2010-06-21 22:15:10.587118909 +0800
--- user/themes/k2/comments.php 2010-06-21 23:20:23.068368014 +0800
***************
*** 22,27 ****
--- 22,28 ----
?>
<li id="comment-<?php echo $comment->id; ?>" <?php echo $theme->k2_comment_class( $comment, $post ); ?>>
<a href="#comment-<?php echo $comment->id; ?>" class="counter" title="<?php _e('Permanent Link to this Comment'); ?>"><?php echo $comment->id; ?></a>
+ <img src="<? echo $comment->gravatar ?>">
<span class="commentauthor"><?php echo $comment_url; ?></span>
<small class="comment-meta"><a href="#comment-<?php echo $comment->id; ?>" title="<?php _e('Time of this Comment'); ?>"><?php $comment->date->out(); ?></a><?php if ( $comment->status == Comment::STATUS_UNAPPROVED ) : ?> <em><?php _e('In moderation'); ?></em><?php endif; ?></small>