今天我花了很多时间像样的数目写一个简单的的zsh实施MacOS的;用法如下:
example command: git commit -m "Changed a few things"
command that copies: c git commit -m "Changed a few things"
# The second command does not actually execute the command, it just copies it.
# Using zsh, this should reduce the whole process to about 3 keystrokes:
#
# 1) CTRL + A (to go to the beginning of the line)
# 2) 'c' + ' '
# 3) ENTER
preexec()是正确的,当你按回车键时调用的zsh的钩子函数,但该命令实际执行之前。
由于某些字符,例如'“,我们将要使用preexec(),它允许您访问未经处理的原始命令
伪代码是这样的zsh中带参数:
1)请确保该命令在开始
2)如果是这样,通过焦炭复制整个命令,焦炭,到一个临时变量
3)管道的临时变量到,MACOS的复制缓冲区
真正的代码:
c() {} # you'll want this so that you don't get a command unrecognized error
preexec() {
tmp="";
if [ "${1:0:1}" = "c" ] && [ "${1:1:1}" = " " ] && [ "${1:2:1}" != " " ]; then
for ((i=2; i
tmp="${tmp}${1:$i:1}";
done
echo "$tmp" | pbcopy;
fi
}
来吧,粘在你的.zshrc文件中上述两种功能,或任何你想要(我把我的一个文件在我.oh-my-zsh/custom目录)。
如果有人有一个更优雅的解决方案,PLZ说出来。 任何要避免使用鼠标。