Skip to content

Instantly share code, notes, and snippets.

@cobrajs
Created March 16, 2013 18:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cobrajs/5177546 to your computer and use it in GitHub Desktop.
Save cobrajs/5177546 to your computer and use it in GitHub Desktop.
Generates a tmuxinator config file for a session. Uses the current session, or takes the session name as an argument.
#!/bin/bash
session_name=
session_pre=
if [[ "$1" ]]; then
session_name="-t $1"
session_pre="$1"
fi
session_path=$(tmux list-panes -t $session_pre:1 -F "#{pane_start_path}")
echo "project_name:" $(tmux display-message $session_name -p -F "#{session_name}")
echo "project_root: $session_path"
echo "tabs:"
function get_command() {
processes=$(ps h -o cmd -s $1 | grep -v "\-bash" | head -n1)
if [[ $(expr "$processes" : ".*$0") -gt 0 ]]; then
echo -n ""
else
echo -n $processes
fi
}
while read window; do
window_id=$(echo $window | cut -d: -f1)
window_name=$(echo $window | cut -d: -f2)
window_panes=$(echo $window | cut -d: -f3)
window_layout=$(echo $window | cut -d: -f4)
if [[ $window_panes -gt 1 ]]; then
echo " - $window_name:"
echo " layout: $window_layout"
echo " panes: "
else
echo -n " - $window_name: "
fi
while read pane; do
pane_pid=$(echo $pane | cut -d: -f1)
pane_current_path=$(echo $pane | cut -d: -f2)
if [[ $window_panes -gt 1 ]]; then
echo -n " - "
fi
if [[ "$pane_current_path" != "$session_path" ]]; then
echo -n "cd $pane_current_path "
fi
comm=$(get_command $pane_pid)
if [[ "$comm" = "" ]]; then
echo
else
if [[ "$pane_current_path" != "$session_path" ]]; then
echo -n "&& "
fi
echo "$comm"
fi
#echo $pane
done < <(tmux list-panes -t $session_pre:$window_id -F "#{pane_pid}:#{pane_current_path}")
done < <(tmux list-windows $session_name -F "#{window_id}:#{window_name}:#{window_panes}:#{window_layout}")
@cobrajs
Copy link
Author

cobrajs commented Mar 16, 2013

I wanted to reboot (for a system upgrade), but I had a lot of tmux sessions running, and I didn't want to create the tmuxinator configs by hand.

@florian
Copy link

florian commented Mar 23, 2013

The idea is pretty awesome, how about adding something like that to the tmuxinator core? :)
This script seems a bit buggy, though. It threw some errors for me.

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