YAML for tmuxinator mapping values inside string

265 views Asked by At

I have the following YAML for tmuxinator:

# ~/.tmuxinator/st.yml
name: st
root: ~/learn/gnu-smalltalk
attach: false

# Runs before everything. Use it to start daemons etc.
on_project_start:
  - emacs --daemon=gst --title=GST
  - export EDITOR="emacsclient --server-file=gst -c -n"
  - export VISUAL=$EDITOR
  - $EDITOR &;
  - gst-load -iI shampoo.im Shampoo
  - gst-remote -I shampoo.im --daemon
  - gst-remote -e "Shampoo.ShampooServer startOn: 9090 login: 'st' pass: 'st'"

on_project_exit:
  - tmux -CC attach -t st

windows:
  - console-emacs-dev:
      - export EDITOR="emacsclient --server-file=gst -c -n"
      - export VISUAL=$EDITOR      
      - echo "A currar"
  - exercism:
      - export EDITOR="emacsclient --server-file=gst -c -n"
      - export VISUAL=$EDITOR

I have two errors that I cannot solve, first is:

 st.yml    14  61 error           mapping values are not allowed in this context (yaml-ruby)

I tried to scape the character ':',

gst-remote -e "Shampoo.ShampooServer startOn: 9090 login\: 'st' pass\: 'st'"

but the same occurs

doesn't work.

2

There are 2 answers

5
Anthon On

Although YAML escape sequences are a superset of those of the C language, you still cannot escape :.

Assuming that gst-remote is executed through some shell, what you need to do is escape the backslash:

gst-remote -e "Shampoo.ShampooServer startOn: 9090 login\\: 'st' pass\\: 'st'"

I would not try and much around with & and assume there is a shell being called that properly processes that. Instead use emacsclient's option --no-wait:

   -n, --no-wait
          returns immediately without waiting for you to "finish" the buf‐
          fer in Emacs.

You should also use .yaml as extension for your YAML files. Not only has that been the recommended extension for YAML since 2006, it also prevents confusion with files in the YML format.

0
anquegi On

This error is a known problem in YAML syntax error when string contains a colon + space, but when using Ansible, after reading the bug the solution that works was to scape the space character after the colon character ':', also in tmuxinator it was a problem

  - gst-remote -e "Shampoo.ShampooServer startOn:\s9090 login:\s'st' pass:\s'st'."

This works for ansible/phyton but not for ruby/tmuxinator

This solution doesn't' work for me, I tried to escape de space inside string \ , \s, or even \u0020, nothing worked the final thing was reading this two posts, it seem that ruby and python use this string in a different way, with ruby I get this error sometimes undefined methodshellescape' for Hash`.

So I continue looking and

Explanation YAML 1

Explanation YAML 2

from the first link:

Plain scalars(value field) must never contain the “: ” and “ #” character combinations. Such combinations would cause ambiguity with mapping key: value pairs and comments.

In addition, inside flow collections, or when used as implicit keys, plain scalars must not contain the “[”, “]”, “{”, “}” and “,” characters. These characters would cause ambiguity with flow collection structures.

You can try these options:

YAML

So the final, yaml file was:

# ~/.tmuxinator/st.yaml
name: st
root: ~/learn/gnu-smalltalk
attach: false

# Runs before everything. Use it to start daemons etc.
on_project_start:
  - emacs --daemon=gst --title=GST
  - export EDITOR="emacsclient --server-file=gst -c -n"
  - export VISUAL=$EDITOR
  - $EDITOR
  - gst-load -iI shampoo.im Shampoo
  - gst-remote -V -I shampoo.im --daemon
  - >-
    gst-remote -V -e "Shampoo.ShampooServer startOn: 9092 login: 'toni' pass: 'toni'."

on_project_exit:
  - tmux -CC attach -t st

windows:
  - console-emacs-dev:
      - export EDITOR="emacsclient --server-file=gst -c -n"
      - export VISUAL=$EDITOR      
      - echo "A currar"
  - exercism:
      - export EDITOR="emacsclient --server-file=gst -c -n"
      - export VISUAL=$EDITOR