Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ env:
- TMUX_VERSION=2.0
- TMUX_VERSION=1.8
- TMUX_VERSION=1.9a
matrix:
allow_failures:
- env: TMUX_VERSION=master
before_install:
- export PIP_USE_MIRRORS=true
- pip install --upgrade pytest # https://github.com/travis-ci/travis-ci/issues/4873
Expand Down
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog

Here you can find the recent changes to tmuxp

- :feature:`65` Ability to specify ``options`` and ``global_options`` via
configuration. Also you can specify environment variables via that.

Include tests.

- :release:`1.1.1 <2016-06-02>`
- :bug:`167 backported` fix attaching multiple sessions
- :bug:`165 backported` fix typo in error output, thanks @fpietka
Expand Down
16 changes: 12 additions & 4 deletions doc/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ Environment variable replacing
------------------------------

tmuxp will replace environment variables wrapped in curly brackets
for the following variables:
for values of these settings:

- ``start_directory``
- ``before_script``
- ``session_name``
- ``window_name``
- ``shell_command_before``
- ``global_options``
- ``options`` in session scope and window scope

tmuxp replaces these variables before-hand with variables in the
terminal ``tmuxp`` invokes in.
Expand Down Expand Up @@ -278,19 +280,25 @@ JSON
.. literalinclude:: ../examples/window-index.json
:language: json

Automatic Rename
Set tmux options
----------------

Works with global (server-wide) options, session options
and window options.

Including ``automatic-rename``, ``default-shell``,
``default-command``, etc.

YAML
~~~~

.. literalinclude:: ../examples/automatic-rename.yaml
.. literalinclude:: ../examples/options.yaml
:language: yaml

JSON
~~~~

.. literalinclude:: ../examples/automatic-rename.json
.. literalinclude:: ../examples/options.json
:language: json

Main pane height
Expand Down
24 changes: 13 additions & 11 deletions examples/env-variables.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"before_script": "${MY_ENV_VAR}/test3.sh",
"before_script": "${MY_ENV_VAR}/test3.sh",
"windows": [
{
"panes": [
Expand All @@ -8,24 +8,26 @@
"tail -F /var/log/syslog"
]
}
],
"start_directory": "/var/log",
],
"start_directory": "/var/log",
"window_name": "editor"
},
},
{
"panes": [
{
"shell_command": [
"htop",
"htop",
"ls $PWD"
]
}
],
"window_name": "logging for {USER}",
"automatic_rename": true
"window_name": "logging for ${USER}",
"options": {
"automatic-rename": true
}
}
],
"shell_command_before": "echo ${PWD}",
"start_directory": "${PWD}/test",
],
"shell_command_before": "echo ${PWD}",
"start_directory": "${PWD}/test",
"session_name": "session - ${USER} (${MY_ENV_VAR})"
}
}
3 changes: 2 additions & 1 deletion examples/env-variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ windows:
- tail -F /var/log/syslog
start_directory: /var/log
- window_name: logging for ${USER}
automatic_rename: true
options:
automatic-rename: true
panes:
- shell_command:
- htop
Expand Down
9 changes: 8 additions & 1 deletion examples/automatic-rename.json → examples/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@
}
],
"session_name": "test window options",
"start_directory": "~"
"start_directory": "~",
"global_options": {
"default-shell": "/bin/sh",
"default-command": "/bin/sh"
},
"options": {
"main-pane-height": "${MAIN_PANE_HEIGHT}"
}
}
5 changes: 5 additions & 0 deletions examples/automatic-rename.yaml → examples/options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
session_name: test window options
start_directory: '~'
global_options:
default-shell: /bin/sh
default-command: /bin/sh
options:
main-pane-height: ${MAIN_PANE_HEIGHT} # works with en variables
windows:
- layout: main-horizontal
options:
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kaptan>=0.5.7
libtmux==0.4.1
libtmux==0.5
click==6.6
colorama
4 changes: 2 additions & 2 deletions tests/fixtures/config/expand1.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
{
'start_directory': '/var/log',
'options': {'automatic_rename': True, },
'options': {'automatic-rename': True, },
'panes': [
{
'shell_command': 'htop'
Expand Down Expand Up @@ -95,7 +95,7 @@
},
{
'start_directory': '/var/log',
'options': {'automatic_rename': True},
'options': {'automatic-rename': True},
'panes': [
{'shell_command': ['htop']},
{'shell_command': ['vim']}
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/config/shell_command_before.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
]
},
{
'options': {'automatic_rename': True, },
'options': {'automatic-rename': True, },
'panes': [
{'shell_command': ['htop']}
]
Expand Down Expand Up @@ -92,7 +92,7 @@
]
},
{
'options': {'automatic_rename': True, },
'options': {'automatic-rename': True, },
'panes': [
{'shell_command': ['htop']}
]
Expand Down Expand Up @@ -155,7 +155,7 @@
},
{
'start_directory': '/',
'options': {'automatic_rename': True, },
'options': {'automatic-rename': True, },
'panes': [
{
'shell_command': ['htop']
Expand Down
13 changes: 13 additions & 0 deletions tests/fixtures/workspacebuilder/env_var_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
session_name: test env vars for options
start_directory: '~'
global_options:
visual-silence: ${VISUAL_SILENCE}
options:
repeat-time: 738
windows:
- window_name: moo
layout: main-horizontal
options:
main-pane-height: ${MAIN_PANE_HEIGHT}
panes:
- pane
12 changes: 12 additions & 0 deletions tests/fixtures/workspacebuilder/global_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
session_name: test global options
start_directory: '~'
global_options:
repeat-time: 493
status-position: 'top'
windows:
- layout: main-horizontal
panes:
- pane
- pane
- pane
window_name: moo
2 changes: 1 addition & 1 deletion tests/fixtures/workspacebuilder/pane_ordering.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ session_name: sampleconfig
start_directory: {HOME}
windows:
- options:
- automatic_rename: on
automatic-rename: on
layout: tiled
panes:
- cd /usr/bin
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/workspacebuilder/session_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
session_name: test session options
start_directory: '~'
options:
default-shell: /bin/sh
default-command: /bin/sh
windows:
- layout: main-horizontal
panes:
- pane
- pane
- pane
window_name: moo
41 changes: 22 additions & 19 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import kaptan
import pytest

from libtmux.test import EnvironmentVarGuard
from tmuxp import config, exc

from . import example_dir
Expand Down Expand Up @@ -129,7 +128,7 @@ def test_config_expand2():
]
},
{
'options': {'automatic_rename': True, },
'options': {'automatic-rename': True, },
'panes': [
{'shell_command': ['htop']}
]
Expand Down Expand Up @@ -158,7 +157,7 @@ def test_config_expand2():
},
{
'options': {
'automatic_rename': True,
'automatic-rename': True,
},
'panes': [
'htop'
Expand Down Expand Up @@ -213,7 +212,7 @@ def test_inline_config():
},
{
'options': {
'automatic_rename': True,
'automatic-rename': True,
},
'panes': [
{
Expand Down Expand Up @@ -257,7 +256,7 @@ def test_inline_config():
]
},
{
'options': {'automatic_rename': True, },
'options': {'automatic-rename': True, },
'panes': [
{
'shell_command': ['htop'],
Expand Down Expand Up @@ -363,7 +362,7 @@ def test_no_session_name():
- tail -F /var/log/syslog
start_directory: /var/log
- window_name: logging
automatic_rename: true
automatic-rename: true
panes:
- shell_command:
- htop
Expand Down Expand Up @@ -399,7 +398,7 @@ def test_no_window_name():
shell_command:
- tail -F /var/log/syslog
start_directory: /var/log
- automatic_rename: true
- automatic-rename: true
panes:
- shell_command:
- htop
Expand All @@ -413,22 +412,26 @@ def test_no_window_name():
assert excinfo.matches('missing "window_name"')


def test_replaces_start_directory():
def test_replaces_env_variables(monkeypatch):
env_key = "TESTHEY92"
env_value = "HEYO1"
env_val = "HEYO1"
yaml_config = """
start_directory: {TEST_VAR}/test
shell_command_before: {TEST_VAR}/test2
before_script: {TEST_VAR}/test3
session_name: hi - {TEST_VAR}
options:
default-command: {TEST_VAR}/lol
global_options:
default-shell: {TEST_VAR}/moo
windows:
- window_name: editor
panes:
- shell_command:
- tail -F /var/log/syslog
start_directory: /var/log
- window_name: logging @ {TEST_VAR}
automatic_rename: true
automatic-rename: true
panes:
- shell_command:
- htop
Expand All @@ -438,12 +441,12 @@ def test_replaces_start_directory():

sconfig = load_yaml(yaml_config)

with EnvironmentVarGuard() as env:
env.set(env_key, env_value)
sconfig = config.expand(sconfig)
assert "%s/test" % env_value == sconfig['start_directory']
assert "%s/test2" % env_value in sconfig['shell_command_before']
assert "%s/test3" % env_value == sconfig['before_script']
assert "hi - %s" % env_value == sconfig['session_name']
assert "logging @ %s" % env_value == \
sconfig['windows'][1]['window_name']
monkeypatch.setenv(env_key, env_val)
sconfig = config.expand(sconfig)
assert "%s/test" % env_val == sconfig['start_directory']
assert "%s/test2" % env_val in sconfig['shell_command_before']
assert "%s/test3" % env_val == sconfig['before_script']
assert "hi - %s" % env_val == sconfig['session_name']
assert "%s/moo" % env_val == sconfig['global_options']['default-shell']
assert "%s/lol" % env_val == sconfig['options']['default-command']
assert "logging @ %s" % env_val == sconfig['windows'][1]['window_name']
Loading