字符串中的tmuxinator映射值的YAML

时间:2019-04-29 07:28:50

标签: yaml tmuxinator

对于tmuxinator,我具有以下YAML:

# ~/.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

我有两个无法解决的错误,首先是:

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

我试图对字符':'进行换码,

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

但同样会发生

不起作用。

2 个答案:

答案 0 :(得分:3)

尽管YAML escape sequences是C语言语言的超集,但是您仍然无法逃脱:

假设gst-remote是通过某些shell执行的,那么您需要做的是转义反斜杠:

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

我不会尝试使用&并假设有一个称为shell的外壳可以正确处理该外壳。而是使用emacsclient的选项--no-wait

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

您还应该使用.yaml作为YAML文件的扩展名。自2006年以来,YAML不仅成为recommended extension的地方,而且还避免了与files in the YML format的混淆。

答案 1 :(得分:0)

当字符串包含冒号+空格时,此错误是YAML语法错误中的一个已知问题,但是当使用Ansible时,在阅读the bug之后,可行的解决方案是在冒号字符':'之后对空格字符进行换码,也在tmuxinator it was a problem

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

这适用于ansible / phyton,但不适用于红宝石/ tmuxinator

这个解决方案对我不起作用,我试图在字符串\,\ s甚至\ u0020内转义空格,最后没有结果是读了这两篇文章,看来ruby和python使用了这个字符串以不同的方式使用ruby有时会出现此错误undefined method shellescape'for Hash`。

所以我继续寻找和

Explanation YAML 1

Explanation YAML 2

从第一个链接开始:

  

普通标量(值字段)不得包含“:”和“#”   字符组合。这样的组合会导致与   映射键:值对和注释。

     

此外,在内部流程集合中,或用作隐式键时,   普通标量不得包含“ [”,“]”,“ {”,“}”和“,”   字符。这些字符会导致流程含糊不清   收集结构。

     

您可以尝试以下选项:

     
    

YAML

            

因此,最终的Yaml文件为:

# ~/.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