4

Really quirky title, I know. Basically, I have this:

 alias vv="xclip -selection clipboard -o"

which prints out anything in my clipboard, such as a repository location in ssh-form (git@github.username/repname.git). Now I'd like to:

 git clone vv

I tried several variations of the above, such as trying various switches on the alias, or using different expansions, but with no luck.

Any suggestions?

4

1 回答 1

2

全局别名可能会这样做......实际上它会这样做:

alias -g vv="$(date)" # replace 'date' with your command of choice

注意:

  1. 它是一个全局别名,所以它可以在命令行的任何地方工作(不仅仅是开始)
  2. $(...)将执行命令替换并将其扩展为变量,查看man zshexpn并搜索$(...). 默认情况下 zsh 不会使用空格破坏结果。

[...]

我最初写了一个建议来创建一个(zsh)小部件,以使用给定的组合键将剪贴板插入命令行,然后我意识到你可能会点击“Ctrl-Shift-V”或其他东西...... :-S

[...]

仅供参考,这就是您使用 zsh 小部件执行此操作的方式:

在命令行上插入剪贴板内容,并将其绑定到某个键,因为它可以让您在按 Enter 之前查看您在做什么。将以下内容放入您的$fpath, 一个名为insert-clipboard(需要加载KSH_AUTOLOADset)的文件中

#! /bin/zsh
## Inserts the output of the command into the cmd line buffer
zmodload -i zsh/parameter

insert-clipboard() {
   LBUFFER+="$(date)" # REPLACE date BY YOUR COMMAND!
}

在你的.zshrc

autoload insert-clipboard # as written, it needs KSH_AUTOLOAD set....
zle -N insert-clipboard
bindkey '^Xu' insert-clipboard # pick a key combination you like...
于 2013-07-03T08:38:46.977 回答