Last active
October 19, 2023 09:17
-
-
Save manero6/87436287a64f32032f0b8d66aad35a23 to your computer and use it in GitHub Desktop.
simple script based on xclip to filter out stuff from the clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# put current clipboard in a variable | |
XCLIP_CLIPBOARD="$(xclip -o -selection clipboard)" | |
XCLIP_SELECTION=$XCLIP_CLIPBOARD | |
if [ $# -ge 1 ] | |
then | |
# print the initial string aka the current clipboard | |
echo "=> 1st string: $XCLIP_CLIPBOARD" | |
echo | |
# Double quotes on "$@" are needed, else strings like 'a ' will be filtered as 'a' | |
for FILTER in "$@" | |
do | |
echo "=> filter out: '$FILTER'" | |
echo "=> old string: '$XCLIP_SELECTION'" | |
# filtering stuff out the bash way | |
XCLIP_SELECTION="${XCLIP_SELECTION/$FILTER/}" | |
echo "=> new string: '$XCLIP_SELECTION'" | |
echo | |
done | |
# copy the result to selection | |
xclip <<< "$XCLIP_SELECTION" | |
echo "=> clipboard: '$XCLIP_CLIPBOARD'" | |
echo "=> selection: '$XCLIP_SELECTION'" | |
else | |
echo "=> Please provide at least one string to filter out!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initial string:
Filtering out strings:
After that printing
xclip
clipboard (which should remain unchanged) and selection (which should contain the final filtered string)