Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add oneline-procfile-manager #2

merged 1 commit into from Apr 3, 2020
Changes from all commits
File filter

Filter by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,116 @@
<!doctype html>
pre {
white-space: pre-line;
margin: 5% 10%;
font-family: Courier;
pre pre {
white-space: pre;
overflow-x: scroll;
margin: 0 0 -1em 0;
background-color: #eee;
code {
background-color: #eee;
font-family: Courier;
footer {
opacity: 0.1;

<link rel=icon href=/favicon-filipp.ico type=image/x-icon/>

@═╦╣╚╗ <strong><a href=/>A mazing engineer</a></strong>

03-Jun-2019 <strong>One-line Procfile manager</strong>

A <a href=>Procfile</a> contains pairs of process names and commands used to run it. It is often used to run several processes locally, during development, typically a web server, asset server, and background job processor:

web: bundle exec rails server
assets: yarn serve
jobs: bundle exec sidekiq

There is a number of inherent problems with <a href=>Foreman</a>:
- the output of all processes is interleaved. It's near impossible to understand what printed what.
- using REPL when stopping at a debug breakpoint splits your input evenly across the processes, making it barely usable.
- selective process restart is impossible.
- selective filtering or focusing of process output is impossible.

There are tools out there, specifically <a href=>overmind</a>. It runs processes in <a href=>tmux</a>, and that resolves the problems Forman has.
However Overmind is an additional tool that you need to learn.

That led me to a thought that this can be done in a simpler way, running the processes in tmux's split panes.

And a single'ish-line <a href=>Toreman</a> was born that does exactly that.
Well, initially it was actually single line, but I decided to format it for better readability.

Moving between the panes with &lt;Prefix&gt; h/j/k/l can be configured with:

# ~/.tmux.conf
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

Or you can employ a tmux <a href=>pain control plugin</a>.

Zooming a pane has a standard convenient key binding, &lt;Prefix&gt;+z.

Killing a process is simple as ^C, pausing it - ^Z.

I'm not an expert in the field, and writing shell script feels like solving a puzzle, but it's usually very rewarding.
Full annotated Toreman source below:

<pre class=shell>
grep --invert-match '^#' &lt; Procfile | # Filter out comments
sed -e 's/^[^:]*: //' | # Split into process name/command pairs
xargs -I {} \ # For each pair:
tmux \ #
split-window -v \; \ # - split window
send-keys '[ -s .env ] &amp;&amp; source .env; {}' 'C-m' &amp;&amp; # - type the command, prefixed with a `source .env;`
tmux \ #
select-pane -t 1 \; \ # Switch to initial pane
send-keys 'C-d' \; \ # - and close it
select-layout ${1:-tiled} # Also, select the layout, defaulting to tiled

Please do not paste the code above, shell script <a href=>won't work with comments inserted like this</a>.

Toreman supports loading the <a href=>.env file</a>, to load the default environment variables for processes.
Typical .env file looks like this:


Toreman accepts a single argument, a layout to be used. Tiled is the default, the other options are even-horizontal, even-vertical, main-horizontal, and main-vertical.

As per the comments, Toreman might not support alternative shells (e.g. tcsh, ksh) so well.
I've tested on Fish shell, it worked quite fine except that you have to prefix environment variables with an <code>env</code>, e.g.:

web: env PORT=8080 bundle exec rails server

If you're on macOS and are using Homebrew, installing Toreman is easy as:

<pre class=shell>
brew install pirj/homebrew-toreman/toreman

<a href=>Reddit thread</a> with some interesting comments.

The content of this article is licensed under <a href=>CC-BY-SA</a>.