首页 > 解决方案 > 有没有办法告诉 Fish shell 纠正带有空格的命令中的常见拼写错误?

问题描述

我对 Fish 很陌生,到目前为止我很喜欢它,但我很生气缩写不能有空格。例如,当我键入git statsu比实际命令更频繁的 时git status,我希望它用正确的命令替换文本。我尝试将以下内容添加到我的config.fish文件中:

abbr "git statsu" "git status"

…这给了我:

abbr --add: Abbreviation 'git statsu' cannot have spaces in the word

第二次尝试(不支持带空格的别名):

alias "git statsu"="git status"
- (line 1): function: Unexpected positional argument 'statsu'
function git statsu --wraps 'git status' --description 'alias git statsu=git status';  git status $argv; end
^
from sourcing file -
    called on line 61 of file /usr/share/fish/functions/alias.fish
in function 'alias' with arguments 'git\ statsu=git\ status'
    called on line 19 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called on line 1 of file -
in function 'config'

同样,我尝试:

alias "git\ statsu"="git\ status"

静默失败:

> git statsu
git: 'statsu' is not a git command. See 'git --help'.

The most similar command is
    status

最后(第一个参数后的缩写未扩展):

abbr statsu status
> git statsu
git: 'statsu' is not a git command. See 'git --help'.

The most similar command is
    status

请提供替代解决方案;我厌倦了不断输入错误的命令并不得不手动更正它。

标签: aliasfishabbreviation

解决方案


为什么不使用 git 别名。这是我的几个:

$ cat ~/.gitconfig
...
[alias]
    co = checkout
    stat = status

这是你可以做的一个鱼的事情,很容易用其他常见的错别字扩展:

function git
    switch $argv[1]
        case statsu
            set argv[1] status
    end
    command git $argv
end

推荐阅读