在 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 thebind
statements into a function calledfish_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/