如何编写一个fish函数来执行字符串中的命令并使其出现在历史记录中?
function qh --description 'Use peco to query command history'
if test (count $argv) = 0
set peco_flags --layout=bottom-up
else
set peco_flags --layout=bottom-up --query "$argv"
end
history | peco $peco_flags | read cmd
if test $cmd
commandline $cmd
else
commandline ''
end
end这不管用..。
发布于 2022-04-18 05:31:25
可以创建一个键绑定,该键绑定设置命令行,然后执行它;然后该命令将出现在历史记录中。示例:
function whatday
commandline "echo Today is $(date +%A)"
commandline -f execute
end
bind \eq whatday现在alt将将命令行设置为echo Today is Sunday并执行它;它出现在历史上。
除此之外,还有缩略语,它允许用文本替换令牌;但是文本只是静态的(例如,gco -> git checkout)。
到目前为止,还没有办法让任意的fish函数(例如,作为shell脚本的一部分运行)附加到历史记录中,只删除和读取它。
https://stackoverflow.com/questions/71904936
复制相似问题