Share the clipboard between bash and X11

Clash Royale CLAN TAG#URR8PPP
up vote
10
down vote
favorite
In this thread the top answer shows how to copy text that has been previously selected with the mouse on a gnome-terminal, to the clipboard in X11.
My question is: Say I copy a piece of text from the terminal using bash set-mark and copy keyboard shortcuts (i.e. set-mark + M-w). Is it possible to share this clipboard with X11?
EDIT: In the original question, I talked about sharing the clipboard with GNOME, but as Gilles points out below, GNOME doesn't specifically have a clipboard (it's general to X), so I have updated the question.
bash x11 clipboard
add a comment |Â
up vote
10
down vote
favorite
In this thread the top answer shows how to copy text that has been previously selected with the mouse on a gnome-terminal, to the clipboard in X11.
My question is: Say I copy a piece of text from the terminal using bash set-mark and copy keyboard shortcuts (i.e. set-mark + M-w). Is it possible to share this clipboard with X11?
EDIT: In the original question, I talked about sharing the clipboard with GNOME, but as Gilles points out below, GNOME doesn't specifically have a clipboard (it's general to X), so I have updated the question.
bash x11 clipboard
In gnome-terminal, you can also type Ctrl+Shift+C and Ctrl+Shift+V to copy and paste to the system clipboard.
â Lie Ryan
Aug 14 '11 at 17:49
2
See this post stackoverflow.com/questions/994563/⦠But it is not working for me.
â great q
Feb 7 '15 at 18:05
add a comment |Â
up vote
10
down vote
favorite
up vote
10
down vote
favorite
In this thread the top answer shows how to copy text that has been previously selected with the mouse on a gnome-terminal, to the clipboard in X11.
My question is: Say I copy a piece of text from the terminal using bash set-mark and copy keyboard shortcuts (i.e. set-mark + M-w). Is it possible to share this clipboard with X11?
EDIT: In the original question, I talked about sharing the clipboard with GNOME, but as Gilles points out below, GNOME doesn't specifically have a clipboard (it's general to X), so I have updated the question.
bash x11 clipboard
In this thread the top answer shows how to copy text that has been previously selected with the mouse on a gnome-terminal, to the clipboard in X11.
My question is: Say I copy a piece of text from the terminal using bash set-mark and copy keyboard shortcuts (i.e. set-mark + M-w). Is it possible to share this clipboard with X11?
EDIT: In the original question, I talked about sharing the clipboard with GNOME, but as Gilles points out below, GNOME doesn't specifically have a clipboard (it's general to X), so I have updated the question.
bash x11 clipboard
edited Apr 13 '17 at 12:36
Communityâ¦
1
1
asked Aug 13 '11 at 23:49
Amelio Vazquez-Reina
11.7k48124225
11.7k48124225
In gnome-terminal, you can also type Ctrl+Shift+C and Ctrl+Shift+V to copy and paste to the system clipboard.
â Lie Ryan
Aug 14 '11 at 17:49
2
See this post stackoverflow.com/questions/994563/⦠But it is not working for me.
â great q
Feb 7 '15 at 18:05
add a comment |Â
In gnome-terminal, you can also type Ctrl+Shift+C and Ctrl+Shift+V to copy and paste to the system clipboard.
â Lie Ryan
Aug 14 '11 at 17:49
2
See this post stackoverflow.com/questions/994563/⦠But it is not working for me.
â great q
Feb 7 '15 at 18:05
In gnome-terminal, you can also type Ctrl+Shift+C and Ctrl+Shift+V to copy and paste to the system clipboard.
â Lie Ryan
Aug 14 '11 at 17:49
In gnome-terminal, you can also type Ctrl+Shift+C and Ctrl+Shift+V to copy and paste to the system clipboard.
â Lie Ryan
Aug 14 '11 at 17:49
2
2
See this post stackoverflow.com/questions/994563/⦠But it is not working for me.
â great q
Feb 7 '15 at 18:05
See this post stackoverflow.com/questions/994563/⦠But it is not working for me.
â great q
Feb 7 '15 at 18:05
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
Bash's clipboard is internal to bash, bash doesn't connect to the X server.
What you could do is change the meaning of M-w to copy the selection to the X clipboardù in addition to bash's internal clipboard. However bash's integration is pretty loose, and I don't think there's a way to access the region information or the clipboard from bash code. You can make a key binding to copy the whole line to the X clipboard.ò
if [[ -n $DISPLAY ]]; then
copy_line_to_x_clipboard () xsel -ib
bind -x '"eW": copy_line_to_x_clipboard'
fi
If you want to do fancy things in the shell, switch to zsh, which (amongst other advantages) has far better integration between the line editor and the scripting language.
if [[ -n $DISPLAY ]]; then
x-copy-region-as-kill () xsel -ib
x-kill-region () xsel -ib
zle -N x-copy-region-as-kill
zle -N x-kill-region
bindkey 'C-w' x-kill-region
bindkey 'ew' x-copy-region-as-kill
fi
ù
Gnome doesn't specifically have a clipboard, this is general to X.
ò
As of bash 4.1, there is a bug in the key parsing code: key sequences bound with bind -x may not be more than two characters long. I think bash 4.2 fixes some cases of longer prefixes but not all of them; I haven't researched the details.
Thanks for the idea @Gilles! I think it's time for me to learn and switch tozsh.
â Amelio Vazquez-Reina
Aug 14 '11 at 18:02
Finally! Thanks a bunch! Thiscopy_line_to_x_clipboardis exactly what I was missing for a very long time: the copy equivalent of shift+insert. I changed to ctrl-x (bind -x '"C-x") becauseEscis too far to my taste (and C-c would be the dumbest possible choice).
â p_barill
Jul 15 at 17:26
add a comment |Â
up vote
7
down vote
@Gilles already gave an excellent answer. I would just like to mention the existence of xclip, which is also a very useful way to copy terminal output to the X clipboard, by just piping anything into it:
$ cat /etc/passwd | xclip
1
Just a note thatxclipcopies into the primary buffer by default. To use the clipboard, usexclip -selection clipboard.
â Sparhawk
May 30 '14 at 6:23
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
Bash's clipboard is internal to bash, bash doesn't connect to the X server.
What you could do is change the meaning of M-w to copy the selection to the X clipboardù in addition to bash's internal clipboard. However bash's integration is pretty loose, and I don't think there's a way to access the region information or the clipboard from bash code. You can make a key binding to copy the whole line to the X clipboard.ò
if [[ -n $DISPLAY ]]; then
copy_line_to_x_clipboard () xsel -ib
bind -x '"eW": copy_line_to_x_clipboard'
fi
If you want to do fancy things in the shell, switch to zsh, which (amongst other advantages) has far better integration between the line editor and the scripting language.
if [[ -n $DISPLAY ]]; then
x-copy-region-as-kill () xsel -ib
x-kill-region () xsel -ib
zle -N x-copy-region-as-kill
zle -N x-kill-region
bindkey 'C-w' x-kill-region
bindkey 'ew' x-copy-region-as-kill
fi
ù
Gnome doesn't specifically have a clipboard, this is general to X.
ò
As of bash 4.1, there is a bug in the key parsing code: key sequences bound with bind -x may not be more than two characters long. I think bash 4.2 fixes some cases of longer prefixes but not all of them; I haven't researched the details.
Thanks for the idea @Gilles! I think it's time for me to learn and switch tozsh.
â Amelio Vazquez-Reina
Aug 14 '11 at 18:02
Finally! Thanks a bunch! Thiscopy_line_to_x_clipboardis exactly what I was missing for a very long time: the copy equivalent of shift+insert. I changed to ctrl-x (bind -x '"C-x") becauseEscis too far to my taste (and C-c would be the dumbest possible choice).
â p_barill
Jul 15 at 17:26
add a comment |Â
up vote
8
down vote
accepted
Bash's clipboard is internal to bash, bash doesn't connect to the X server.
What you could do is change the meaning of M-w to copy the selection to the X clipboardù in addition to bash's internal clipboard. However bash's integration is pretty loose, and I don't think there's a way to access the region information or the clipboard from bash code. You can make a key binding to copy the whole line to the X clipboard.ò
if [[ -n $DISPLAY ]]; then
copy_line_to_x_clipboard () xsel -ib
bind -x '"eW": copy_line_to_x_clipboard'
fi
If you want to do fancy things in the shell, switch to zsh, which (amongst other advantages) has far better integration between the line editor and the scripting language.
if [[ -n $DISPLAY ]]; then
x-copy-region-as-kill () xsel -ib
x-kill-region () xsel -ib
zle -N x-copy-region-as-kill
zle -N x-kill-region
bindkey 'C-w' x-kill-region
bindkey 'ew' x-copy-region-as-kill
fi
ù
Gnome doesn't specifically have a clipboard, this is general to X.
ò
As of bash 4.1, there is a bug in the key parsing code: key sequences bound with bind -x may not be more than two characters long. I think bash 4.2 fixes some cases of longer prefixes but not all of them; I haven't researched the details.
Thanks for the idea @Gilles! I think it's time for me to learn and switch tozsh.
â Amelio Vazquez-Reina
Aug 14 '11 at 18:02
Finally! Thanks a bunch! Thiscopy_line_to_x_clipboardis exactly what I was missing for a very long time: the copy equivalent of shift+insert. I changed to ctrl-x (bind -x '"C-x") becauseEscis too far to my taste (and C-c would be the dumbest possible choice).
â p_barill
Jul 15 at 17:26
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
Bash's clipboard is internal to bash, bash doesn't connect to the X server.
What you could do is change the meaning of M-w to copy the selection to the X clipboardù in addition to bash's internal clipboard. However bash's integration is pretty loose, and I don't think there's a way to access the region information or the clipboard from bash code. You can make a key binding to copy the whole line to the X clipboard.ò
if [[ -n $DISPLAY ]]; then
copy_line_to_x_clipboard () xsel -ib
bind -x '"eW": copy_line_to_x_clipboard'
fi
If you want to do fancy things in the shell, switch to zsh, which (amongst other advantages) has far better integration between the line editor and the scripting language.
if [[ -n $DISPLAY ]]; then
x-copy-region-as-kill () xsel -ib
x-kill-region () xsel -ib
zle -N x-copy-region-as-kill
zle -N x-kill-region
bindkey 'C-w' x-kill-region
bindkey 'ew' x-copy-region-as-kill
fi
ù
Gnome doesn't specifically have a clipboard, this is general to X.
ò
As of bash 4.1, there is a bug in the key parsing code: key sequences bound with bind -x may not be more than two characters long. I think bash 4.2 fixes some cases of longer prefixes but not all of them; I haven't researched the details.
Bash's clipboard is internal to bash, bash doesn't connect to the X server.
What you could do is change the meaning of M-w to copy the selection to the X clipboardù in addition to bash's internal clipboard. However bash's integration is pretty loose, and I don't think there's a way to access the region information or the clipboard from bash code. You can make a key binding to copy the whole line to the X clipboard.ò
if [[ -n $DISPLAY ]]; then
copy_line_to_x_clipboard () xsel -ib
bind -x '"eW": copy_line_to_x_clipboard'
fi
If you want to do fancy things in the shell, switch to zsh, which (amongst other advantages) has far better integration between the line editor and the scripting language.
if [[ -n $DISPLAY ]]; then
x-copy-region-as-kill () xsel -ib
x-kill-region () xsel -ib
zle -N x-copy-region-as-kill
zle -N x-kill-region
bindkey 'C-w' x-kill-region
bindkey 'ew' x-copy-region-as-kill
fi
ù
Gnome doesn't specifically have a clipboard, this is general to X.
ò
As of bash 4.1, there is a bug in the key parsing code: key sequences bound with bind -x may not be more than two characters long. I think bash 4.2 fixes some cases of longer prefixes but not all of them; I haven't researched the details.
answered Aug 14 '11 at 0:39
Gilles
505k1199991528
505k1199991528
Thanks for the idea @Gilles! I think it's time for me to learn and switch tozsh.
â Amelio Vazquez-Reina
Aug 14 '11 at 18:02
Finally! Thanks a bunch! Thiscopy_line_to_x_clipboardis exactly what I was missing for a very long time: the copy equivalent of shift+insert. I changed to ctrl-x (bind -x '"C-x") becauseEscis too far to my taste (and C-c would be the dumbest possible choice).
â p_barill
Jul 15 at 17:26
add a comment |Â
Thanks for the idea @Gilles! I think it's time for me to learn and switch tozsh.
â Amelio Vazquez-Reina
Aug 14 '11 at 18:02
Finally! Thanks a bunch! Thiscopy_line_to_x_clipboardis exactly what I was missing for a very long time: the copy equivalent of shift+insert. I changed to ctrl-x (bind -x '"C-x") becauseEscis too far to my taste (and C-c would be the dumbest possible choice).
â p_barill
Jul 15 at 17:26
Thanks for the idea @Gilles! I think it's time for me to learn and switch to
zsh.â Amelio Vazquez-Reina
Aug 14 '11 at 18:02
Thanks for the idea @Gilles! I think it's time for me to learn and switch to
zsh.â Amelio Vazquez-Reina
Aug 14 '11 at 18:02
Finally! Thanks a bunch! This
copy_line_to_x_clipboard is exactly what I was missing for a very long time: the copy equivalent of shift+insert. I changed to ctrl-x (bind -x '"C-x") because Esc is too far to my taste (and C-c would be the dumbest possible choice).â p_barill
Jul 15 at 17:26
Finally! Thanks a bunch! This
copy_line_to_x_clipboard is exactly what I was missing for a very long time: the copy equivalent of shift+insert. I changed to ctrl-x (bind -x '"C-x") because Esc is too far to my taste (and C-c would be the dumbest possible choice).â p_barill
Jul 15 at 17:26
add a comment |Â
up vote
7
down vote
@Gilles already gave an excellent answer. I would just like to mention the existence of xclip, which is also a very useful way to copy terminal output to the X clipboard, by just piping anything into it:
$ cat /etc/passwd | xclip
1
Just a note thatxclipcopies into the primary buffer by default. To use the clipboard, usexclip -selection clipboard.
â Sparhawk
May 30 '14 at 6:23
add a comment |Â
up vote
7
down vote
@Gilles already gave an excellent answer. I would just like to mention the existence of xclip, which is also a very useful way to copy terminal output to the X clipboard, by just piping anything into it:
$ cat /etc/passwd | xclip
1
Just a note thatxclipcopies into the primary buffer by default. To use the clipboard, usexclip -selection clipboard.
â Sparhawk
May 30 '14 at 6:23
add a comment |Â
up vote
7
down vote
up vote
7
down vote
@Gilles already gave an excellent answer. I would just like to mention the existence of xclip, which is also a very useful way to copy terminal output to the X clipboard, by just piping anything into it:
$ cat /etc/passwd | xclip
@Gilles already gave an excellent answer. I would just like to mention the existence of xclip, which is also a very useful way to copy terminal output to the X clipboard, by just piping anything into it:
$ cat /etc/passwd | xclip
edited Aug 14 '11 at 16:30
Michael Mrozekâ¦
58.3k26184206
58.3k26184206
answered Aug 14 '11 at 6:34
âÂÂaphink
25118
25118
1
Just a note thatxclipcopies into the primary buffer by default. To use the clipboard, usexclip -selection clipboard.
â Sparhawk
May 30 '14 at 6:23
add a comment |Â
1
Just a note thatxclipcopies into the primary buffer by default. To use the clipboard, usexclip -selection clipboard.
â Sparhawk
May 30 '14 at 6:23
1
1
Just a note that
xclip copies into the primary buffer by default. To use the clipboard, use xclip -selection clipboard.â Sparhawk
May 30 '14 at 6:23
Just a note that
xclip copies into the primary buffer by default. To use the clipboard, use xclip -selection clipboard.â Sparhawk
May 30 '14 at 6:23
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f18701%2fshare-the-clipboard-between-bash-and-x11%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
In gnome-terminal, you can also type Ctrl+Shift+C and Ctrl+Shift+V to copy and paste to the system clipboard.
â Lie Ryan
Aug 14 '11 at 17:49
2
See this post stackoverflow.com/questions/994563/⦠But it is not working for me.
â great q
Feb 7 '15 at 18:05