zsh 中的奇怪 "jobs" 行为

Weird "jobs" behavior within zsh

我的 zsh shell 中的 jobsfgbg 命令出现奇怪的行为。这是一个示例(所有命令都会发生这种情况,而不仅仅是 python):

$ python &
[1] 21214
Python 2.7.8 (default, Oct 19 2014, 16:02:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
[1]  + 21214 suspended (tty output)  python
$ jobs
[1]  + suspended (tty output)  python
$ fg 1
fg: job not found: 1
$ bg 1
bg: job not found: 1

我在 OS X 上使用标准的 oh-my-zsh 安装。

您可能习惯于fg N(其中N是工作编号)在Bash工作。但是在 Zsh 中有点不同,需要一个 %;例如,fg %1。 Bash 行为很方便,所以你可以让 Zsh 做同样的事情:

fg() {
    if [[ $# -eq 1 &&  = - ]]; then
        builtin fg %-
    else
        builtin fg %"$@"
    fi
}

可以对 bghistory 执行相同的操作。这最初来自 this thread.

您也可以只键入 fg 并且隐含 %1。当您有几项工作正在进行时,制表符补全也非常适合:fg<tab>