-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipboard-filter
executable file
·30 lines (25 loc) · 1.1 KB
/
clipboard-filter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env fish
# clipboard-filter - Automatically apply edits when the clipboard is modified.
# By default, the only edits this makes are to remove YouTube's &pp= tracking parameters from URLs, but it should be pretty easy to add your own.
# requirements: copyevent, xsel
# will work with clipnotify once 2.0 is released; see https://github.com/cdown/clipnotify/issues/19#issuecomment-1304954434
set -- script "$(path basename (status filename))"
argparse -n $script 'h/help' -- $argv
if set -q _flag_h
echo "$script - Automatically apply edits when the clipboard is modified."
echo "Usage: $script [arguments]"
echo
echo " -h/--help - Print help and exit."
exit
end
function replace-clipboard -d "Replace the contents of the clipboard."
xsel --delete --clipboard
printf '%s' "$argv[1]" | xsel --clipboard
end
while copyevent -s clipboard
set text (xsel --clipboard)
if string match --quiet --regex -- '(?<youtube>https?:/+(www\.)youtube\.com/.+?)&pp=[^&]+(?<suffix>.*)$' $text
# Remove &pp= (user tracking) from YouTube URLs.
replace-clipboard "$youtube"
end
end