2022-01-13 18:23:21 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
def qute(cmd):
|
|
|
|
with open(os.environ['QUTE_FIFO'], 'w') as fifo:
|
|
|
|
fifo.write(cmd)
|
|
|
|
fifo.write('\n')
|
|
|
|
fifo.flush()
|
|
|
|
|
|
|
|
def error(msg):
|
|
|
|
print(msg, file=sys.stderr)
|
|
|
|
qute('message-error "{}"'.format(msg))
|
|
|
|
|
|
|
|
def parse_args():
|
2023-10-29 12:05:53 +00:00
|
|
|
parser = argparse.ArgumentParser(description="Clear URL and yank to clipboard")
|
2022-01-13 18:23:21 +00:00
|
|
|
parser.add_argument('--selection', '-s', action='store_true',
|
|
|
|
help='Yank to selection')
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if 'QUTE_FIFO' not in os.environ:
|
|
|
|
print(f"No QUTE_FIFO found - {sys.argv[0]} must be run as a qutebrowser userscript")
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
args = parse_args()
|
|
|
|
|
|
|
|
url = os.environ['QUTE_URL']
|
|
|
|
|
2022-03-19 10:33:43 +00:00
|
|
|
try:
|
|
|
|
import unalix
|
|
|
|
url = unalix.clear_url(url)
|
|
|
|
except:
|
|
|
|
pass
|
2022-01-13 18:23:21 +00:00
|
|
|
|
|
|
|
if args.selection:
|
2022-03-19 10:33:43 +00:00
|
|
|
qute('yank inline "{}" -s'.format(url))
|
2022-01-13 18:23:21 +00:00
|
|
|
else:
|
2022-03-19 10:33:43 +00:00
|
|
|
qute('yank inline "{}"'.format(url))
|
2022-01-13 18:23:21 +00:00
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
error(str(e))
|