Question

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?

Was it helpful?

Solution

Global alias might do it... actually it does it:

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

Notice:

  1. it is a global alias, so it works anywhere in the command line (not just the beginning)
  2. $(...) will do command substitution and expand it as a variable, see man zshexpn and search for $(...). By default zsh will not break the results using white-spaces.

[...]

I initially wrote a suggestion to create a (zsh) widget to insert the clipboard into the command line with a given key combination, then I realized that you would just likely hit "Ctrl-Shift-V" or something... :-S

[...]

FYI, this is how you would do this using a zsh widget:

that inserts the clipboard content on the command line, and binding it to some key, as it would allow you to see what you are doing before hitting enter. Place the following into your $fpath, inside a file called insert-clipboard (needs to be loaded with KSH_AUTOLOAD set)

#! /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!
}

At your .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...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top