Skip to content

Instantly share code, notes, and snippets.

@jerowe
Last active June 20, 2016 23:18
Show Gist options
  • Save jerowe/11393370 to your computer and use it in GitHub Desktop.
Save jerowe/11393370 to your computer and use it in GitHub Desktop.
Perl Catalyst Develop with Tmux

Tmux and Catalyst

Install Tmux

sudo apt-get install tmux or sudo yjm install tmux

Tmux has some weird bugs on centos. Need to install some libraries from source.

https://gist.github.com/ekiara/11023782

Here is a tmux cheat sheet: http://www.dayid.org/os/notes/tm.html

Create a ~/.tmux.conf file

These options move the bind key from Ctrl-b to Ctrl-a

#Tmux config

set-option -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix
set-window-option -g mode-keys vi
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
set -g mode-mouse on
set -g mouse-select-pane on
set -g mouse-resize-pane on

#Copy and paste tmux
#http://stackoverflow.com/questions/11042920/how-to-copy-and-paste-between-different-tmux-panes-running-vim-instances
#So you can use prefix-<C-y> to activate copy mode, /search term as an example to go where you want,
#v to visually select, y to yank into tmux. 
#Then go to other vim session and get into insert mode.
#Use prefix-p to paste what's in the tmux paste buffer. There are also ways to copy tmux's paste buffer to your system clipboard.
setw -g mode-keys vi
unbind [
unbind p
bind C-y copy-mode
bind p paste-buffer
bind -t vi-copy v begin-selection
bind -t vi-copy y copy-selection
bind -t vi-copy Escape cancel

# highlight active window
set-window-option -g window-status-current-bg colour166
set-window-option -g window-status-current-fg colour15
set-window-option -g window-status-current-attr bold
set-window-option -g window-status-current-format ' #I #W '

# tmux window titling for X
set-option -g set-titles on
#set-option -g set-titles-string '[#I] #W'
set-window-option -g automatic-rename on
#set-window-option -g window-status-format ' #I #W '
set-window-option -g window-status-attr bold
# starts windows at 1 not 0
set-option -g base-index 1

#set -g set-titles off

Manage windows and sessions with Tmuxifier

Tmuxifier is a shell script. No yaml, so it may not have the same level of nesting windows, but it doesn't require ruby.

git clone https://github.com/jimeh/tmuxifier.git ~/.tmuxifier echo "export PATH="$HOME/.tmuxifier/bin:$PATH" " >> ~/.bashrc source ~/.bashrc

Example script

FYI, I name my root directories MyApp/root/myapp/{static,src} - if yours aren't like this you will need to change the script.

#!/bin/bash

#------------------------------------------
# ~/.tmuxifier/layouts/myapp.session.sh
# Run with tmuxifier load-session myapp
#------------------------------------------

PROJECTDIR="/var/www"
PROJECT="MyApp"
SCRIPT=$(echo $PROJECT | sed 's/.*/\L&/')
PORT=3000

#session_root "$PROJECTDIR"
session_root $HOME

if initialize_session "$SCRIPT" ; then

    window_root "$PROJECTDIR"

    new_window "top"
    run_cmd "cd $PROJECTDIR/$PROJECT && git status"

    new_window "lib"
    run_cmd "cd $PROJECTDIR/$PROJECT/lib"

    new_window "moose"
    run_cmd "cd $PROJECTDIR/$PROJECT/lib/$PROJECT"

    new_window "con"
    run_cmd "cd $PROJECTDIR/$PROJECT/lib/$PROJECT/Controller"
    split_h 60
    run_cmd "$PROJECTDIR/$PROJECT/script/$SCRIPT""_server.pl -r -p $PORT" 
    select_pane 0

    new_window "views"
    run_cmd "cd $PROJECTDIR/$PROJECT/root/$SCRIPT/src"
    
    new_window "static"
    run_cmd "cd $PROJECTDIR/$PROJECT/root/$SCRIPT/static"

    #Select the default active window on session creation.
    select_window 1

fi

# Finalize session creation and switch/attach to it.
finalize_and_go_to_session
                                       

Acknowledgements

This module was originally developed at and for Weill Cornell Medical College in Qatar within ITS Advanced Computing Team. With approval from WCMC-Q, this information was generalized and put on github, for which the authors would like to express their gratitude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment