0

我有以下用于 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'"

但同样的事情发生

不起作用。

4

2 回答 2

3

尽管YAML 转义序列是 C 语言转义序列的超集,但您仍然无法转义:.

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

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

我不会尝试并&假设有一个外壳被调用来正确处理它。而是使用emacsclient's 选项--no-wait

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

您还应该将.yaml其用作 YAML 文件的扩展名。这不仅是自 2006 年以来推荐的 YAML 扩展名,它还可以防止与YML 格式的文件混淆。

于 2019-04-29T08:28:03.970 回答
0

当字符串包含冒号 + 空格时,此错误是 YAML 语法错误中的一个已知问题,但是在使用 Ansible 时,在阅读了该错误后,可行的解决方案是在冒号字符“:”之后转义空格字符,也在 tmuxinator 中它是一个问题

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

这适用于 ansible/phyton 但不适用于 ruby​​/tmuxinator

这个解决方案对我不起作用,我试图在字符串 \ 、 \s 甚至 \u0020 中转义空间,没有任何效果最后一件事是阅读这两个帖子,似乎 ruby​​ 和 python 在不同的方式,使用 ruby​​,我有时会遇到这个错误undefined methodshellescape' for Hash`。

所以我继续寻找

说明 YAML 1

说明 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
于 2019-05-01T06:59:31.207 回答