Skip to content

Commit 0924e44

Browse files
Ronnie76erflashcode
authored andcommitted
urlgrab.py 3.1: store urls by buffer full_name
This adds an option to store URLs by the full_name of the buffer, rather than the short_name or name that is currently the default. This fixes an issue that I had directly, where some buffers would (frequently) get typing indicators at the short name, thus storing the URL under `>general` instead of `#general`. This would break trying to open URLs by index in the channel. This should also address issue weechat#90, as the full name should contain the network information in it. There is also a small linting cleanup, using `completion_list_add` and fixing the weechat URLs
1 parent 1a0c26d commit 0924e44

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

python/urlgrab.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,20 @@
6262
# The file where the command output (if any) is saved. Overwritten
6363
# each time you launch a new URL. Default is ~/.weechat/urllaunch.log
6464
#
65+
# use_full_name
66+
# Whether or not to use the buffer's full name to store the URL. This can
67+
# help if you have such issues as URLs getting saved under buffers that
68+
# have a typing indicator active, or you have the same channel name in
69+
# two different networks.
70+
#
6571
# default
6672
# The command that will be run if no arguemnts to /url are given.
6773
# Default is show
6874
#
6975
# Requirements:
7076
#
7177
# - Designed to run with weechat version 0.3 or better.
72-
# http://www.weechat.org/
78+
# https://weechat.org/
7379
#
7480
# Acknowlegements:
7581
#
@@ -125,6 +131,8 @@
125131
# - Updated script for python3 support (now python2 and 3 are both supported)
126132
# - V3.0 Sébastien Helleu <[email protected]>:
127133
# - Fix python 3 compatibility (replace "has_key" by "in")
134+
# - V3.1 Ron Alleva <[email protected]>:
135+
# - Add 'use_full_name' setting, to allow storing URLs by full name of buffer
128136
#
129137
# Copyright (C) 2005 David Rubin <drubin AT smartcube dot co dot za>
130138
#
@@ -152,7 +160,7 @@
152160
import_ok = True
153161
except:
154162
print("This script must be run under WeeChat.")
155-
print("Get WeeChat now at: http://www.weechat.org/")
163+
print("Get WeeChat now at: https://weechat.org")
156164
import_ok = False
157165
import subprocess
158166
import time
@@ -177,7 +185,7 @@
177185

178186
SCRIPT_NAME = "urlgrab"
179187
SCRIPT_AUTHOR = "David Rubin <drubin [At] smartcube [dot] co [dot] za>"
180-
SCRIPT_VERSION = "3.0"
188+
SCRIPT_VERSION = "3.1"
181189
SCRIPT_LICENSE = "GPL"
182190
SCRIPT_DESC = "Url functionality Loggin, opening of browser, selectable links"
183191
CONFIG_FILE_NAME= "urlgrab"
@@ -203,7 +211,9 @@ def urlGrabPrint(message):
203211
weechat.prnt(bufferd,"[%s] %s" % ( SCRIPT_NAME, message ) )
204212

205213
def hashBufferName(bufferp):
206-
if not weechat.buffer_get_string(bufferp, "short_name"):
214+
if(urlGrabSettings['use_full_name']):
215+
bufferd = weechat.buffer_get_string(bufferp, "full_name")
216+
elif not weechat.buffer_get_string(bufferp, "short_name"):
207217
bufferd = weechat.buffer_get_string(bufferp, "name")
208218
else:
209219
bufferd = weechat.buffer_get_string(bufferp, "short_name")
@@ -298,6 +308,13 @@ def __init__(self):
298308
"remotecmd", "string", remotecmd, "", 0, 0,
299309
remotecmd, remotecmd, 0, "", "", "", "", "", "")
300310

311+
self.data['use_full_name']=weechat.config_new_option(
312+
self.config_file, section_default,
313+
"use_full_name", "boolean",
314+
"""Use full name of buffer to store URL""", "", 0, 0,
315+
"0", "0", 0, "", "", "", "", "", ""
316+
)
317+
301318
self.data['url_log']=weechat.config_new_option(
302319
self.config_file, section_default,
303320
"url_log", "string", """log location""", "", 0, 0,
@@ -320,6 +337,8 @@ def __getitem__(self, key):
320337
return weechat.config_integer(self.data[key])
321338
elif key == 'output_main_buffer':
322339
return weechat.config_boolean(self.data[key])
340+
elif key == 'use_full_name':
341+
return weechat.config_boolean(self.data[key])
323342
#elif key.startswith('color'):
324343
# return weechat.config_color(self.data[key])
325344
else:
@@ -664,7 +683,7 @@ def completion_urls_cb(data, completion_item, bufferp, completion):
664683
bufferd = hashBufferName( bufferp)
665684
for url in urlGrab.globalUrls :
666685
if url['buffer'] == bufferd:
667-
weechat.hook_completion_list_add(completion, url['url'], 0, weechat.WEECHAT_LIST_POS_SORT)
686+
weechat.completion_list_add(completion, url['url'], 0, weechat.WEECHAT_LIST_POS_SORT)
668687
return weechat.WEECHAT_RC_OK
669688

670689
def ug_unload_script():

0 commit comments

Comments
 (0)