Yes, sure - there is PRIMARY
selection in X11.
PRIMARY selection, is used when the user selects some data. X Window: Clipboard
You can use either xsel
or xclip
cli tools:
TL;DR
- Select some text
2a. grep "$(xsel)" -r -C 30 -h ~/helpfiles/*
OR
2b. grep "$(xclip -o)" -r -C 30 -h ~/helpfiles/*
Precondition
xsel
or xclip
package installed: apt get install xsel
or apt get install xclip
X
server is running (i.e. you use X server, not text-mode without X server): xset q > /dev/null && echo "X is running" || echo "start X server"
Explanation
Both xsel
and xclip
are clipboard management tools. Commands xsel
and xclip -o
print to STDOUT
contents of PRIMARY
selection.
More info you can find here: 'xclip' vs. 'xsel'
Use double quotes around $()
. This allows to highlight more than 1 word.