小编Mar*_*ert的帖子

如何使用 hist_ignore_dups 忽略 zsh 中启用 Extended_history 的重复行?

当启用hist_ignore_dupsin时zsh,我发现 中有很多重复的行$HISTFILE

(笔记:HISTFILE="$HOME/.zsh_history"

$ cat $HISTFILE

: 1593874281:0;ls
: 1593874287:0;l
: 1593874288:0;ls
: 1593874291:0;l
Run Code Online (Sandbox Code Playgroud)

我认为hist_ignore_dups应该解决这个问题。(HIST_IGNORE_DUPS http://zsh.sourceforge.net/Doc/Release/Options.html)。

但是重复的行仍然出现在 中$HISTFILE,即使已经通过历史记录hist_ignore_dups插件启用了。ohmyzsh

## History command configuration
setopt extended_history       # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups       # ignore duplicated commands history list
setopt hist_ignore_space      # ignore commands that start with space
setopt hist_verify            # …
Run Code Online (Sandbox Code Playgroud)

zsh

8
推荐指数
1
解决办法
4577
查看次数

zsh 行编辑器:我可以通过参数进行导航和编辑吗?

当尝试执行命令时,我在 shell 中遇到一种常见情况

command "/some/complex/and terrible/path" -vf --various --flags --and -- things --config-file="/some other/annoyingly/large/path/to/somewhere"

事实证明我大部分时间都在那里,但需要移动一些东西。假设我必须将最后一个参数一直移到前面才能尝试下一步。

command --config-file="/some other/annoyingly/large/path/to/somewhere" "/some/complex/and terrible/path" -vf --various --flags --and -- things

尝试用击键高尔夫来看待这个问题,这是一个可怕的情况。这实际上是一个噩梦般的 shell 命令输入场景,您必须重新输入(或复制并粘贴)几乎一半的命令。保持理智的最佳希望可能是使用外部编辑器[像这样]

即便如此,Vim 还不够聪明,无法进行 arg 解析(因此没有快速的方法可以使用 eg 来取出最后一个 arg daW,尽管考虑到 vim 的强大功能,应该可以在 8 个按键左右完成这项工作) 。

我认为这可能是一个不错的解决方法,因为我确实使用了很多软件来在 vim 中编辑文本,因为我使用它来完成所有编码。

但我想要的是,Zsh(甚至 Bash!)行编辑器是否可以以某种方式进行编程,让我可以将 arg 推到周围。有点像这样: https: //github.com/AndrewRadev/sideways.vim但是,当然,这个插件也不适用于空格分隔的 shell 参数。并且需要vim。

我对定向跳跃(这样我可以将光标放在--config-filearg 上的某处,然后混搭 HopLeft 以将 arg 跳到左侧)或猛拉并粘贴(这样我可以将光标放在--config-filearg上的某处)感到满意,将其拉出,按 home 转到前面并将其粘贴在后面)。

通过这种方式,我们可以通过将参数作为一个单元进行导航,而不是将单个字符作为一个单元进行导航,从而快速重构 shell 参数。它会大大加快一般命令编辑的速度。我非常关心这一点,因为我直接在 shell 中进行了异常大量的编码。

如果我们要进一步考虑这个想法,这将被实现为编辑器模式,我们将其称为参数编辑模式,其中光标在参数而不是字符上移动,并且可以将参数作为一个单元执行一组更完善的操作。

现在让我们回到现实。问题是:我可以通过编程方式使 zsh 删除我当前所在的 …

shell bash zsh line-editor

7
推荐指数
1
解决办法
1322
查看次数

代码在 bash 中工作,而不是在 zsh 中工作——在任意 fd 上聚集

我是 shell 脚本新手,这让我想知道为什么以下代码片段在 zsh 中不起作用,但在 bash 中却起作用?是否有相同片段的 zsh 等效项?我收到错误parse error near `200'

( 
  flock -e 200
  echo "In critical section"
  sleep 5 
) 200>/tmp/blah.lockfile 
echo "After critical section"
Run Code Online (Sandbox Code Playgroud)

上面的代码片段来自src: https: //stackoverflow.com/a/13551882/15087532

bash zsh shell-script lock

6
推荐指数
1
解决办法
664
查看次数

zsh:如何检索上一个命令行?

我想创建一个命令来获取匹配的先前命令,如下所示:

match-latest "ssh root@150"
Run Code Online (Sandbox Code Playgroud)

但随后退出并使用最新的匹配项填充命令提示符,例如:

owilliams@OWILLIAMS010451 ~/go/ % ssh root@150.2.3.4
Run Code Online (Sandbox Code Playgroud)

并将其留给用户编辑(如果需要)并自行按 Enter 键。这可能吗?我该怎么做呢?

zsh我在 MacBook Pro OSX 上使用5.8

command-line zsh

3
推荐指数
1
解决办法
3259
查看次数

标签 统计

zsh ×4

bash ×2

command-line ×1

line-editor ×1

lock ×1

shell ×1

shell-script ×1