我正在尝试找出一种方法将我的 i3wm 配置文件移动到组织模式文件。我有一个包含键绑定以及它们应该执行的命令的表,我想从中生成适当的源代码。
例子:
| Keybinding | Command | Action |
|-----------------------+----------------------+--------------------------|
| {{{mod}}} + Return | i3-sensible-terminal | Opens a new terminal |
| {{{mod}}} + Shift + q | kill | Kills the focused window |
Run Code Online (Sandbox Code Playgroud)
应该生成
bindsym {{{mod}}}+Return exec --no-startup-id i3-sensible-terminal ;; Opens a new Terminal
bindsym {{{mod}}}+Shift+q exec --no-startup-id kill ;; Kills the focused window
Run Code Online (Sandbox Code Playgroud)
这样的事可能吗?
您可以命名该表并将其作为参数传递给源块,然后让源块迭代行。这是一个实现python:
#+NAME: commands
| Keybinding | Command | Action |
|-----------------------+----------------------+--------------------------|
| {{{mod}}} + Return | i3-sensible-terminal | Opens a new terminal |
| {{{mod}}} + Shift + q | kill | Kills the focused window |
#+begin_src python :var cmds=commands :results output raw
for row in cmds:
print("bindsym {} exec --no-startup-id {} ;; {}".format(row[0].replace(' ', ''), row[1], row[2]))
#+end_src
Run Code Online (Sandbox Code Playgroud)
这里我假设应该消除第一列中的空格,而不是引用字符串,但您可以轻松修改它。
以下是运行上述源代码块的结果:
#+RESULTS:
bindsym {{{mod}}}+Return exec --no-startup-id i3-sensible-terminal ;; Opens a new terminal
bindsym {{{mod}}}+Shift+q exec --no-startup-id kill ;; Kills the focused window
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
166 次 |
| 最近记录: |