Fra*_*itt 35 bash shell command-line fish
我已经使用 bash 十多年了,并且已经习惯于能够输入 !$ 来重复最后一个参数,例如:
$ mkdir foo
$ cd !$
cd foo
Run Code Online (Sandbox Code Playgroud)
(最后一行是由 shell 打印出来的,告诉你你的命令的计算结果)。同样,我经常对以下内容:
$ make_sandwich
-bash: make_sandwich: Permission denied
$ sudo !!
sudo make_sandwich
Run Code Online (Sandbox Code Playgroud)
我真的很喜欢鱼壳,但我的肌肉记忆已经很成熟了。鱼有等价物吗?我可以配置 fish 以使用相同的命令吗?
gle*_*man 31
Alt-Up arrow为您提供上一个命令的最后一个参数。随后的推送循环遍历先前的参数。
我还没有找到一个满意相当于!!,除了Up那么Ctrl-A
gle*_*man 15
我在fish-users 邮件列表上找到了这个完美的答案:
function bind_bang
switch (commandline -t)[-1]
case "!"
commandline -t $history[1]; commandline -f repaint
case "*"
commandline -i !
end
end
function bind_dollar
switch (commandline -t)[-1]
case "!"
commandline -t ""
commandline -f history-token-search-backward
case "*"
commandline -i '$'
end
end
function fish_user_key_bindings
bind ! bind_bang
bind '$' bind_dollar
end
Run Code Online (Sandbox Code Playgroud)
关于fish的github wiki的进一步讨论
小智 13
sudo !!在fish shell(版本3.1b1及更高版本)中,您可以使用绑定__fish_prepend_sudo(默认情况下为Alt+ S)在当前存在的命令行前面加上sudo :
$ make sandwich\xe2\x96\x8e \nRun Code Online (Sandbox Code Playgroud)\nAlt+S
\n$ sudo make sandwich\xe2\x96\x8e\nRun Code Online (Sandbox Code Playgroud)\n从 Fish 3.2.0 开始,空行上的Alt+S将从历史记录中拉出最新的行并添加到前面sudo 。在 3.2.0 之前,您首先需要通过 . 从历史记录中提取最新的行。
从 Fish 3.5.0 开始,doas如果系统上可用但sudo不可用,则将使用该命令。
sudo/之外的前置命令doas请参阅@GlennJackman\'s 答案bind_bang中的函数
<command> !$您可以使用绑定循环遍历先前命令的参数history-token-search-backward。默认的键绑定是Alt+ .,如 Bash 中一样,但也可以使用Alt+和Alt+ :
$ mkdir foo\n$ rmdir \xe2\x96\x8e\nRun Code Online (Sandbox Code Playgroud)\nAlt+.
\n$ rmdir foo\xe2\x96\x8e\nRun Code Online (Sandbox Code Playgroud)\nfish_config可以通过执行并导航到“绑定”选项卡来查看鱼的所有绑定。
Car*_*rot 11
须藤!!(或 sudo bang bang)是我最常用的命令之一。我仍然只使用普通的旧 bash,它已经很好了。很遗憾听到鱼没有正确实现它。有点谷歌搜索,我发现了这个:
function sudo
if test "$argv" = !!
eval command sudo $history[1]
else
command sudo $argv
end
end
Run Code Online (Sandbox Code Playgroud)
这里的线程有更多选项:https : //github.com/fish-shell/fish-shell/issues/288
我和你有同样的问题,我通过使用oh-my-fish
(它是fishshell的插件管理器)https://github.com/oh-my-fish/oh-my-fish来修复 。您可以使用以下命令安装它:
curl -L https://get.oh-my.fish | fish
Run Code Online (Sandbox Code Playgroud)
然后bang-bang使用以下命令安装插件:
omf install bang-bang
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11523 次 |
| 最近记录: |