将构造的命令添加到bash历史记录中

问题描述 投票:1回答:1

我制作了一个bash函数,该函数检索cron任务列表(从Magento)。我可以立即使用FZF搜索该列表(已过滤),并使用另一个通过xargs的命令运行选定的cron。功能如下:

crf () { magerun2 sys:cr:li | grep -E '\*|-' | grep -v '+' | awk '{print $2}' | fzf --query=$1 | xargs magerun2 sys:cr:run; }

是否有可能将刚刚通过xargs运行的命令添加到历史记录中,所以当我按下up箭头时,它将显示刚刚通过xargs传递的命令?

我正在使用bash 5.0.11(1)-发行版(x86_64-apple-darwin18.6.0)和tmux 3.0的Macbook Pro上运行。

bash
1个回答
1
投票

是,使用history -s

$ history -s my command
<PRESS UP KEY>
$ my command

编辑:因此,在您的情况下,它将类似于

crf () { 

CHRON=$(magerun2 sys:cr:li | grep -E '\*|-' | grep -v '+' | awk '{print $2}' | fzf --query=$1 ) 

for item in $CHRON ; do
    history -s $item
    magerun2 sys:cr:run $item
done 
}
© www.soinside.com 2019 - 2024. All rights reserved.