remi / teamocil

There's no I in Teamocil. At least not where you think. Teamocil is a simple tool used to automatically create windows and panes in tmux with YAML files.
MIT License
2.35k stars 101 forks source link

Environment variable for `root` does not work #119

Open spinningarrow opened 7 years ago

spinningarrow commented 7 years ago

I'm trying to use teamocil with the root setting in my config. I have something like this:

windows:
  - name: some-name
    root: $WORKSPACE
    layout: even-horizontal
    panes:
      - commands:
        - cd my-project
        - git fetch

I have $WORKSPACE set to ~/dev/workspace and exported in my shell config (I'm using fish) but this is not working.

Running with the debug flag I see

tmux new-window -n 'some-name' -c '/Users/sahil/dev/$WORKSPACE'

Instead of resolving the variable to a path, it's instead appending it to my current directory and creating an invalid path.

Is this something that can be fixed?

SidOfc commented 7 years ago

This happens because the file is not 'parsed' by the shell, when you use commands on the terminal, the shell can look up the variable SAMPLE in your environment when you echo $SAMPLE. However, this file simply gets loaded into Teamocil as a string and no further parsing is done, except from YAML to a ruby hash, not even a shell nearby :)

I've created a pull request here: #121 but the tests aren't running and I'm not really sure why but the commits add a grand total of ~3 lines (including documentation note) enabling ERB support in the YAML config files. This allows you to do something like this instead:

windows:
  - name: some-name
     root: <%= ENV['WORKSPACE'] %>
     layout: even-horizontal
     ... snipped...

I'm unsure if it'll make it in the actual project, for now - I've created a fork which is at the time of writing on version 1.4.2.

To install the fork, one should first git clone my fork locally, then uninstall the teamocil gem with gem uninstall teamocil then cd into the fork directory and run rake install:local to build and install the forked version, you should be able to use the teamocil command like normal with the key difference being enabled ERB support :)