Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Watch for regex match and run shell command when match found #34

Open
devtweakr opened this issue Oct 28, 2023 · 3 comments

Comments

@devtweakr
Copy link

So, when there is a regex match of copied text it would automatically run a shell command.

Example: Whenever an URL is copied and "http.*" is found it would automatically run my script to open url in firefox

#!/bin/bash url=$(xclip -selection clipboard -o) firefox $url

Is it possible to add such feature?
I haven't yet seen any of clipboard extensions with such functionality.

@joelpurra
Copy link
Collaborator

@devtweakr: how about just using another command line utility instead of relying a full-featured Gnome Shell Extension with all (GUI) dependencies that implies?

A quick search yielded clipnotify which might work like this:

url_matcher='^http'

while clipnotify -s clipboard;
do
	clipboard_selection="$(xclip -selection clipboard -out)"
	if [[ $clipboard_selection =~ $url_matcher ]];
	then
		firefox "$clipboard_selection"
	fi
done

That bash snippet was written on the fly and is completely untested, so take it with a grain of salt.

@devtweakr
Copy link
Author

yep, did just that
little check to skip last url

#!/bin/bash

last_url=""
while true; do
    clipboard=$(xclip -selection clipboard -o)
    regex_pattern="^https?"
    if [[ $clipboard =~ $regex_pattern && "$clipboard" != "$last_url" ]]; then
        last_url=$clipboard
        firefox "$clipboard" &
    fi
    sleep 1
done

@b00f
Copy link
Owner

b00f commented Oct 29, 2023

it would automatically run my script to open url in firefox

This can raise security concerns.
This extension is designed to be simple and perform just one task: managing the clipboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants