📜 ⬆️ ⬇️

Multiple clipboards in Linux

I wanted to make it so that hotkeys could save the selected text in several different clipboards. And then also hotkeys insert text from there ..

For this we need xsel and xbindkeys :

sudo apt-get install xsel xbindkeys


Then we create a script that will save the selected text to files (clip-1, clip-2, etc.) or extract the text from the files to the clipboard and press Ctrl + V
')
gedit ~ / bin / st-clip


File Contents:

#!/bin/bash

if [[ $# -lt 2 ]]; then
echo "Usage: $0 (save|load) NUM"
exit 1
fi

op=$1
num=$2

DIR=$HOME/.clips
FILE=$DIR/clip-$num

if [ ! -e "$DIR" ]
then
mkdir -p "$DIR"
chmod 700 $DIR
fi

case "$op" in
"save" )
xsel -o > $FILE
;;
"load" )
cat $FILE | xsel --clipboard -i
xvkbd -xsendevent -text "\[Control_L]\[v]"
;;
*)
echo "Wrong operation. Allowed \" save\ " and \" load\ "."
exit 1
esac


* This source code was highlighted with Source Code Highlighter .



Making the script executable:

chmod + x ~ / bin / st-clip


The script takes two arguments:
  1. save or load - save the clipboard or load it
  2. any number to save to different files



Add to the configuration file xbindkeys:

gedit ~ / .xbindkeysrc


"St-clip save 1"
Control + Alt + 1
"St-clip load 1"
Control + Shift + 1

"St-clip save 2"
Control + Alt + 2
"St-clip load 2"
Control + Shift + 2

"St-clip save 3"
Control + Alt + 3
"St-clip load 3"
Control + Shift + 3


Now when you press Ctrl + Alt + 1..3, the selected text is saved under different numbers (1..3), and when you press Ctrl + Shift + 1..3, the saved text under the number 1..3 is inserted accordingly

I hope someone else can come in handy :)

Source: https://habr.com/ru/post/49939/


All Articles