ft's z-shell setup

This page used to be the home of my zsh setup. I've since moved all the code to a git repository at dev.0x50.de: zsh setup

Now, I'm using this page to outline a few of the things in my setup, that might be of use for other people, as well.

zsh integration: tmux

I am using sessions in tmux obsessively.

Every job gets its session. Hack on a project? New session. Write on a paper? New session. Hack on another project? New session. That makes everything really tidy. I love it. Never going back to my old habits again. But with that, you'll need a way to create new or attach to old session very easily. Also, I want a session to have its default path for new programs to be somewhere that's not my home directory. And while I know that tmux 1.6 can create new windows in the same directory as the current window, I'd very much like to remain in control - so, that's not for me.

tmux attach or create session

If you want to switch a tmux client from session to session, that's easily done from within tmux. No problem. If you want a new session in a new terminal, then that's still pretty simple. If you want a little more convenience, you need a way to look if a session already exists and if so attach to it and only create a new one otherwise. That's what my `ta' function is for. Its usage description looks like this:

usage: ta [OPTION(s)] <session-name>

`session-name' may be an existing or a new session name. If it is an
existing session's name, the session is attached to; otherwise, a new
session is registered with tmux and then attached to.

Options:
  -d    When attaching to an existing session, pass the `-d' option
        to tmux, which will detach any other clients attached to the
        session.
  -x    Do *not* call "tmux attach" using `exec', but without. So,
        when present and the tmux session is detached from again,
        control will be picked up by the (still existing) parent shell
        again.

Use tab completion to complete option characters and names of exiting
sessions.

Oh yeah, it comes with support for zsh's completion. And that looks something like this (depending on your compsys setup you'll be able to choose sessions using cursor keys):

ta completion

The function itself and the completion each live in a file that holds their code. If you're unfamiliar with that concept, take a look at zsh function files over at the zshwiki.

Basically, you're adding a directory to zsh's function-search-path and add files to it, which you'd then mark for autoloading. Say `~/.zfunctions'. And you'd drop both files (ta and _ta) into that directory. The code for that would then be:

fpath=( ~/.zfunctions "${fpath[@]}" )
autoload -Uz ta

Make sure that this is done before you're calling `compinit' to initialise zsh's completion system.

Finally, here are the links to the functions:

Changing tmux's `default-path' option on the fly

The second thing you'd like to automate with many sessions is the tmux's `default-path' option. That way, you get the feel of a session "living" in a directory. For that I hacked up another function: cdm

The idea is to use it as the first `cd' after a new session was created. Say there is a session called "grmldev" and you'd like it to "live" in `~/src/grml'. A new session (obviously created using `ta' - see above) will drop you into your home directory, so the whole command trail would look like this:

% ta grmldev
% cdm src/grml

And that's it. Tmux will now set the initial path for new commands (including new shells) to that directory. Fun!