【发布时间】:2019-09-02 13:14:51
【问题描述】:
我在 Vim 中有一个热键,可以让我进入命令模式并调用 Bash 脚本。 Bash 脚本会尝试以下步骤:
- 在两个标记之间选择文本
- 将选定的文本块发送到 .py 文件
- 将.py文件加载到IPython
如果我手动输入所有内容,脚本就可以工作,但是如果我运行脚本,文本块直到脚本完成后才会保存为文件,当 IPython 稍后尝试加载文件时会导致错误脚本。
以下是我尝试过的步骤:
- 如果我的文件被保存在缓冲区中,我尝试了syncing and flushing
- 如果文件需要更多时间来编写,我尝试了sleep and wait
- 我还尝试asynchronous shell commands 来查看 Bash 脚本是否比 Vim 写入文件的优先级更高。
#!/bin/bash
# Text to be written has been selected in Vim
tmux send-keys ':w jtemp.py'
tmux send-keys 'Enter'
# Load code selection in IPython
tmux select-pane -t 1
tmux send-keys '%load jtemp.py'
tmux send-keys 'Enter'
tmux send-keys 'Enter'
如何在 Bash 脚本仍在运行时将文件保存到磁盘?
【问题讨论】: