Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

0 votes
3 answers
182 views
xsel like a clipboard manager: keep clipboard content for future use
I'd like to run `xsel` as background process to keep clipboard content for future use. I run it in openbox startup script like that: ```lang-shell xsel -b -k ``` But when I select something with Ctrl - C and close original application, there is nothing in clipboard. Also I don't see `xsel` process i...
I'd like to run xsel as background process to keep clipboard content for future use. I run it in openbox startup script like that:
-shell
xsel -b -k
But when I select something with Ctrl-C and close original application, there is nothing in clipboard. Also I don't see xsel process in task manager. What I'm doing wrong? PS. I don't what to use parcellite of smth like that. Just simple shell scripts.
Anton Vakulenko (23 rep)
Jul 2, 2024, 06:24 AM • Last activity: Jul 3, 2024, 03:36 PM
3 votes
3 answers
6484 views
How do I copy a file to the clipboard with the terminal?
I'm aware of how to copy the **contents** of file: ```shell xsel -b < myfile.txt ``` But this is **not** what I want. I would like something like this: ``` ./file2clip.sh myfile.txt ``` Which would copy `myfile.txt` to the clipboard so then I could `ctrl` + `v` (paste) or right click and paste **the...
I'm aware of how to copy the **contents** of file:
xsel -b < myfile.txt
But this is **not** what I want. I would like something like this:
./file2clip.sh myfile.txt
Which would copy myfile.txt to the clipboard so then I could ctrl + v (paste) or right click and paste **the file** anywhere (on the desktop, in the file explorer, etc.). How can I copy a file/files to the clipboard so that I can paste it with ctrl + v anywhere in the gui? Windows equivalent: (powershell)
Set-Clipboard -Path myfile.txt
Macos equivalent: (applescript)
#!/usr/bin/osascript
on run args
    set the clipboard to POSIX file (first item of args)
end
./file2clip.applescript myfile.txt
lordcommander (139 rep)
May 22, 2021, 01:00 PM • Last activity: Jun 24, 2024, 11:02 PM
10 votes
3 answers
22780 views
xsel: Can't open display: (null)
I want to copy a long file into clipboard with xsel,in my local pc ,just input: cat /usr/bin/mysql_secure_installation|xsel -b The file `mysql_secure_installation` located in my local os was copied into clipboard. Now login to my vps with ssh command,then input DISPLAY=:0 cat /usr/bin/mysql_secure_i...
I want to copy a long file into clipboard with xsel,in my local pc ,just input: cat /usr/bin/mysql_secure_installation|xsel -b The file mysql_secure_installation located in my local os was copied into clipboard. Now login to my vps with ssh command,then input DISPLAY=:0 cat /usr/bin/mysql_secure_installation|xsel -b I come across the error info: xsel: Can't open display: (null) : Inappropriate ioctl for device I know that the proper way to get remote file is scp command: scp -P port username@tohostname:/remotefile /newlocalfile I just wonder how to get file content copied into clipboard after loginning my vps,copy file from remote machine to the clipboard of my local computer. Same error: DISPLAY=:0 xsel -b < /usr/bin/mysql_secure_installation xsel: Can't open display: (null) : Connection refused
showkey (499 rep)
Feb 6, 2020, 09:53 AM • Last activity: Apr 26, 2024, 11:37 PM
0 votes
2 answers
1058 views
how to get file path without the filename itself
im trying to find my .csv files then cd into their directory: find Documents/notes -type f -name "*.csv" | head -1 | xsel -b this copies the first file dir into my clipboard and i'd like to then run: cd $(xsel -b) but ofcourse I can't because it's including the filename which isn't a directory. Is t...
im trying to find my .csv files then cd into their directory: find Documents/notes -type f -name "*.csv" | head -1 | xsel -b this copies the first file dir into my clipboard and i'd like to then run: cd $(xsel -b) but ofcourse I can't because it's including the filename which isn't a directory. Is there anyway to omit the filename? is there a better way to do this?
Mathew (243 rep)
Sep 17, 2023, 08:26 PM • Last activity: Sep 18, 2023, 12:05 AM
0 votes
1 answers
184 views
xsel not outputing to file in bash script
I am currently learning French, and in order to streamline my study process, I would like to have a script that allows me to look up words on Wiktionary and keep a record of my searches for later review. After some trial and error, I hacked together a bash script that launched the Wiktionary page fo...
I am currently learning French, and in order to streamline my study process, I would like to have a script that allows me to look up words on Wiktionary and keep a record of my searches for later review. After some trial and error, I hacked together a bash script that launched the Wiktionary page for my text selection and saved the selection, and the date of the selection, to a text file.
#!/bin/bash

firefox 'https://en.wiktionary.org/wiki/ '$(xsel)'#French'
echo $(xsel)$(date +": %Y-%m-%d (%a)") >> fr/word-list.txt
The first dozen times I used the script it worked as desired. However, for some reason, the second line of the script is no longer fully working. The date is still outputted to the file but not the xsel text selection. The first line below is expected output; the second line is an example of the output I am currently getting.
enterrement: 2023-06-18 (Sun)
: 2023-06-18 (Sun)
I'm sure my noob script could be improved but the problem seems to be with xsel itself as it is not working consistently when I run it by itself. Sometimes it is returning a blank output including when I use xsel -o, xsel -ob, and xsel -op. Confusingly, the first line of the script, which also relies on xsel, *is* working consistently.
Spen Lack (3 rep)
Jun 19, 2023, 01:22 AM • Last activity: Jun 19, 2023, 09:39 AM
9 votes
2 answers
1303 views
xsel and xclip hang
My objective is to make a text on my remote machine (CentOS 7.2) available to seamlessly paste on my local machine (OS X 10.12.2) with the standard &#8984;V shortcut. My setup connects to the remote machine with `ssh -Y` and then attaches to tmux (or creates a new session if non-existent). When I ru...
My objective is to make a text on my remote machine (CentOS 7.2) available to seamlessly paste on my local machine (OS X 10.12.2) with the standard ⌘V shortcut. My setup connects to the remote machine with ssh -Y and then attaches to tmux (or creates a new session if non-existent). When I run either echo "test" | xsel -ib or echo "test" | xclip it hangs. The $DISPLAY variable is localhost:10.0. If I exit tmux the $DISPLAY variable seems to be null and I get a can't open display error.
Kvass (221 rep)
Jan 4, 2017, 11:25 PM • Last activity: Jan 7, 2023, 12:36 PM
1 votes
1 answers
89 views
How to run command when user push ctrl+c?
User selects any text and push ctrl+c. How to autorun `command` after this action? I need solutions for: 1. How to get notification/check about the state of the clipboard 2. After notification/check will autorun command I haven't idea.
User selects any text and push ctrl+c. How to autorun command after this action? I need solutions for: 1. How to get notification/check about the state of the clipboard 2. After notification/check will autorun command I haven't idea.
69 420 1970 (407 rep)
Sep 23, 2022, 04:20 PM • Last activity: Sep 23, 2022, 09:21 PM
2 votes
0 answers
513 views
How to paste selection from vi-mode to clipboard
I want to access the content of what I copied in the buffer with the vi-mode of the clipboard via the command `ctrl` + `v` or `ctrl` + `shift` + `v` in the terminal. I copied in my .zshrc the following: (from this answer: https://unix.stackexchange.com/questions/25765/pasting-from-clipboard-to-vi-en...
I want to access the content of what I copied in the buffer with the vi-mode of the clipboard via the command ctrl + v or ctrl + shift + v in the terminal. I copied in my .zshrc the following: (from this answer: https://unix.stackexchange.com/questions/25765/pasting-from-clipboard-to-vi-enabled-zsh-or-bash-shell)
vi-append-x-selection () { RBUFFER=$(xsel -o -p 
When I highlight something in the terminal in vi-mode and yank it, I can successfully retrieve it by typing Ctrl + shift + y. However when I type Ctrl + shift + v, something else in being pasted. When I inspect the content of the clipboard with the following commands:
xclip -o sel p
xclip -o sel s
xclip -o sel c
xsel -o -p
xsel -o -s
xsel -o -b
it contains other string that I peviously copied with other means but NOT what I highlighted in vi-mode. Here is my **first question**: if I can retrieve it with the command Ctrl + shift + y and confirm that with xsel and xclip that it is not in one of the three buffer ("primary", "secondary" and "clipboard") where is stored then???) I also tried to replace the '^Y' by '^V' in the line
bindkey -a '^Y' vi-yank-x-selection
(as follows:)
bindkey -a '^V' vi-yank-x-selection
Without any success (it seems to print out an empty buffer) **my second question**: What am I doing wrong?
ecjb (475 rep)
May 26, 2022, 01:25 PM • Last activity: May 27, 2022, 10:16 PM
3 votes
2 answers
1543 views
Linux clipboards, including with WSL consoles
It occurred to me that there are multiple clipboards on any given Linux console: - First is the bash clipboard, this can be invoked by Ctrl-U / K, cut all line before (U) or after (K) cursor into clipboard, or Ctrl-W, to cut the word on the left side of the cursor (is there a corresponding "cut word...
It occurred to me that there are multiple clipboards on any given Linux console: - First is the bash clipboard, this can be invoked by Ctrl-U / K, cut all line before (U) or after (K) cursor into clipboard, or Ctrl-W, to cut the word on the left side of the cursor (is there a corresponding "cut word on right side"?), and then Ctrl-Y to paste somewhere else. - Then we have the X clipboard, which is setup as follows (I don't know where the names pbcopy and pbpaste come from, but I have seen these names dozens of times, so it seems a lot of people use that nomenclature for some reason):
sudo apt install xclip xsel
alias pbcopy='xclip -selection clipboard'      # To use xclip for copy
alias pbpaste='xclip -selection clipboard -o'  # To use xclip for paste
alias pbcopy='xsel --clipboard --input'        # To use xsel for copy
alias pbpaste='xsel --clipboard --output'      # To use xsel for paste
- Then, additionally, if you are on WSL, there is a third clipboard, from Windows, which you can send to quite simply, e.g. echo 123 | clip.exe. To do the reverse, and paste into the WSL console, you can use powershell.exe -noprofile Get-Clipboard > file.txt. It would be be good to completely control how information is sent/retrieved from these various clipboards easily. - I can pipe information into the X clipboard (with xclip and xsel), but I have not found a way to pipe things into the bash buffer; how do we pipe into the bash buffer programmatically? - How can I pipe something into all 4 clipboards (assuming that xclip and xsel are independent?) from one output in single command (I seem to remember that tee can do this, but not certain)? By knowing this, I would then be able to send receive information from any of the 4 clipboards.
echo 123 |
For reference, though does not answer the above. https://stackoverflow.com/questions/5130968/how-can-i-copy-the-output-of-a-command-directly-into-my-clipboard
YorSubs (661 rep)
Oct 13, 2021, 11:05 AM • Last activity: Oct 14, 2021, 08:22 AM
1 votes
1 answers
475 views
How to avoid xsel sending text to clipboard with space/Enter at the end
I am trying to answer this other question: [Command/script to start a terminal, enter text but don't execute...](https://unix.stackexchange.com/q/644117/341192). I want to start the terminal and add specific text to it **without executing**, thus allowing me to copy some other variable text to it be...
I am trying to answer this other question: [Command/script to start a terminal, enter text but don't execute...](https://unix.stackexchange.com/q/644117/341192) . I want to start the terminal and add specific text to it **without executing**, thus allowing me to copy some other variable text to it before executing. It's like when pasting sudo apt install mpv into terminal without space at the end: the command will not start, but allow for example to add other programs to be installed. I have come close to a solution with xsel, which can send a command to terminal with a shortcut. The commands to be used can be something like bash -c "xsel -ib <<< 'MY_TEXT'" or bash -c "xsel -p <<< 'MY_TEXT'" Thus, I can send that text to clipboard with one shortcut, open terminal with another shortcut, then paste what xsel has copied to clipboard. The problem is that the xsel command sends to clipboard the text with a space or Enter at the end enter image description here It's `MY_TEXT instead of MY_TEXT` It's like the difference between `sudo apt install mpv which automatically runs the installation command and sudo apt install mpv` that waits for me to press enter.
cipricus (1779 rep)
Apr 8, 2021, 02:31 PM • Last activity: Apr 8, 2021, 02:58 PM
3 votes
1 answers
1477 views
Copying text with Ctrl + C when the Zsh line editor is active
I've added some keyboard shortcuts in my Zsh to enable selecting words. In order for the selection to do something, I would like to use `Ctrl + C` to copy it. However I would also like to use `Ctrl + C` to interrupt programs, when the Zsh Line Editor (ZLE) isn't active. Is this possible and how can...
I've added some keyboard shortcuts in my Zsh to enable selecting words. In order for the selection to do something, I would like to use Ctrl + C to copy it. However I would also like to use Ctrl + C to interrupt programs, when the Zsh Line Editor (ZLE) isn't active. Is this possible and how can I do this? I tried to declare a function TRAPINT to hook Ctrl + C, however when I'm in the ZLE and hit Ctrl + C, this function doesn't appear to be called.
simonzack (752 rep)
Feb 16, 2021, 11:55 AM • Last activity: Feb 19, 2021, 03:37 AM
3 votes
1 answers
1793 views
zsh - optimize copy, cut, paste using ctrl+c, ctrl+x, ctrl+v
I am using the following config in my `.zshrc`. if [[ -t 0 && $- = *i* ]] then # change Ctrl+C to Ctrl+I stty start '' stty stop '' stty quit '' stty erase '' stty kill '' stty eof '' # Ctrl + D stty rprnt '' stty werase '' stty lnext '' stty discard '' fi # change Ctrl+C to Ctrl+Q stty intr '^q' #...
I am using the following config in my .zshrc. if [[ -t 0 && $- = *i* ]] then # change Ctrl+C to Ctrl+I stty start '' stty stop '' stty quit '' stty erase '' stty kill '' stty eof '' # Ctrl + D stty rprnt '' stty werase '' stty lnext '' stty discard '' fi # change Ctrl+C to Ctrl+Q stty intr '^q' # change Ctrl+z to Ctrl+j stty susp '^j' # change Ctrl+V to Ctrl+K bindkey '^k' quoted-insert # for zle _copy-using-xsel() { if ((REGION_ACTIVE)) then zle copy-region-as-kill printf "$CUTBUFFER" | xsel -i --clipboard ((REGION_ACTIVE = 0)) fi } zle -N _copy-using-xsel bindkey '^C' _copy-using-xsel # Copy text _cut-using-xsel() { if ((REGION_ACTIVE)) then zle copy-region-as-kill printf "$CUTBUFFER" | xsel -i --clipboard zle kill-region fi } zle -N _cut-using-xsel bindkey '^X' _cut-using-xsel # Cut text _paste-copy-using-xsel() { LBUFFER+="$(xsel -b -o)" } zle -N _paste-copy-using-xsel bindkey '^V' _paste-copy-using-xsel # Paste It enables me to copy using ctrl+c, cut using ctrl+x, paste using ctrl+v. However, I noticed that the operations are slow. I mean it appears to me that, it takes half a second to cut. Is it due to the use of xsel? How can I optimize my keybindings so that the lag is gone.
Ahmad Ismail (2998 rep)
Aug 16, 2020, 08:21 AM • Last activity: Aug 16, 2020, 04:51 PM
0 votes
1 answers
115 views
Yank trimmed string in tmux copy mode
I am trying to yank string without trailing and heading spaces using this keybinding: bind-key -T copy-mode-vi z send-keys -X \ copy-pipe 'sed "s/^[[:blank:]]\+//;s/[[:blank:]]\+$//" | xsel -ib' But it doesn't work, `xsel -ob` outputs string with spaces. So does Ctrl+V in GUI applications. Why? How...
I am trying to yank string without trailing and heading spaces using this keybinding: bind-key -T copy-mode-vi z send-keys -X \ copy-pipe 'sed "s/^[[:blank:]]\+//;s/[[:blank:]]\+$//" | xsel -ib' But it doesn't work, xsel -ob outputs string with spaces. So does Ctrl+V in GUI applications. Why? How can I achieve desired functionality? tmux 2.6, set-clipboard off **EDIT**: I've tested my sed expression and it works: igor@igor-ideapad:~$ echo " hello world " | sed "s/^[[:blank:]]\+//;s/[[:blank:]]\+$//" hello world
vatosarmat (252 rep)
Feb 15, 2020, 11:51 AM • Last activity: Feb 15, 2020, 02:30 PM
1 votes
1 answers
311 views
How to get clipboard as input file name to Vim on bash?
I install `xclip` to access system clipboard, my setting and some operations as below: ➜ ~ cat .zshrc | grep xclip alias c="xclip -selection c" alias v="xclip -selection c -o" ➜ ~ which dict | c ➜ ~ v /usr/bin/dict ➜ ~ sudo vim ?? `/usr/bin/dict` is a python script. And what I want to know is what c...
I install xclip to access system clipboard, my setting and some operations as below: ➜ ~ cat .zshrc | grep xclip alias c="xclip -selection c" alias v="xclip -selection c -o" ➜ ~ which dict | c ➜ ~ v /usr/bin/dict ➜ ~ sudo vim ?? /usr/bin/dict is a python script. And what I want to know is what can substitute ?? on my last command can use vim open file /usr/bin/dict?
roachsinai (326 rep)
Jan 8, 2019, 08:20 AM • Last activity: Jan 8, 2019, 08:33 AM
8 votes
2 answers
1577 views
To which stream does xsel print the no newline warning?
xsel is a program with which you can access system clipboard from command line. If there is no newline at the end of copied content, it prints a warning after the clipboard content like this: $ xsel -b copied text \ No newline at end of selection Earlier I used to think that this warning is printed...
xsel is a program with which you can access system clipboard from command line. If there is no newline at the end of copied content, it prints a warning after the clipboard content like this: $ xsel -b copied text \ No newline at end of selection Earlier I used to think that this warning is printed to the standard error, but today I found that the warning is not there even if the standard error is merged with the standard output.xsel-b |& less just prints the copied text, without the warning. Why does it behave like this?
saga (1411 rep)
Jan 13, 2017, 03:16 PM • Last activity: Dec 16, 2018, 03:09 PM
18 votes
2 answers
6940 views
`tee` for commands
`tee` can redirect the piped standard input into the standard output **and** file. echo Hello, World! | tee greeting.txt The command above would display the greeting on the terminal screen and save it in the contents of `greeting.txt` file, creating the file if there's none by that name. There's als...
tee can redirect the piped standard input into the standard output **and** file. echo Hello, World! | tee greeting.txt The command above would display the greeting on the terminal screen and save it in the contents of greeting.txt file, creating the file if there's none by that name. There's also -a switch for tee to append to the existing file instead of overwriting. --- Is there a convenient way to redirect the piped input to the command and **standard output** instead of file? I am trying to create a wrapper script for [buku](https://github.com/jarun/Buku) to copy to primary selection the URL of the bookmark specified by its index number. # bukuc: #!/bin/sh url=$(buku -f 1 -p $1 | cut -f 2) # NUMBER : URL echo $url # DISPLAY echo $url | xsel # PRIMARY SELECTION Here I use echo **two** times, first for displaying on the terminal, and then saving in the primary selection (clipboard). I imagine something of echo $url | teeC xsel or a shortcut to display the output before passing to the next command (chaining commands), what would allow me to chain the whole command in one line without the need to save the result in a **variable** as follows: buku -f 1 -p $1 | cut -f 2 | teeC xsel --- I can also use it with [urlview](https://github.com/sigpipe/urlview) to view, select, and open with the $BROWSER as follows: bukuc 10-20 | urlview
user86041
Jun 17, 2017, 06:56 PM • Last activity: Jun 17, 2017, 11:11 PM
3 votes
1 answers
165 views
Piping search term from clipboard (not filename) to grep to search a folder
I am trying to use `xsel` clipboard to pipe search term to `grep` to search in folder full of txt files. Can anybody suggest a method to do it.
I am trying to use xsel clipboard to pipe search term to grep to search in folder full of txt files. Can anybody suggest a method to do it.
Ramaprakasha (205 rep)
Apr 26, 2017, 09:11 AM • Last activity: Apr 26, 2017, 10:38 AM
-3 votes
1 answers
1467 views
Do xsel and xclip work only for copy and not for paste?
The usages of `xsel` and `xclip` seem to me all about the copy operation, whether it is primary or clipboard selection. When I perform the paste operation, is it only by using mouse or trackpad, not via `xsel` and `xclip` again?
The usages of xsel and xclip seem to me all about the copy operation, whether it is primary or clipboard selection. When I perform the paste operation, is it only by using mouse or trackpad, not via xsel and xclip again?
Tim (106420 rep)
Jun 12, 2016, 02:13 PM • Last activity: Jun 12, 2016, 04:37 PM
4 votes
1 answers
326 views
xbindkeys Paste Script is Failing to Work
I'm trying to bind `control + i` to load the contents of `file.txt` to the clipboard (so that I can use `ctrl + v` to paste the contents of `file.txt` into windows like my browser). The following command works perfectly if I manually type it into a bash terminal: `xsel --clipboard < /home/paul/Dropb...
I'm trying to bind control + i to load the contents of file.txt to the clipboard (so that I can use ctrl + v to paste the contents of file.txt into windows like my browser). The following command works perfectly if I manually type it into a bash terminal: xsel --clipboard < /home/paul/Dropbox/file.txt However, when I try to use xbindkeys to do it, it does not. This is what I have in my xbindkeys config: "xsel --clipboard < /home/paul/Dropbox/file.txt" control + i What could be causing this problem?
PP1211 (41 rep)
Oct 16, 2015, 07:07 PM • Last activity: Oct 28, 2015, 08:33 AM
1 votes
2 answers
335 views
Can I pipe clipboard content to browser for viewing?
Here is the situation. I often have to read chunks of information from large plain text files. I am planning to use [Readability][1] extension for formating the content to make it readable on screen. [1]: https://www.readability.com/addons/
Here is the situation. I often have to read chunks of information from large plain text files. I am planning to use Readability extension for formating the content to make it readable on screen.
Ramaprakasha (205 rep)
Sep 2, 2015, 06:29 AM • Last activity: Sep 3, 2015, 01:25 AM
Showing page 1 of 20 total questions