Code and Hacks

Stuff I've stumbled on or figured out... mostly Perl, Linux, Mac and Cygwin.

My Photo
Name:
Location: CA, United States

Perl hacker, investor and entrepreneur.

Monday, April 12, 2010

Setting the Terminal Title in Gnu Screen

I often have multiple terminals open and screen running in each one. I then try to group all my work for a particular project in that terminal. While I am trying to limit the amount of multitasking and concentrate on one thing at a time, I might leave a terminal/screen session up for days and when I come back I can jump right back where I started.

The downside to this is using cmd-tab (or alt-tab with Witch) gives me a list of several terminals each with the title screen - bash - username or maybe screen - vim - username… not very helpful. What I want is to set a name for each terminal and display it in the terminal’s title. If I anticipate this before launching screen, I can accomplish it with screen -t <My Title>. Once I am inside a session though, you need to change each window’s title/name for this to work.

After searching the web and a bunch of trial-and-error, I found a solution. The first part is pretty well documented. Changing the name for all windows and the default for new windows took quite a bit a tinkering.

  1. Setup screen (via .screenrc) to update your terminals title bar and include the name of the current window.

    # Add to .screenrc
    termcapinfo xterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
    defhstatus "screen ^E (^Et) | $USER@^EH"
    hardstatus off

    The escape string ^Et in the defhstatus is converted into the current window’s name/title.

  2. Create a function to update the name of each screen window.

    # Add to .bashrc
    # Set the title of a Terminal window
    function settitle() {
     if [ -n "$STY" ] ; then         # We are in a screen session
      echo "Setting screen titles to $@"
      printf "\033k%s\033\\" "$@"
      screen -X eval "at \\# title $@" "shelltitle $@"
     else
      printf "\033]0;%s\007" "$@"
     fi
    }

    You can change the name of the current window by pressing Ctrl-a A, but we want to change the title for all the windows. screen -X eval will execute each of its arguments in the current screen. The command at \# title will execute the title command in all the windows (the \ before # is required otherwise # will be interpreted as the beginning of a comment). The shelltitle command will ensure that any newly created windows use this title.

Labels:

Friday, April 2, 2010

Open Source Presentation Software

I am thinking about giving a presentation at one of my local Perl Monger meetings. So as usual, I have spent a bunch of time toying with new tools rather than getting work done! Which tools: open source presentation creation software. I wanted something that would take a simple text file and easily create an attractive and easy to use presentation.

Here is a quick summary of the options that I tried or looked into:

  • Vroom::Vroom - This is cool. If you like vim and aren’t hung up on the output format it might be for you. I had some trouble getting the key-bindings to work, but I would guess it was a conflict with another vim plugin.

    Vroom can present right in vim or output to html. Both are pretty plain looking, but I didn’t look into customizing the html output. I love that you can press RR and run the code on the slide. The input is a custom format but it is pretty similar to markdown.

  • Pod::S5 - I really wanted to like this one–it is written in Perl, uses a standard method input format, and it creates an HTML presentation. But I was hung up on a couple of things. While pod is great, it isn’t nearly as easy to use as markdown, and the text slides just aren’t that easy to read. Things like lists just take up too much room:

    =over 4
    
    =item *
    
    A Bullet
    
    =item *
    
    Another Bullet
    
    =back

    That’s just too much vertical whitespace.

    Second, the output is S5 which has been superseded by S6. The templates in S5 didn’t really appeal to me and had some issues in my browser.

  • Spork / Spork::S5 - I had some trouble installing this, but eventually realized I just needed to install Kwiki::Cache first. The default themes are not particularly attractive, but again I didn’t look into customizing the output. I do like that it automatically scales text. The ability to highlight sections of the text/code with underlining or colors sounds very cool. For example, this markup:

    .pretty.
     sub greet {
      print "Hello there\n";
    #             _______________
    #              RRRRR
     }    
    .pretty.

    Should underline and make “Hello there” red. I didn’t test this, but according to the documentation it is “coming soon”.

  • Slide Show (S9) - I ended up settling on Slide Show. While I was biased toward a Perl solution, and this is written in Ruby, it definitely seemed the most mature and robust solution. (Maybe I’ll end up learning a bit of Ruby as a side benefit.)

    Slide show can take either textile or markdown as input, it outputs S5 or S6, and has some nice (and simple) templates bundled. It will use any one of a number of markdown parsers so I am using Maruku which has some nice additions to the core markdown syntax (ie, add a css class declaration to an element).

    Installation was easy (once I googled for one error message):

    gem install slideshow
    gem install ultraviolet
    # got error: oniguruma.h: No such file or directory
    port install oniguruma
    gem install ultraviolet

    Slide show also handles syntax highlighting for your code and can import external files into the presentation.

    # Import a file
    <%= include 'help.txt' %>
    # Highlight and import code
    <% code 'test.pl', :lang => 'perl' %> 
    # Highlight inline code
    <% code :lang => 'perl' do %> 
     my $code = 'is simple';
    <% end %>

    All in all, it seems like it fits the bill.

Summary

I probably missed some very nice alternatives. I know there is spod5 on CPAN, but that seems very similar to Pod::S5. I’m sure there are more. Let me know if I should be trying out your favorite.

One other aspect that I’ve been tinkering with: printing the presentation. I don’t need it for the PM presentation I am working on, but if I were to try to switch from PowerPoint to Slide Share for my day job, I would definitely need a way to create .pdf files.

This seems like an issue that others are running into, but there is no great solution so far. It looks like the trick may be to customize the print.css file. The following should change the page layout and add page breaks:

@page {size: landscape;}  /* only works in Opera? */
.slide {page-break-after: always;}

But we are still missing the nice background and layout. I’ll need to spend some more time on this.

Last note: I stumbled into what may be a nice tool to convert a web page to .pdf from the command line: wkhtmltopdf. It barfed on my S6 presentation, but it printed a few other websites nicely.

Labels: