fish - 如何在 Fish 中使用键盘快捷键扩展环境变量?

标签 fish tab-completion

在 Bash 中,快捷键 Esc Ctrl-e 可用于在 shell 中扩展环境变量:

$ echo $PATH
/home/joe

$ $PATH<Press Esc Ctrl-e>
$ /home/joe

在 Fish 中是否有实现类似功能的快捷方式?

最佳答案

你可以做这样的事情

function bind_expand_all
    # what are the tokens of the current command line
    set tokens (commandline --tokenize)
    # erase the current command line (replace with empty string)
    commandline -r ""
    for token in $tokens
        # append the expanded value of each token followed by a space
        commandline -a (eval echo $token)" "
    end
    # move the cursor to the end of the new command line
    commandline -C (string length (commandline))
end

然后

bind \e\ce bind_expand_all

如果这是您当前的命令行(光标位于下划线处):

$ echo $HOME (date -u)_

当你点击AltCtrle时,你会得到

$ echo /home/jackman Thu May 10 19:27:18 UTC 2018 _

要永久存储该绑定(bind),请将其添加到您的 fish_user_key_bindings 函数中(如果不存在则创建它):

Key bindings are not saved between sessions by default. Bare bind statements in config.fish won't have any effect because it is sourced before the default keybindings are setup. To save custom keybindings, put the bind statements into a function called fish_user_key_bindings, which will be autoloaded.


好一点:

function bind_expand_all
    set -l expanded
    for token in (commandline --tokenize)
        set expanded $expanded (eval echo $token)
    end
    set -l new (string join " " $expanded)
    commandline -r $new
    commandline -C (string length $new)
end

关于fish - 如何在 Fish 中使用键盘快捷键扩展环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50279388/

相关文章:

python - 如何使用 PyQt5 QCompleter 进行代码补全

python - Python 中的 subprocess.call 没有此类文件或目录错误

macos - fish shell 功能中如何具有argv选项?

fish - 如何清空 fish 中的文件?

fish - fish shell 中带有空格的别名

docker - 动态应用完成选项

python - `ipython` 选项卡自动完成对导入的模块不起作用

shell - 在变量扩展后添加文本 - fish

git - 自定义 git "bang"别名的 Zsh 完成 - Git 分支名称

python __getattr__ 自动完成