【问题标题】:YAML for tmuxinator mapping values inside stringYAML 用于字符串内的 tmuxinator 映射值
【发布时间】:2019-04-29 07:28:49
【问题描述】:

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

但同样的事情发生

没用。

【问题讨论】:

    标签: yaml tmuxinator


    【解决方案1】:

    虽然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 混淆。

    【讨论】:

    • 我正在使用 zsh,也许这就是问题所在,但这对我不起作用,我遇到了同样的错误。 emacs 提示进展顺利
    • @anquegi 您应该将您的问题分成两个帖子,而不是合并两个不相关的项目,这样您就可以接受这两个项目中的一个,这样就可以让人们知道问题解决了。你确定Shampoo.ShampooServer 不希望login:st 在冒号后面没有空格吗?
    • 是的,你是对的,这个问题可能应该是两个不同的问题,在洗发水的文档中,你在这里看到的字符串是怎样的
    • 你能不能启动一个shell,然后尝试调用整个gst-remote ... 行。一旦您知道什么有效(将结果作为编辑添加到您的问题中),它可能会帮助其他更熟悉 tmuxinator 的人提供帮助(我自己使用基于 Python 的 tmuxp 来处理这种东西(也是基于 YAML 的 BTW))
    • 我知道这个命令在 shell 中工作,它工作得很好,所以现在我想用 tmuxinator 自动化,你说得对,我要编辑这个问题
    【解决方案2】:

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

      - 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`。

    所以我继续寻找和

    Explanation YAML 1

    Explanation YAML 2

    来自第一个链接:

    普通标量(值字段)不得包含“:”和“#” 字符组合。这样的组合会引起歧义 映射键:值对和 cmets。

    此外,在流集合内部,或用作隐式键时, 纯标量不能包含“[”、“]”、“{”、“}”和“,” 人物。这些字符会导致流的歧义 集合结构。

    您可以尝试以下选项:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 2019-05-04
      • 2021-01-15
      • 2015-12-27
      • 1970-01-01
      • 2021-09-23
      • 2018-07-09
      相关资源
      最近更新 更多