my shell and tool configurations

looooots of weechat

+2364 -27
+1 -1
Makefile
··· 47 47 vim: 48 48 @printf "$(YELLOW)--- vim ------------------------------------------------\n$(RESET)" 49 49 stow -t "$$HOME" vim 50 - [[ -f ~/.spf13-vim/bootstrap.sh ]] || 50 + [[ -f ~/.spf13-vim/bootstrap.sh ]] || \ 51 51 git submodule update --init 52 52 ~/.spf13-vim/bootstrap.sh 53 53
+31
fish/.config/fish/fishd.slash
··· 1 + # This file is automatically generated by the fish. 2 + # Do NOT edit it directly, your changes will be overwritten. 3 + SET __fish_init_2_39_8:\x1d 4 + SET __fish_init_2_3_0:\x1d 5 + SET fish_color_autosuggestion:555\x1ebrblack 6 + SET fish_color_cancel:\x2dr 7 + SET fish_color_command:\x2d\x2dbold 8 + SET fish_color_comment:red 9 + SET fish_color_cwd:green 10 + SET fish_color_cwd_root:red 11 + SET fish_color_end:brmagenta 12 + SET fish_color_error:brred 13 + SET fish_color_escape:bryellow\x1e\x2d\x2dbold 14 + SET fish_color_history_current:\x2d\x2dbold 15 + SET fish_color_host:normal 16 + SET fish_color_match:\x2d\x2dbackground\x3dbrblue 17 + SET fish_color_normal:normal 18 + SET fish_color_operator:bryellow 19 + SET fish_color_param:cyan 20 + SET fish_color_quote:yellow 21 + SET fish_color_redirection:brblue 22 + SET fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack 23 + SET fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack 24 + SET fish_color_user:brgreen 25 + SET fish_color_valid_path:\x2d\x2dunderline 26 + SET fish_greeting:Welcome\x20to\x20fish\x2c\x20the\x20friendly\x20interactive\x20shell 27 + SET fish_key_bindings:fish_default_key_bindings 28 + SET fish_pager_color_completion:\x1d 29 + SET fish_pager_color_description:B3A06D\x1eyellow 30 + SET fish_pager_color_prefix:white\x1e\x2d\x2dbold\x1e\x2d\x2dunderline 31 + SET fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan
+1
weechat/.weechat/.gitignore
··· 3 3 sec.conf 4 4 script/plugins.xml.gz 5 5 weechat_fifo 6 + *.pem 6 7
+22
weechat/.weechat/autosort.conf
··· 1 + # 2 + # weechat -- autosort.conf 3 + # 4 + # WARNING: It is NOT recommended to edit this file by hand, 5 + # especially if WeeChat is running. 6 + # 7 + # Use /set or similar command to change settings in WeeChat. 8 + # 9 + # For more info, see: https://weechat.org/doc/quickstart 10 + # 11 + 12 + [sorting] 13 + case_sensitive = off 14 + replacements = "" 15 + rules = "" 16 + signal_delay = 5 17 + signals = "buffer_opened buffer_merged buffer_unmerged buffer_renamed" 18 + sort_on_config_change = on 19 + 20 + [v3] 21 + helpers = "{"core_first": "${if:${buffer.full_name}!=core.weechat}", "irc_raw_last": "${if:${buffer.full_name}==irc.irc_raw}", "irc_last": "${if:${buffer.plugin.name}==irc}", "hashless_name": "${info:autosort_replace,#,,${buffer.name}}", "irc_first": "${if:${buffer.plugin.name}!=irc}", "irc_raw_first": "${if:${buffer.full_name}!=irc.irc_raw}"}" 22 + rules = "["${core_first}", "${irc_last}", "${buffer.plugin.name}", "${irc_raw_first}", "${if:${plugin}==irc?${server}}", "${if:${plugin}==irc?${info:autosort_order,${type},server,*,channel,private}}", "${if:${plugin}==irc?${hashless_name}}", "${buffer.full_name}"]"
+20
weechat/.weechat/colorize_nicks.conf
··· 1 + # 2 + # weechat -- colorize_nicks.conf 3 + # 4 + # WARNING: It is NOT recommended to edit this file by hand, 5 + # especially if WeeChat is running. 6 + # 7 + # Use /set or similar command to change settings in WeeChat. 8 + # 9 + # For more info, see: https://weechat.org/doc/quickstart 10 + # 11 + 12 + [look] 13 + blacklist_channels = "" 14 + blacklist_nicks = "so,root" 15 + colorize_input = off 16 + greedy_matching = on 17 + ignore_nicks_in_urls = off 18 + ignore_tags = "" 19 + match_limit = 20 20 + min_nick_length = 2
+338 -10
weechat/.weechat/irc.conf
··· 129 129 msg_kick = "" 130 130 msg_part = "WeeChat ${info:version}" 131 131 msg_quit = "WeeChat ${info:version}" 132 - nicks = "ben,ben1,ben2,ben3,ben4" 132 + nicks = "ben,benharri,ben2,ben3,ben4" 133 133 nicks_alternate = on 134 134 notify = "" 135 135 password = "" ··· 164 164 tilde.password 165 165 tilde.capabilities 166 166 tilde.sasl_mechanism 167 - tilde.sasl_username 168 - tilde.sasl_password 167 + tilde.sasl_username = "ben" 168 + tilde.sasl_password = "${sec.data.pass}" 169 169 tilde.sasl_key 170 170 tilde.sasl_timeout 171 171 tilde.sasl_fail ··· 175 175 tilde.nicks 176 176 tilde.nicks_alternate 177 177 tilde.username 178 - tilde.realname 178 + tilde.realname = "Ben Harris" 179 179 tilde.local_hostname 180 180 tilde.usermode 181 - tilde.command 181 + tilde.command = "/msg nickserv identify ${sec.data.pass}; /oper root ${sec.data.tildenetoper}; /msg operserv login ${sec.data.pass}" 182 182 tilde.command_delay 183 - tilde.autojoin = "#meta,#team,#sudoers,#yourtilde,#chaos" 183 + tilde.autojoin = "#meta,#team,#sudoers,#yourtilde,#chaos,#town,#bots,#music,#share,#stevenuniverse,#suwp,#projects,#zccount,#politics,#dnd,#journal,#shitposting,#quotes,#gopher,#tildeverse,#venting,#idlerpg" 184 184 tilde.autorejoin 185 185 tilde.autorejoin_delay 186 186 tilde.connection_timeout ··· 197 197 hashbang.proxy 198 198 hashbang.ipv6 199 199 hashbang.ssl = on 200 - hashbang.ssl_cert 200 + hashbang.ssl_cert = "%h/ssl/benharri.pem" 201 201 hashbang.ssl_priorities 202 202 hashbang.ssl_dhkey_size 203 203 hashbang.ssl_fingerprint ··· 213 213 hashbang.autoconnect 214 214 hashbang.autoreconnect 215 215 hashbang.autoreconnect_delay 216 - hashbang.nicks 216 + hashbang.nicks = "benharri" 217 217 hashbang.nicks_alternate 218 218 hashbang.username 219 - hashbang.realname 219 + hashbang.realname = "Ben Harris" 220 220 hashbang.local_hostname 221 221 hashbang.usermode 222 - hashbang.command 222 + hashbang.command = "/oper benharri x" 223 223 hashbang.command_delay 224 224 hashbang.autojoin 225 225 hashbang.autorejoin ··· 234 234 hashbang.msg_quit 235 235 hashbang.notify 236 236 hashbang.split_msg_max_length 237 + town.addresses = "localhost/2345" 238 + town.proxy 239 + town.ipv6 240 + town.ssl 241 + town.ssl_cert 242 + town.ssl_priorities 243 + town.ssl_dhkey_size 244 + town.ssl_fingerprint 245 + town.ssl_verify 246 + town.password 247 + town.capabilities 248 + town.sasl_mechanism 249 + town.sasl_username 250 + town.sasl_password 251 + town.sasl_key 252 + town.sasl_timeout 253 + town.sasl_fail 254 + town.autoconnect 255 + town.autoreconnect 256 + town.autoreconnect_delay 257 + town.nicks = "benharri" 258 + town.nicks_alternate 259 + town.username = "benharri" 260 + town.realname 261 + town.local_hostname 262 + town.usermode 263 + town.command 264 + town.command_delay 265 + town.autojoin 266 + town.autorejoin 267 + town.autorejoin_delay 268 + town.connection_timeout 269 + town.anti_flood_prio_high 270 + town.anti_flood_prio_low 271 + town.away_check 272 + town.away_check_max_nicks 273 + town.msg_kick 274 + town.msg_part 275 + town.msg_quit 276 + town.notify 277 + town.split_msg_max_length 278 + esper.addresses = "irc.esper.net/6697" 279 + esper.proxy 280 + esper.ipv6 281 + esper.ssl = on 282 + esper.ssl_cert 283 + esper.ssl_priorities 284 + esper.ssl_dhkey_size 285 + esper.ssl_fingerprint 286 + esper.ssl_verify 287 + esper.password 288 + esper.capabilities 289 + esper.sasl_mechanism 290 + esper.sasl_username 291 + esper.sasl_password = "${sec.data.pass}" 292 + esper.sasl_key 293 + esper.sasl_timeout 294 + esper.sasl_fail 295 + esper.autoconnect 296 + esper.autoreconnect 297 + esper.autoreconnect_delay 298 + esper.nicks = "benharri" 299 + esper.nicks_alternate 300 + esper.username = "benharri" 301 + esper.realname = "benharri" 302 + esper.local_hostname 303 + esper.usermode 304 + esper.command = "/msg nickserv identify ${sec.data.pass}" 305 + esper.command_delay 306 + esper.autojoin = "#lobby,#coders" 307 + esper.autorejoin 308 + esper.autorejoin_delay 309 + esper.connection_timeout 310 + esper.anti_flood_prio_high 311 + esper.anti_flood_prio_low 312 + esper.away_check 313 + esper.away_check_max_nicks 314 + esper.msg_kick 315 + esper.msg_part 316 + esper.msg_quit 317 + esper.notify 318 + esper.split_msg_max_length 319 + sdf.addresses = "irc.sdf.org" 320 + sdf.proxy 321 + sdf.ipv6 322 + sdf.ssl 323 + sdf.ssl_cert 324 + sdf.ssl_priorities 325 + sdf.ssl_dhkey_size 326 + sdf.ssl_fingerprint 327 + sdf.ssl_verify 328 + sdf.password 329 + sdf.capabilities 330 + sdf.sasl_mechanism 331 + sdf.sasl_username 332 + sdf.sasl_password 333 + sdf.sasl_key 334 + sdf.sasl_timeout 335 + sdf.sasl_fail 336 + sdf.autoconnect 337 + sdf.autoreconnect 338 + sdf.autoreconnect_delay 339 + sdf.nicks = "benharri" 340 + sdf.nicks_alternate 341 + sdf.username = "benharri" 342 + sdf.realname = "Ben Harris" 343 + sdf.local_hostname 344 + sdf.usermode 345 + sdf.command 346 + sdf.command_delay 347 + sdf.autojoin = "#sdf,#gopher" 348 + sdf.autorejoin 349 + sdf.autorejoin_delay 350 + sdf.connection_timeout 351 + sdf.anti_flood_prio_high 352 + sdf.anti_flood_prio_low 353 + sdf.away_check 354 + sdf.away_check_max_nicks 355 + sdf.msg_kick 356 + sdf.msg_part 357 + sdf.msg_quit 358 + sdf.notify 359 + sdf.split_msg_max_length 360 + darwin.addresses = "irc.darwin.network/6697" 361 + darwin.proxy 362 + darwin.ipv6 363 + darwin.ssl = on 364 + darwin.ssl_cert 365 + darwin.ssl_priorities 366 + darwin.ssl_dhkey_size 367 + darwin.ssl_fingerprint 368 + darwin.ssl_verify 369 + darwin.password = "${sec.data.darwin}" 370 + darwin.capabilities 371 + darwin.sasl_mechanism 372 + darwin.sasl_username 373 + darwin.sasl_password 374 + darwin.sasl_key 375 + darwin.sasl_timeout 376 + darwin.sasl_fail 377 + darwin.autoconnect 378 + darwin.autoreconnect 379 + darwin.autoreconnect_delay 380 + darwin.nicks 381 + darwin.nicks_alternate 382 + darwin.username 383 + darwin.realname 384 + darwin.local_hostname 385 + darwin.usermode 386 + darwin.command 387 + darwin.command_delay 388 + darwin.autojoin = "#darwin" 389 + darwin.autorejoin 390 + darwin.autorejoin_delay 391 + darwin.connection_timeout 392 + darwin.anti_flood_prio_high 393 + darwin.anti_flood_prio_low 394 + darwin.away_check 395 + darwin.away_check_max_nicks 396 + darwin.msg_kick 397 + darwin.msg_part 398 + darwin.msg_quit 399 + darwin.notify 400 + darwin.split_msg_max_length 401 + gitter.addresses = "irc.gitter.im/6697" 402 + gitter.proxy 403 + gitter.ipv6 404 + gitter.ssl = on 405 + gitter.ssl_cert 406 + gitter.ssl_priorities 407 + gitter.ssl_dhkey_size 408 + gitter.ssl_fingerprint 409 + gitter.ssl_verify 410 + gitter.password = "323cf7b2994d646e80b261c0d5bc546b766fe0c6" 411 + gitter.capabilities 412 + gitter.sasl_mechanism 413 + gitter.sasl_username 414 + gitter.sasl_password 415 + gitter.sasl_key 416 + gitter.sasl_timeout 417 + gitter.sasl_fail 418 + gitter.autoconnect 419 + gitter.autoreconnect 420 + gitter.autoreconnect_delay 421 + gitter.nicks = "benharri" 422 + gitter.nicks_alternate 423 + gitter.username = "benharri" 424 + gitter.realname = "benharri" 425 + gitter.local_hostname 426 + gitter.usermode 427 + gitter.command 428 + gitter.command_delay 429 + gitter.autojoin 430 + gitter.autorejoin 431 + gitter.autorejoin_delay 432 + gitter.connection_timeout 433 + gitter.anti_flood_prio_high 434 + gitter.anti_flood_prio_low 435 + gitter.away_check 436 + gitter.away_check_max_nicks 437 + gitter.msg_kick 438 + gitter.msg_part 439 + gitter.msg_quit 440 + gitter.notify 441 + gitter.split_msg_max_length 442 + oftc.addresses = "irc.oftc.net/6697" 443 + oftc.proxy 444 + oftc.ipv6 445 + oftc.ssl = on 446 + oftc.ssl_cert 447 + oftc.ssl_priorities 448 + oftc.ssl_dhkey_size 449 + oftc.ssl_fingerprint 450 + oftc.ssl_verify 451 + oftc.password 452 + oftc.capabilities 453 + oftc.sasl_mechanism 454 + oftc.sasl_username = "bhh" 455 + oftc.sasl_password = "${sec.data.pass}" 456 + oftc.sasl_key 457 + oftc.sasl_timeout 458 + oftc.sasl_fail 459 + oftc.autoconnect 460 + oftc.autoreconnect 461 + oftc.autoreconnect_delay 462 + oftc.nicks = "bhh" 463 + oftc.nicks_alternate 464 + oftc.username 465 + oftc.realname = "bhh" 466 + oftc.local_hostname 467 + oftc.usermode 468 + oftc.command = "/msg nickserv identify ${sec.data.pass}" 469 + oftc.command_delay 470 + oftc.autojoin = "#debian,#debian-next,#debian-offtopic,#fish,#moocows,#msys2,#oftc,#suckless" 471 + oftc.autorejoin 472 + oftc.autorejoin_delay 473 + oftc.connection_timeout 474 + oftc.anti_flood_prio_high 475 + oftc.anti_flood_prio_low 476 + oftc.away_check 477 + oftc.away_check_max_nicks 478 + oftc.msg_kick 479 + oftc.msg_part 480 + oftc.msg_quit 481 + oftc.notify 482 + oftc.split_msg_max_length 483 + freenode.addresses = "irc.freenode.net/6697" 484 + freenode.proxy 485 + freenode.ipv6 486 + freenode.ssl = on 487 + freenode.ssl_cert 488 + freenode.ssl_priorities 489 + freenode.ssl_dhkey_size 490 + freenode.ssl_fingerprint 491 + freenode.ssl_verify 492 + freenode.password 493 + freenode.capabilities 494 + freenode.sasl_mechanism 495 + freenode.sasl_username 496 + freenode.sasl_password 497 + freenode.sasl_key 498 + freenode.sasl_timeout 499 + freenode.sasl_fail 500 + freenode.autoconnect 501 + freenode.autoreconnect 502 + freenode.autoreconnect_delay 503 + freenode.nicks = "benharri,bhh" 504 + freenode.nicks_alternate 505 + freenode.username = "benharri" 506 + freenode.realname = "benharri" 507 + freenode.local_hostname 508 + freenode.usermode 509 + freenode.command = "/msg nickserv identify ${sec.data.pass}" 510 + freenode.command_delay 511 + freenode.autojoin = "##oodnet,##tildeverse,#alacritty,#disroot,#fediverse,#irc.net,#litepub,#lobsters,#lobsters-boil,#lxcontainers,#systemd,#thelounge,#gitea,#ipfs,#mailpile,#mastodon,#pleroma,#pleroma-offtopic,#pixelfed,#pixelfed-offtopic,#oragono,##csharp,#manjaro,#vim,#weechat-android" 512 + freenode.autorejoin 513 + freenode.autorejoin_delay 514 + freenode.connection_timeout 515 + freenode.anti_flood_prio_high 516 + freenode.anti_flood_prio_low 517 + freenode.away_check 518 + freenode.away_check_max_nicks 519 + freenode.msg_kick 520 + freenode.msg_part 521 + freenode.msg_quit 522 + freenode.notify 523 + freenode.split_msg_max_length 524 + blackhat.addresses = "breaking.technology/6697" 525 + blackhat.proxy 526 + blackhat.ipv6 527 + blackhat.ssl = on 528 + blackhat.ssl_cert 529 + blackhat.ssl_priorities 530 + blackhat.ssl_dhkey_size 531 + blackhat.ssl_fingerprint 532 + blackhat.ssl_verify 533 + blackhat.password 534 + blackhat.capabilities 535 + blackhat.sasl_mechanism 536 + blackhat.sasl_username 537 + blackhat.sasl_password 538 + blackhat.sasl_key 539 + blackhat.sasl_timeout 540 + blackhat.sasl_fail 541 + blackhat.autoconnect 542 + blackhat.autoreconnect 543 + blackhat.autoreconnect_delay 544 + blackhat.nicks = "no_u" 545 + blackhat.nicks_alternate 546 + blackhat.username = "no_u" 547 + blackhat.realname = "no_u" 548 + blackhat.local_hostname 549 + blackhat.usermode 550 + blackhat.command 551 + blackhat.command_delay 552 + blackhat.autojoin = "#blackhat" 553 + blackhat.autorejoin 554 + blackhat.autorejoin_delay 555 + blackhat.connection_timeout 556 + blackhat.anti_flood_prio_high 557 + blackhat.anti_flood_prio_low 558 + blackhat.away_check 559 + blackhat.away_check_max_nicks 560 + blackhat.msg_kick 561 + blackhat.msg_part 562 + blackhat.msg_quit 563 + blackhat.notify 564 + blackhat.split_msg_max_length
+26
weechat/.weechat/plugins.conf
··· 32 32 python.apply_corrections.print_limit = "1" 33 33 python.autojoin.autosave = "off" 34 34 python.check_license = "off" 35 + python.go.auto_jump = "off" 36 + python.go.buffer_number = "on" 37 + python.go.color_name = "black,cyan" 38 + python.go.color_name_highlight = "red,cyan" 39 + python.go.color_name_highlight_selected = "red,brown" 40 + python.go.color_name_selected = "black,brown" 41 + python.go.color_number = "yellow,magenta" 42 + python.go.color_number_selected = "yellow,red" 43 + python.go.fuzzy_search = "off" 44 + python.go.message = "Go to: " 45 + python.go.short_name = "off" 46 + python.go.sort = "number,beginning" 47 + python.go.use_core_instead_weechat = "off" 35 48 python.grep.clear_buffer = "off" 36 49 python.grep.default_tail_head = "10" 37 50 python.grep.go_to_buffer = "on" ··· 57 70 python.apply_corrections.message_limit = "Number of messages to store per nick." 58 71 python.apply_corrections.print_format = "Format string for the printed corrections." 59 72 python.apply_corrections.print_limit = "Maximum number of lines to correct." 73 + python.go.auto_jump = "automatically jump to buffer when it is uniquely selected (default: "off")" 74 + python.go.buffer_number = "display buffer number (default: "on")" 75 + python.go.color_name = "color for buffer name (not selected) (default: "black,cyan")" 76 + python.go.color_name_highlight = "color for highlight in buffer name (not selected) (default: "red,cyan")" 77 + python.go.color_name_highlight_selected = "color for highlight in a selected buffer name (default: "red,brown")" 78 + python.go.color_name_selected = "color for a selected buffer name (default: "black,brown")" 79 + python.go.color_number = "color for buffer number (not selected) (default: "yellow,magenta")" 80 + python.go.color_number_selected = "color for selected buffer number (default: "yellow,red")" 81 + python.go.fuzzy_search = "search buffer matches using approximation (default: "off")" 82 + python.go.message = "message to display before list of buffers (default: "Go to: ")" 83 + python.go.short_name = "display and search in short names instead of buffer name (default: "off")" 84 + python.go.sort = "comma-separated list of keys to sort buffers (the order is important, sorts are performed in the given order): name = sort by name (or short name), (default: "number,beginning")" 85 + python.go.use_core_instead_weechat = "use name "core" instead of "weechat" for core buffer (default: "off")" 60 86 python.screen_away.away_suffix = "What to append to your nick when you're away." 61 87 python.screen_away.command_on_attach = "Commands to execute on attach, separated by semicolon" 62 88 python.screen_away.command_on_detach = "Commands to execute on detach, separated by semicolon"
+30 -13
weechat/.weechat/python/autojoin.py
··· 43 43 # 2014-05-22, Nathaniel Wesley Filardo <PADEBR2M2JIQN02N9OO5JM0CTN8K689P@cmx.ietfng.org> 44 44 # version 0.2.5: Fix keyed channel support 45 45 # 46 + # 2016-01-13, The fox in the shell <KellerFuchs@hashbang.sh> 47 + # version 0.2.6: Support keeping chan list as secured data 48 + # 46 49 # @TODO: add options to ignore certain buffers 47 50 # @TODO: maybe add an option to enable autosaving on part/join messages 48 51 ··· 51 54 52 55 SCRIPT_NAME = "autojoin" 53 56 SCRIPT_AUTHOR = "xt <xt@bash.no>" 54 - SCRIPT_VERSION = "0.2.5" 57 + SCRIPT_VERSION = "0.2.6" 55 58 SCRIPT_LICENSE = "GPL3" 56 59 SCRIPT_DESC = "Configure autojoin for all servers according to currently joined channels" 57 60 SCRIPT_COMMAND = "autojoin" ··· 89 92 90 93 # print/execute commands 91 94 for server, channels in items.iteritems(): 92 - channels = channels.rstrip(',') 93 - command = "/set irc.server.%s.autojoin '%s'" % (server, channels) 94 - w.command('', command) 95 + process_server(server, channels) 95 96 96 97 return w.WEECHAT_RC_OK 97 98 ··· 111 112 match = re.match(pattern, callback_data) 112 113 113 114 if match: # check if nick is my nick. In that case: save 114 - channel = match.group(2) 115 - channels = channels.rstrip(',') 116 - command = "/set irc.server.%s.autojoin '%s'" % (server, channels) 117 - w.command('', command) 115 + process_server(server, channels) 118 116 else: # someone else: ignore 119 117 continue 120 118 ··· 126 124 """But I can't believe somebody would want that behaviour""" 127 125 items = find_channels() 128 126 127 + if args == '--run': 128 + run = True 129 + else: 130 + run = False 131 + 129 132 # print/execute commands 130 133 for server, channels in items.iteritems(): 134 + process_server(server, channels, run) 135 + 136 + return w.WEECHAT_RC_OK 137 + 138 + def process_server(server, channels, run=True): 139 + option = "irc.server.%s.autojoin" % server 131 140 channels = channels.rstrip(',') 141 + oldchans = w.config_string(w.config_get(option)) 142 + 132 143 if not channels: # empty channel list 133 - continue 134 - command = '/set irc.server.%s.autojoin %s' % (server, channels) 135 - if args == '--run': 144 + return 145 + 146 + # Note: re already caches the result of regexp compilation 147 + sec = re.match('^\${sec\.data\.(.*)}$', oldchans) 148 + if sec: 149 + secvar = sec.group(1) 150 + command = "/secure set %s %s" % (secvar, channels) 151 + else: 152 + command = "/set irc.server.%s.autojoin '%s'" % (server, channels) 153 + 154 + if run: 136 155 w.command('', command) 137 156 else: 138 157 w.prnt('', command) 139 - 140 - return w.WEECHAT_RC_OK 141 158 142 159 def find_channels(): 143 160 """Return list of servers and channels"""
+1
weechat/.weechat/python/autoload/autosort.py
··· 1 + ../autosort.py
+1
weechat/.weechat/python/autoload/colorize_nicks.py
··· 1 + ../colorize_nicks.py
+1
weechat/.weechat/python/autoload/go.py
··· 1 + ../go.py
+923
weechat/.weechat/python/autosort.py
··· 1 + # -*- coding: utf-8 -*- 2 + # 3 + # Copyright (C) 2013-2017 Maarten de Vries <maarten@de-vri.es> 4 + # 5 + # This program is free software; you can redistribute it and/or modify 6 + # it under the terms of the GNU General Public License as published by 7 + # the Free Software Foundation; either version 3 of the License, or 8 + # (at your option) any later version. 9 + # 10 + # This program is distributed in the hope that it will be useful, 11 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + # GNU General Public License for more details. 14 + # 15 + # You should have received a copy of the GNU General Public License 16 + # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 + # 18 + 19 + # 20 + # Autosort automatically keeps your buffers sorted and grouped by server. 21 + # You can define your own sorting rules. See /help autosort for more details. 22 + # 23 + # https://github.com/de-vri-es/weechat-autosort 24 + # 25 + 26 + # 27 + # Changelog: 28 + # 3.3: 29 + # * Fix the /autosort debug command for unicode. 30 + # * Update the default rules to work better with Slack. 31 + # 3.2: 32 + # * Fix python3 compatiblity. 33 + # 3.1: 34 + # * Use colors to format the help text. 35 + # 3.0: 36 + # * Switch to evaluated expressions for sorting. 37 + # * Add `/autosort debug` command. 38 + # * Add ${info:autosort_replace,from,to,text} to replace substrings in sort rules. 39 + # * Add ${info:autosort_order,value,first,second,third} to ease writing sort rules. 40 + # * Make tab completion context aware. 41 + # 2.8: 42 + # * Fix compatibility with python 3 regarding unicode handling. 43 + # 2.7: 44 + # * Fix sorting of buffers with spaces in their name. 45 + # 2.6: 46 + # * Ignore case in rules when doing case insensitive sorting. 47 + # 2.5: 48 + # * Fix handling unicode buffer names. 49 + # * Add hint to set irc.look.server_buffer to independent and buffers.look.indenting to on. 50 + # 2.4: 51 + # * Make script python3 compatible. 52 + # 2.3: 53 + # * Fix sorting items without score last (regressed in 2.2). 54 + # 2.2: 55 + # * Add configuration option for signals that trigger a sort. 56 + # * Add command to manually trigger a sort (/autosort sort). 57 + # * Add replacement patterns to apply before sorting. 58 + # 2.1: 59 + # * Fix some minor style issues. 60 + # 2.0: 61 + # * Allow for custom sort rules. 62 + # 63 + 64 + 65 + import json 66 + import math 67 + import re 68 + import sys 69 + import time 70 + import weechat 71 + 72 + SCRIPT_NAME = 'autosort' 73 + SCRIPT_AUTHOR = 'Maarten de Vries <maarten@de-vri.es>' 74 + SCRIPT_VERSION = '3.3' 75 + SCRIPT_LICENSE = 'GPL3' 76 + SCRIPT_DESC = 'Flexible automatic (or manual) buffer sorting based on eval expressions.' 77 + 78 + 79 + config = None 80 + hooks = [] 81 + timer = None 82 + 83 + # Make sure that unicode, bytes and str are always available in python2 and 3. 84 + # For python 2, str == bytes 85 + # For python 3, str == unicode 86 + if sys.version_info[0] >= 3: 87 + unicode = str 88 + 89 + def ensure_str(input): 90 + ''' 91 + Make sure the given type if the correct string type for the current python version. 92 + That means bytes for python2 and unicode for python3. 93 + ''' 94 + if not isinstance(input, str): 95 + if isinstance(input, bytes): 96 + return input.encode('utf-8') 97 + if isinstance(input, unicode): 98 + return input.decode('utf-8') 99 + return input 100 + 101 + 102 + if hasattr(time, 'perf_counter'): 103 + perf_counter = time.perf_counter 104 + else: 105 + perf_counter = time.clock 106 + 107 + def casefold(string): 108 + if hasattr(string, 'casefold'): return string.casefold() 109 + # Fall back to lowercasing for python2. 110 + return string.lower() 111 + 112 + def list_swap(values, a, b): 113 + values[a], values[b] = values[b], values[a] 114 + 115 + def list_move(values, old_index, new_index): 116 + values.insert(new_index, values.pop(old_index)) 117 + 118 + def list_find(collection, value): 119 + for i, elem in enumerate(collection): 120 + if elem == value: return i 121 + return None 122 + 123 + class HumanReadableError(Exception): 124 + pass 125 + 126 + def parse_int(arg, arg_name = 'argument'): 127 + ''' Parse an integer and provide a more human readable error. ''' 128 + arg = arg.strip() 129 + try: 130 + return int(arg) 131 + except ValueError: 132 + raise HumanReadableError('Invalid {0}: expected integer, got "{1}".'.format(arg_name, arg)) 133 + 134 + def decode_rules(blob): 135 + parsed = json.loads(blob) 136 + if not isinstance(parsed, list): 137 + log('Malformed rules, expected a JSON encoded list of strings, but got a {0}. No rules have been loaded. Please fix the setting manually.'.format(type(parsed))) 138 + return [] 139 + 140 + for i, entry in enumerate(parsed): 141 + if not isinstance(entry, (str, unicode)): 142 + log('Rule #{0} is not a string but a {1}. No rules have been loaded. Please fix the setting manually.'.format(i, type(entry))) 143 + return [] 144 + 145 + return parsed 146 + 147 + def decode_helpers(blob): 148 + parsed = json.loads(blob) 149 + if not isinstance(parsed, dict): 150 + log('Malformed helpers, expected a JSON encoded dictonary but got a {0}. No helpers have been loaded. Please fix the setting manually.'.format(type(parsed))) 151 + return {} 152 + 153 + for key, value in parsed.items(): 154 + if not isinstance(value, (str, unicode)): 155 + log('Helper "{0}" is not a string but a {1}. No helpers have been loaded. Please fix seting manually.'.format(key, type(value))) 156 + return {} 157 + return parsed 158 + 159 + class Config: 160 + ''' The autosort configuration. ''' 161 + 162 + default_rules = json.dumps([ 163 + '${core_first}', 164 + '${irc_last}', 165 + '${buffer.plugin.name}', 166 + '${irc_raw_first}', 167 + '${if:${plugin}==irc?${server}}', 168 + '${if:${plugin}==irc?${info:autosort_order,${type},server,*,channel,private}}', 169 + '${if:${plugin}==irc?${hashless_name}}', 170 + '${buffer.full_name}', 171 + ]) 172 + 173 + default_helpers = json.dumps({ 174 + 'core_first': '${if:${buffer.full_name}!=core.weechat}', 175 + 'irc_first': '${if:${buffer.plugin.name}!=irc}', 176 + 'irc_last': '${if:${buffer.plugin.name}==irc}', 177 + 'irc_raw_first': '${if:${buffer.full_name}!=irc.irc_raw}', 178 + 'irc_raw_last': '${if:${buffer.full_name}==irc.irc_raw}', 179 + 'hashless_name': '${info:autosort_replace,#,,${buffer.name}}', 180 + }) 181 + 182 + default_signal_delay = 5 183 + 184 + default_signals = 'buffer_opened buffer_merged buffer_unmerged buffer_renamed' 185 + 186 + def __init__(self, filename): 187 + ''' Initialize the configuration. ''' 188 + 189 + self.filename = filename 190 + self.config_file = weechat.config_new(self.filename, '', '') 191 + self.sorting_section = None 192 + self.v3_section = None 193 + 194 + self.case_sensitive = False 195 + self.rules = [] 196 + self.helpers = {} 197 + self.signals = [] 198 + self.signal_delay = Config.default_signal_delay, 199 + self.sort_on_config = True 200 + 201 + self.__case_sensitive = None 202 + self.__rules = None 203 + self.__helpers = None 204 + self.__signals = None 205 + self.__signal_delay = None 206 + self.__sort_on_config = None 207 + 208 + if not self.config_file: 209 + log('Failed to initialize configuration file "{0}".'.format(self.filename)) 210 + return 211 + 212 + self.sorting_section = weechat.config_new_section(self.config_file, 'sorting', False, False, '', '', '', '', '', '', '', '', '', '') 213 + self.v3_section = weechat.config_new_section(self.config_file, 'v3', False, False, '', '', '', '', '', '', '', '', '', '') 214 + 215 + if not self.sorting_section: 216 + log('Failed to initialize section "sorting" of configuration file.') 217 + weechat.config_free(self.config_file) 218 + return 219 + 220 + self.__case_sensitive = weechat.config_new_option( 221 + self.config_file, self.sorting_section, 222 + 'case_sensitive', 'boolean', 223 + 'If this option is on, sorting is case sensitive.', 224 + '', 0, 0, 'off', 'off', 0, 225 + '', '', '', '', '', '' 226 + ) 227 + 228 + weechat.config_new_option( 229 + self.config_file, self.sorting_section, 230 + 'rules', 'string', 231 + 'Sort rules used by autosort v2.x and below. Not used by autosort anymore.', 232 + '', 0, 0, '', '', 0, 233 + '', '', '', '', '', '' 234 + ) 235 + 236 + weechat.config_new_option( 237 + self.config_file, self.sorting_section, 238 + 'replacements', 'string', 239 + 'Replacement patterns used by autosort v2.x and below. Not used by autosort anymore.', 240 + '', 0, 0, '', '', 0, 241 + '', '', '', '', '', '' 242 + ) 243 + 244 + self.__rules = weechat.config_new_option( 245 + self.config_file, self.v3_section, 246 + 'rules', 'string', 247 + 'An ordered list of sorting rules encoded as JSON. See /help autosort for commands to manipulate these rules.', 248 + '', 0, 0, Config.default_rules, Config.default_rules, 0, 249 + '', '', '', '', '', '' 250 + ) 251 + 252 + self.__helpers = weechat.config_new_option( 253 + self.config_file, self.v3_section, 254 + 'helpers', 'string', 255 + 'A dictionary helper variables to use in the sorting rules, encoded as JSON. See /help autosort for commands to manipulate these helpers.', 256 + '', 0, 0, Config.default_helpers, Config.default_helpers, 0, 257 + '', '', '', '', '', '' 258 + ) 259 + 260 + self.__signals = weechat.config_new_option( 261 + self.config_file, self.sorting_section, 262 + 'signals', 'string', 263 + 'A space separated list of signals that will cause autosort to resort your buffer list.', 264 + '', 0, 0, Config.default_signals, Config.default_signals, 0, 265 + '', '', '', '', '', '' 266 + ) 267 + 268 + self.__signal_delay = weechat.config_new_option( 269 + self.config_file, self.sorting_section, 270 + 'signal_delay', 'integer', 271 + 'Delay in milliseconds to wait after a signal before sorting the buffer list. This prevents triggering many times if multiple signals arrive in a short time. It can also be needed to wait for buffer localvars to be available.', 272 + '', 0, 1000, str(Config.default_signal_delay), str(Config.default_signal_delay), 0, 273 + '', '', '', '', '', '' 274 + ) 275 + 276 + self.__sort_on_config = weechat.config_new_option( 277 + self.config_file, self.sorting_section, 278 + 'sort_on_config_change', 'boolean', 279 + 'Decides if the buffer list should be sorted when autosort configuration changes.', 280 + '', 0, 0, 'on', 'on', 0, 281 + '', '', '', '', '', '' 282 + ) 283 + 284 + if weechat.config_read(self.config_file) != weechat.WEECHAT_RC_OK: 285 + log('Failed to load configuration file.') 286 + 287 + if weechat.config_write(self.config_file) != weechat.WEECHAT_RC_OK: 288 + log('Failed to write configuration file.') 289 + 290 + self.reload() 291 + 292 + def reload(self): 293 + ''' Load configuration variables. ''' 294 + 295 + self.case_sensitive = weechat.config_boolean(self.__case_sensitive) 296 + 297 + rules_blob = weechat.config_string(self.__rules) 298 + helpers_blob = weechat.config_string(self.__helpers) 299 + signals_blob = weechat.config_string(self.__signals) 300 + 301 + self.rules = decode_rules(rules_blob) 302 + self.helpers = decode_helpers(helpers_blob) 303 + self.signals = signals_blob.split() 304 + self.signal_delay = weechat.config_integer(self.__signal_delay) 305 + self.sort_on_config = weechat.config_boolean(self.__sort_on_config) 306 + 307 + def save_rules(self, run_callback = True): 308 + ''' Save the current rules to the configuration. ''' 309 + weechat.config_option_set(self.__rules, json.dumps(self.rules), run_callback) 310 + 311 + def save_helpers(self, run_callback = True): 312 + ''' Save the current helpers to the configuration. ''' 313 + weechat.config_option_set(self.__helpers, json.dumps(self.helpers), run_callback) 314 + 315 + 316 + def pad(sequence, length, padding = None): 317 + ''' Pad a list until is has a certain length. ''' 318 + return sequence + [padding] * max(0, (length - len(sequence))) 319 + 320 + 321 + def log(message, buffer = 'NULL'): 322 + weechat.prnt(buffer, 'autosort: {0}'.format(message)) 323 + 324 + 325 + def get_buffers(): 326 + ''' Get a list of all the buffers in weechat. ''' 327 + hdata = weechat.hdata_get('buffer') 328 + buffer = weechat.hdata_get_list(hdata, "gui_buffers"); 329 + 330 + result = [] 331 + while buffer: 332 + number = weechat.hdata_integer(hdata, buffer, 'number') 333 + result.append((number, buffer)) 334 + buffer = weechat.hdata_pointer(hdata, buffer, 'next_buffer') 335 + return hdata, result 336 + 337 + class MergedBuffers(list): 338 + """ A list of merged buffers, possibly of size 1. """ 339 + def __init__(self, number): 340 + super(MergedBuffers, self).__init__() 341 + self.number = number 342 + 343 + def merge_buffer_list(buffers): 344 + ''' 345 + Group merged buffers together. 346 + The output is a list of MergedBuffers. 347 + ''' 348 + if not buffers: return [] 349 + result = {} 350 + for number, buffer in buffers: 351 + if number not in result: result[number] = MergedBuffers(number) 352 + result[number].append(buffer) 353 + return result.values() 354 + 355 + def sort_buffers(hdata, buffers, rules, helpers, case_sensitive): 356 + for merged in buffers: 357 + for buffer in merged: 358 + name = weechat.hdata_string(hdata, buffer, 'name') 359 + 360 + return sorted(buffers, key=merged_sort_key(rules, helpers, case_sensitive)) 361 + 362 + def buffer_sort_key(rules, helpers, case_sensitive): 363 + ''' Create a sort key function for a list of lists of merged buffers. ''' 364 + def key(buffer): 365 + extra_vars = {} 366 + for helper_name, helper in sorted(helpers.items()): 367 + expanded = weechat.string_eval_expression(helper, {"buffer": buffer}, {}, {}) 368 + extra_vars[helper_name] = expanded if case_sensitive else casefold(expanded) 369 + result = [] 370 + for rule in rules: 371 + expanded = weechat.string_eval_expression(rule, {"buffer": buffer}, extra_vars, {}) 372 + result.append(expanded if case_sensitive else casefold(expanded)) 373 + return result 374 + 375 + return key 376 + 377 + def merged_sort_key(rules, helpers, case_sensitive): 378 + buffer_key = buffer_sort_key(rules, helpers, case_sensitive) 379 + def key(merged): 380 + best = None 381 + for buffer in merged: 382 + this = buffer_key(buffer) 383 + if best is None or this < best: best = this 384 + return best 385 + return key 386 + 387 + def apply_buffer_order(buffers): 388 + ''' Sort the buffers in weechat according to the given order. ''' 389 + for i, buffer in enumerate(buffers): 390 + weechat.buffer_set(buffer[0], "number", str(i + 1)) 391 + 392 + def split_args(args, expected, optional = 0): 393 + ''' Split an argument string in the desired number of arguments. ''' 394 + split = args.split(' ', expected - 1) 395 + if (len(split) < expected): 396 + raise HumanReadableError('Expected at least {0} arguments, got {1}.'.format(expected, len(split))) 397 + return split[:-1] + pad(split[-1].split(' ', optional), optional + 1, '') 398 + 399 + def do_sort(): 400 + hdata, buffers = get_buffers() 401 + buffers = merge_buffer_list(buffers) 402 + buffers = sort_buffers(hdata, buffers, config.rules, config.helpers, config.case_sensitive) 403 + apply_buffer_order(buffers) 404 + 405 + def command_sort(buffer, command, args): 406 + ''' Sort the buffers and print a confirmation. ''' 407 + start = perf_counter() 408 + do_sort() 409 + elapsed = perf_counter() - start 410 + log("Finished sorting buffers in {0:.4f} seconds.".format(elapsed)) 411 + return weechat.WEECHAT_RC_OK 412 + 413 + def command_debug(buffer, command, args): 414 + hdata, buffers = get_buffers() 415 + buffers = merge_buffer_list(buffers) 416 + 417 + # Show evaluation results. 418 + log('Individual evaluation results:') 419 + start = perf_counter() 420 + key = buffer_sort_key(config.rules, config.helpers, config.case_sensitive) 421 + results = [] 422 + for merged in buffers: 423 + for buffer in merged: 424 + fullname = weechat.hdata_string(hdata, buffer, 'full_name') 425 + results.append((fullname, key(buffer))) 426 + elapsed = perf_counter() - start 427 + 428 + for fullname, result in results: 429 + fullname = ensure_str(fullname) 430 + result = [ensure_str(x) for x in result] 431 + log('{0}: {1}'.format(fullname, result)) 432 + log('Computing evalutaion results took {0:.4f} seconds.'.format(elapsed)) 433 + 434 + return weechat.WEECHAT_RC_OK 435 + 436 + def command_rule_list(buffer, command, args): 437 + ''' Show the list of sorting rules. ''' 438 + output = 'Sorting rules:\n' 439 + for i, rule in enumerate(config.rules): 440 + output += ' {0}: {1}\n'.format(i, rule) 441 + if not len(config.rules): 442 + output += ' No sorting rules configured.\n' 443 + log(output ) 444 + 445 + return weechat.WEECHAT_RC_OK 446 + 447 + 448 + def command_rule_add(buffer, command, args): 449 + ''' Add a rule to the rule list. ''' 450 + config.rules.append(args) 451 + config.save_rules() 452 + command_rule_list(buffer, command, '') 453 + 454 + return weechat.WEECHAT_RC_OK 455 + 456 + 457 + def command_rule_insert(buffer, command, args): 458 + ''' Insert a rule at the desired position in the rule list. ''' 459 + index, rule = split_args(args, 2) 460 + index = parse_int(index, 'index') 461 + 462 + config.rules.insert(index, rule) 463 + config.save_rules() 464 + command_rule_list(buffer, command, '') 465 + return weechat.WEECHAT_RC_OK 466 + 467 + 468 + def command_rule_update(buffer, command, args): 469 + ''' Update a rule in the rule list. ''' 470 + index, rule = split_args(args, 2) 471 + index = parse_int(index, 'index') 472 + 473 + config.rules[index] = rule 474 + config.save_rules() 475 + command_rule_list(buffer, command, '') 476 + return weechat.WEECHAT_RC_OK 477 + 478 + 479 + def command_rule_delete(buffer, command, args): 480 + ''' Delete a rule from the rule list. ''' 481 + index = args.strip() 482 + index = parse_int(index, 'index') 483 + 484 + config.rules.pop(index) 485 + config.save_rules() 486 + command_rule_list(buffer, command, '') 487 + return weechat.WEECHAT_RC_OK 488 + 489 + 490 + def command_rule_move(buffer, command, args): 491 + ''' Move a rule to a new position. ''' 492 + index_a, index_b = split_args(args, 2) 493 + index_a = parse_int(index_a, 'index') 494 + index_b = parse_int(index_b, 'index') 495 + 496 + list_move(config.rules, index_a, index_b) 497 + config.save_rules() 498 + command_rule_list(buffer, command, '') 499 + return weechat.WEECHAT_RC_OK 500 + 501 + 502 + def command_rule_swap(buffer, command, args): 503 + ''' Swap two rules. ''' 504 + index_a, index_b = split_args(args, 2) 505 + index_a = parse_int(index_a, 'index') 506 + index_b = parse_int(index_b, 'index') 507 + 508 + list_swap(config.rules, index_a, index_b) 509 + config.save_rules() 510 + command_rule_list(buffer, command, '') 511 + return weechat.WEECHAT_RC_OK 512 + 513 + 514 + def command_helper_list(buffer, command, args): 515 + ''' Show the list of helpers. ''' 516 + output = 'Helper variables:\n' 517 + 518 + width = max(map(lambda x: len(x) if len(x) <= 30 else 0, config.helpers.keys())) 519 + 520 + for name, expression in sorted(config.helpers.items()): 521 + output += ' {0:>{width}}: {1}\n'.format(name, expression, width=width) 522 + if not len(config.helpers): 523 + output += ' No helper variables configured.' 524 + log(output) 525 + 526 + return weechat.WEECHAT_RC_OK 527 + 528 + 529 + def command_helper_set(buffer, command, args): 530 + ''' Add/update a helper to the helper list. ''' 531 + name, expression = split_args(args, 2) 532 + 533 + config.helpers[name] = expression 534 + config.save_helpers() 535 + command_helper_list(buffer, command, '') 536 + 537 + return weechat.WEECHAT_RC_OK 538 + 539 + def command_helper_delete(buffer, command, args): 540 + ''' Delete a helper from the helper list. ''' 541 + name = args.strip() 542 + 543 + del config.helpers[name] 544 + config.save_helpers() 545 + command_helper_list(buffer, command, '') 546 + return weechat.WEECHAT_RC_OK 547 + 548 + 549 + def command_helper_rename(buffer, command, args): 550 + ''' Rename a helper to a new position. ''' 551 + old_name, new_name = split_args(args, 2) 552 + 553 + try: 554 + config.helpers[new_name] = config.helpers[old_name] 555 + del config.helpers[old_name] 556 + except KeyError: 557 + raise HumanReadableError('No such helper: {0}'.format(old_name)) 558 + config.save_helpers() 559 + command_helper_list(buffer, command, '') 560 + return weechat.WEECHAT_RC_OK 561 + 562 + 563 + def command_helper_swap(buffer, command, args): 564 + ''' Swap two helpers. ''' 565 + a, b = split_args(args, 2) 566 + try: 567 + config.helpers[b], config.helpers[a] = config.helpers[a], config.helpers[b] 568 + except KeyError as e: 569 + raise HumanReadableError('No such helper: {0}'.format(e.args[0])) 570 + 571 + config.helpers.swap(index_a, index_b) 572 + config.save_helpers() 573 + command_helper_list(buffer, command, '') 574 + return weechat.WEECHAT_RC_OK 575 + 576 + def call_command(buffer, command, args, subcommands): 577 + ''' Call a subccommand from a dictionary. ''' 578 + subcommand, tail = pad(args.split(' ', 1), 2, '') 579 + subcommand = subcommand.strip() 580 + if (subcommand == ''): 581 + child = subcommands.get(' ') 582 + else: 583 + command = command + [subcommand] 584 + child = subcommands.get(subcommand) 585 + 586 + if isinstance(child, dict): 587 + return call_command(buffer, command, tail, child) 588 + elif callable(child): 589 + return child(buffer, command, tail) 590 + 591 + log('{0}: command not found'.format(' '.join(command))) 592 + return weechat.WEECHAT_RC_ERROR 593 + 594 + def on_signal(*args, **kwargs): 595 + global timer 596 + ''' Called whenever the buffer list changes. ''' 597 + if timer is not None: 598 + weechat.unhook(timer) 599 + timer = None 600 + weechat.hook_timer(config.signal_delay, 0, 1, "on_timeout", "") 601 + return weechat.WEECHAT_RC_OK 602 + 603 + def on_timeout(pointer, remaining_calls): 604 + global timer 605 + timer = None 606 + do_sort() 607 + return weechat.WEECHAT_RC_OK 608 + 609 + def apply_config(): 610 + # Unhook all signals and hook the new ones. 611 + for hook in hooks: 612 + weechat.unhook(hook) 613 + for signal in config.signals: 614 + hooks.append(weechat.hook_signal(signal, 'on_signal', '')) 615 + 616 + if config.sort_on_config: 617 + do_sort() 618 + 619 + def on_config_changed(*args, **kwargs): 620 + ''' Called whenever the configuration changes. ''' 621 + config.reload() 622 + apply_config() 623 + 624 + return weechat.WEECHAT_RC_OK 625 + 626 + def parse_arg(args): 627 + if not args: return None, None 628 + 629 + result = '' 630 + escaped = False 631 + for i, c in enumerate(args): 632 + if not escaped: 633 + if c == '\\': 634 + escaped = True 635 + continue 636 + elif c == ',': 637 + return result, args[i+1:] 638 + result += c 639 + escaped = False 640 + return result, None 641 + 642 + def parse_args(args, max = None): 643 + result = [] 644 + i = 0 645 + while max is None or i < max: 646 + arg, args = parse_arg(args) 647 + if arg is None: break 648 + result.append(arg) 649 + i += 1 650 + return result, args 651 + 652 + def on_info_replace(pointer, name, arguments): 653 + arguments, rest = parse_args(arguments, 3) 654 + if rest or len(arguments) < 3: 655 + log('usage: ${{info:{0},old,new,text}}'.format(name)) 656 + return '' 657 + old, new, text = arguments 658 + 659 + return text.replace(old, new) 660 + 661 + def on_info_order(pointer, name, arguments): 662 + arguments, rest = parse_args(arguments) 663 + if len(arguments) < 1: 664 + log('usage: ${{info:{0},value,first,second,third,...}}'.format(name)) 665 + return '' 666 + 667 + value = arguments[0] 668 + keys = arguments[1:] 669 + if not keys: return '0' 670 + 671 + # Find the value in the keys (or '*' if we can't find it) 672 + result = list_find(keys, value) 673 + if result is None: result = list_find(keys, '*') 674 + if result is None: result = len(keys) 675 + 676 + # Pad result with leading zero to make sure string sorting works. 677 + width = int(math.log10(len(keys))) + 1 678 + return '{0:0{1}}'.format(result, width) 679 + 680 + 681 + def on_autosort_command(data, buffer, args): 682 + ''' Called when the autosort command is invoked. ''' 683 + try: 684 + return call_command(buffer, ['/autosort'], args, { 685 + ' ': command_sort, 686 + 'sort': command_sort, 687 + 'debug': command_debug, 688 + 689 + 'rules': { 690 + ' ': command_rule_list, 691 + 'list': command_rule_list, 692 + 'add': command_rule_add, 693 + 'insert': command_rule_insert, 694 + 'update': command_rule_update, 695 + 'delete': command_rule_delete, 696 + 'move': command_rule_move, 697 + 'swap': command_rule_swap, 698 + }, 699 + 'helpers': { 700 + ' ': command_helper_list, 701 + 'list': command_helper_list, 702 + 'set': command_helper_set, 703 + 'delete': command_helper_delete, 704 + 'rename': command_helper_rename, 705 + 'swap': command_helper_swap, 706 + }, 707 + }) 708 + except HumanReadableError as e: 709 + log(e) 710 + return weechat.WEECHAT_RC_ERROR 711 + 712 + def add_completions(completion, words): 713 + for word in words: 714 + weechat.hook_completion_list_add(completion, word, 0, weechat.WEECHAT_LIST_POS_END) 715 + 716 + def autosort_complete_rules(words, completion): 717 + if len(words) == 0: 718 + add_completions(completion, ['add', 'delete', 'insert', 'list', 'move', 'swap', 'update']) 719 + if len(words) == 1 and words[0] in ('delete', 'insert', 'move', 'swap', 'update'): 720 + add_completions(completion, map(str, range(len(config.rules)))) 721 + if len(words) == 2 and words[0] in ('move', 'swap'): 722 + add_completions(completion, map(str, range(len(config.rules)))) 723 + if len(words) == 2 and words[0] in ('update'): 724 + try: 725 + add_completions(completion, [config.rules[int(words[1])]]) 726 + except KeyError: pass 727 + except ValueError: pass 728 + else: 729 + add_completions(completion, ['']) 730 + return weechat.WEECHAT_RC_OK 731 + 732 + def autosort_complete_helpers(words, completion): 733 + if len(words) == 0: 734 + add_completions(completion, ['delete', 'list', 'rename', 'set', 'swap']) 735 + elif len(words) == 1 and words[0] in ('delete', 'rename', 'set', 'swap'): 736 + add_completions(completion, sorted(config.helpers.keys())) 737 + elif len(words) == 2 and words[0] == 'swap': 738 + add_completions(completion, sorted(config.helpers.keys())) 739 + elif len(words) == 2 and words[0] == 'rename': 740 + add_completions(completion, sorted(config.helpers.keys())) 741 + elif len(words) == 2 and words[0] == 'set': 742 + try: 743 + add_completions(completion, [config.helpers[words[1]]]) 744 + except KeyError: pass 745 + return weechat.WEECHAT_RC_OK 746 + 747 + def on_autosort_complete(data, name, buffer, completion): 748 + cmdline = weechat.buffer_get_string(buffer, "input") 749 + cursor = weechat.buffer_get_integer(buffer, "input_pos") 750 + prefix = cmdline[:cursor] 751 + words = prefix.split()[1:] 752 + 753 + # If the current word isn't finished yet, 754 + # ignore it for coming up with completion suggestions. 755 + if prefix[-1] != ' ': words = words[:-1] 756 + 757 + if len(words) == 0: 758 + add_completions(completion, ['debug', 'helpers', 'rules', 'sort']) 759 + elif words[0] == 'rules': 760 + return autosort_complete_rules(words[1:], completion) 761 + elif words[0] == 'helpers': 762 + return autosort_complete_helpers(words[1:], completion) 763 + return weechat.WEECHAT_RC_OK 764 + 765 + command_description = r'''{*white}# General commands{reset} 766 + 767 + {*white}/autosort {brown}sort{reset} 768 + Manually trigger the buffer sorting. 769 + 770 + {*white}/autosort {brown}debug{reset} 771 + Show the evaluation results of the sort rules for each buffer. 772 + 773 + 774 + {*white}# Sorting rule commands{reset} 775 + 776 + {*white}/autosort{brown} rules list{reset} 777 + Print the list of sort rules. 778 + 779 + {*white}/autosort {brown}rules add {cyan}<expression>{reset} 780 + Add a new rule at the end of the list. 781 + 782 + {*white}/autosort {brown}rules insert {cyan}<index> <expression>{reset} 783 + Insert a new rule at the given index in the list. 784 + 785 + {*white}/autosort {brown}rules update {cyan}<index> <expression>{reset} 786 + Update a rule in the list with a new expression. 787 + 788 + {*white}/autosort {brown}rules delete {cyan}<index> 789 + Delete a rule from the list. 790 + 791 + {*white}/autosort {brown}rules move {cyan}<index_from> <index_to>{reset} 792 + Move a rule from one position in the list to another. 793 + 794 + {*white}/autosort {brown}rules swap {cyan}<index_a> <index_b>{reset} 795 + Swap two rules in the list 796 + 797 + 798 + {*white}# Helper variable commands{reset} 799 + 800 + {*white}/autosort {brown}helpers list 801 + Print the list of helper variables. 802 + 803 + {*white}/autosort {brown}helpers set {cyan}<name> <expression> 804 + Add or update a helper variable with the given name. 805 + 806 + {*white}/autosort {brown}helpers delete {cyan}<name> 807 + Delete a helper variable. 808 + 809 + {*white}/autosort {brown}helpers rename {cyan}<old_name> <new_name> 810 + Rename a helper variable. 811 + 812 + {*white}/autosort {brown}helpers swap {cyan}<name_a> <name_b> 813 + Swap the expressions of two helper variables in the list. 814 + 815 + 816 + {*white}# Description 817 + Autosort is a weechat script to automatically keep your buffers sorted. The sort 818 + order can be customized by defining your own sort rules, but the default should 819 + be sane enough for most people. It can also group IRC channel/private buffers 820 + under their server buffer if you like. 821 + 822 + {*white}# Sort rules{reset} 823 + Autosort evaluates a list of eval expressions (see {*default}/help eval{reset}) and sorts the 824 + buffers based on evaluated result. Earlier rules will be considered first. Only 825 + if earlier rules produced identical results is the result of the next rule 826 + considered for sorting purposes. 827 + 828 + You can debug your sort rules with the `{*default}/autosort debug{reset}` command, which will 829 + print the evaluation results of each rule for each buffer. 830 + 831 + {*brown}NOTE:{reset} The sort rules for version 3 are not compatible with version 2 or vice 832 + versa. You will have to manually port your old rules to version 3 if you have any. 833 + 834 + {*white}# Helper variables{reset} 835 + You may define helper variables for the main sort rules to keep your rules 836 + readable. They can be used in the main sort rules as variables. For example, 837 + a helper variable named `{cyan}foo{reset}` can be accessed in a main rule with the 838 + string `{cyan}${{foo}}{reset}`. 839 + 840 + {*white}# Replacing substrings{reset} 841 + There is no default method for replacing text inside eval expressions. However, 842 + autosort adds a `replace` info hook that can be used inside eval expressions: 843 + {cyan}${{info:autosort_replace,from,to,text}}{reset} 844 + 845 + For example, to strip all hashes from a buffer name, you could write: 846 + {cyan}${{info:autosort_replace,#,,${{buffer.name}}}}{reset} 847 + 848 + You can escape commas and backslashes inside the arguments by prefixing them with 849 + a backslash. 850 + 851 + {*white}# Automatic or manual sorting{reset} 852 + By default, autosort will automatically sort your buffer list whenever a buffer 853 + is opened, merged, unmerged or renamed. This should keep your buffers sorted in 854 + almost all situations. However, you may wish to change the list of signals that 855 + cause your buffer list to be sorted. Simply edit the `{cyan}autosort.sorting.signals{reset}` 856 + option to add or remove any signal you like. 857 + 858 + If you remove all signals you can still sort your buffers manually with the 859 + `{*default}/autosort sort{reset}` command. To prevent all automatic sorting, the option 860 + `{cyan}autosort.sorting.sort_on_config_change{reset}` should also be disabled. 861 + 862 + {*white}# Recommended settings 863 + For the best visual effect, consider setting the following options: 864 + {*white}/set {cyan}irc.look.server_buffer{reset} {brown}independent{reset} 865 + {*white}/set {cyan}buffers.look.indenting{reset} {brown}on{reset} 866 + 867 + The first setting allows server buffers to be sorted independently, which is 868 + needed to create a hierarchical tree view of the server and channel buffers. 869 + The second one indents channel and private buffers in the buffer list of the 870 + `{*default}buffers.pl{reset}` script. 871 + 872 + If you are using the {*default}buflist{reset} plugin you can (ab)use Unicode to draw a tree 873 + structure with the following setting (modify to suit your need): 874 + {*white}/set {cyan}buflist.format.indent {brown}"${{color:237}}${{if:${{buffer.next_buffer.local_variables.type}}=~^(channel|private)$?├─:└─}}"{reset} 875 + ''' 876 + 877 + command_completion = '%(plugin_autosort) %(plugin_autosort) %(plugin_autosort) %(plugin_autosort) %(plugin_autosort)' 878 + 879 + info_replace_description = 'Replace all occurences of `from` with `to` in the string `text`.' 880 + info_replace_arguments = 'from,to,text' 881 + 882 + info_order_description = ( 883 + 'Get a zero padded index of a value in a list of possible values.' 884 + 'If the value is not found, the index for `*` is returned.' 885 + 'If there is no `*` in the list, the highest index + 1 is returned.' 886 + ) 887 + info_order_arguments = 'value,first,second,third,...' 888 + 889 + 890 + if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): 891 + config = Config('autosort') 892 + 893 + colors = { 894 + 'default': weechat.color('default'), 895 + 'reset': weechat.color('reset'), 896 + 'black': weechat.color('black'), 897 + 'red': weechat.color('red'), 898 + 'green': weechat.color('green'), 899 + 'brown': weechat.color('brown'), 900 + 'yellow': weechat.color('yellow'), 901 + 'blue': weechat.color('blue'), 902 + 'magenta': weechat.color('magenta'), 903 + 'cyan': weechat.color('cyan'), 904 + 'white': weechat.color('white'), 905 + '*default': weechat.color('*default'), 906 + '*black': weechat.color('*black'), 907 + '*red': weechat.color('*red'), 908 + '*green': weechat.color('*green'), 909 + '*brown': weechat.color('*brown'), 910 + '*yellow': weechat.color('*yellow'), 911 + '*blue': weechat.color('*blue'), 912 + '*magenta': weechat.color('*magenta'), 913 + '*cyan': weechat.color('*cyan'), 914 + '*white': weechat.color('*white'), 915 + } 916 + 917 + weechat.hook_config('autosort.*', 'on_config_changed', '') 918 + weechat.hook_completion('plugin_autosort', '', 'on_autosort_complete', '') 919 + weechat.hook_command('autosort', command_description.format(**colors), '', '', command_completion, 'on_autosort_command', '') 920 + weechat.hook_info('autosort_replace', info_replace_description, info_replace_arguments, 'on_info_replace', '') 921 + weechat.hook_info('autosort_order', info_order_description, info_order_arguments, 'on_info_order', '') 922 + 923 + apply_config()
+400
weechat/.weechat/python/colorize_nicks.py
··· 1 + # -*- coding: utf-8 -*- 2 + # 3 + # Copyright (c) 2010 by xt <xt@bash.no> 4 + # 5 + # This program is free software; you can redistribute it and/or modify 6 + # it under the terms of the GNU General Public License as published by 7 + # the Free Software Foundation; either version 3 of the License, or 8 + # (at your option) any later version. 9 + # 10 + # This program is distributed in the hope that it will be useful, 11 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + # GNU General Public License for more details. 14 + # 15 + # You should have received a copy of the GNU General Public License 16 + # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 + # 18 + 19 + # This script colors nicks in IRC channels in the actual message 20 + # not just in the prefix section. 21 + # 22 + # 23 + # History: 24 + # 2018-04-06: Joey Pabalinas <joeypabalinas@gmail.com> 25 + # version 26: fix freezes with too many nicks in one line 26 + # 2018-03-18: nils_2 27 + # version 25: fix unable to run function colorize_config_reload_cb() 28 + # 2017-06-20: lbeziaud <louis.beziaud@ens-rennes.fr> 29 + # version 24: colorize utf8 nicks 30 + # 2017-03-01, arza <arza@arza.us> 31 + # version 23: don't colorize nicklist group names 32 + # 2016-05-01, Simmo Saan <simmo.saan@gmail.com> 33 + # version 22: invalidate cached colors on hash algorithm change 34 + # 2015-07-28, xt 35 + # version 21: fix problems with nicks with commas in them 36 + # 2015-04-19, xt 37 + # version 20: fix ignore of nicks in URLs 38 + # 2015-04-18, xt 39 + # version 19: new option ignore nicks in URLs 40 + # 2015-03-03, xt 41 + # version 18: iterate buffers looking for nicklists instead of servers 42 + # 2015-02-23, holomorph 43 + # version 17: fix coloring in non-channel buffers (#58) 44 + # 2014-09-17, holomorph 45 + # version 16: use weechat config facilities 46 + # clean unused, minor linting, some simplification 47 + # 2014-05-05, holomorph 48 + # version 15: fix python2-specific re.search check 49 + # 2013-01-29, nils_2 50 + # version 14: make script compatible with Python 3.x 51 + # 2012-10-19, ldvx 52 + # version 13: Iterate over every word to prevent incorrect colorization of 53 + # nicks. Added option greedy_matching. 54 + # 2012-04-28, ldvx 55 + # version 12: added ignore_tags to avoid colorizing nicks if tags are present 56 + # 2012-01-14, nesthib 57 + # version 11: input_text_display hook and modifier to colorize nicks in input bar 58 + # 2010-12-22, xt 59 + # version 10: hook config option for updating blacklist 60 + # 2010-12-20, xt 61 + # version 0.9: hook new config option for weechat 0.3.4 62 + # 2010-11-01, nils_2 63 + # version 0.8: hook_modifier() added to communicate with rainbow_text 64 + # 2010-10-01, xt 65 + # version 0.7: changes to support non-irc-plugins 66 + # 2010-07-29, xt 67 + # version 0.6: compile regexp as per patch from Chris quigybo@hotmail.com 68 + # 2010-07-19, xt 69 + # version 0.5: fix bug with incorrect coloring of own nick 70 + # 2010-06-02, xt 71 + # version 0.4: update to reflect API changes 72 + # 2010-03-26, xt 73 + # version 0.3: fix error with exception 74 + # 2010-03-24, xt 75 + # version 0.2: use ignore_channels when populating to increase performance. 76 + # 2010-02-03, xt 77 + # version 0.1: initial (based on ruby script by dominikh) 78 + # 79 + # Known issues: nicks will not get colorized if they begin with a character 80 + # such as ~ (which some irc networks do happen to accept) 81 + 82 + import weechat 83 + import re 84 + w = weechat 85 + 86 + SCRIPT_NAME = "colorize_nicks" 87 + SCRIPT_AUTHOR = "xt <xt@bash.no>" 88 + SCRIPT_VERSION = "26" 89 + SCRIPT_LICENSE = "GPL" 90 + SCRIPT_DESC = "Use the weechat nick colors in the chat area" 91 + 92 + # Based on the recommendations in RFC 7613. A valid nick is composed 93 + # of anything but " ,*?.!@". 94 + VALID_NICK = r'([@~&!%+-])?([^\s,\*?\.!@]+)' 95 + valid_nick_re = re.compile(VALID_NICK) 96 + ignore_channels = [] 97 + ignore_nicks = [] 98 + 99 + # Dict with every nick on every channel with its color as lookup value 100 + colored_nicks = {} 101 + 102 + CONFIG_FILE_NAME = "colorize_nicks" 103 + 104 + # config file and options 105 + colorize_config_file = "" 106 + colorize_config_option = {} 107 + 108 + def colorize_config_init(): 109 + ''' 110 + Initialization of configuration file. 111 + Sections: look. 112 + ''' 113 + global colorize_config_file, colorize_config_option 114 + colorize_config_file = weechat.config_new(CONFIG_FILE_NAME, 115 + "", "") 116 + if colorize_config_file == "": 117 + return 118 + 119 + # section "look" 120 + section_look = weechat.config_new_section( 121 + colorize_config_file, "look", 0, 0, "", "", "", "", "", "", "", "", "", "") 122 + if section_look == "": 123 + weechat.config_free(colorize_config_file) 124 + return 125 + colorize_config_option["blacklist_channels"] = weechat.config_new_option( 126 + colorize_config_file, section_look, "blacklist_channels", 127 + "string", "Comma separated list of channels", "", 0, 0, 128 + "", "", 0, "", "", "", "", "", "") 129 + colorize_config_option["blacklist_nicks"] = weechat.config_new_option( 130 + colorize_config_file, section_look, "blacklist_nicks", 131 + "string", "Comma separated list of nicks", "", 0, 0, 132 + "so,root", "so,root", 0, "", "", "", "", "", "") 133 + colorize_config_option["min_nick_length"] = weechat.config_new_option( 134 + colorize_config_file, section_look, "min_nick_length", 135 + "integer", "Minimum length nick to colorize", "", 136 + 2, 20, "", "", 0, "", "", "", "", "", "") 137 + colorize_config_option["colorize_input"] = weechat.config_new_option( 138 + colorize_config_file, section_look, "colorize_input", 139 + "boolean", "Whether to colorize input", "", 0, 140 + 0, "off", "off", 0, "", "", "", "", "", "") 141 + colorize_config_option["ignore_tags"] = weechat.config_new_option( 142 + colorize_config_file, section_look, "ignore_tags", 143 + "string", "Comma separated list of tags to ignore; i.e. irc_join,irc_part,irc_quit", "", 0, 0, 144 + "", "", 0, "", "", "", "", "", "") 145 + colorize_config_option["greedy_matching"] = weechat.config_new_option( 146 + colorize_config_file, section_look, "greedy_matching", 147 + "boolean", "If off, then use lazy matching instead", "", 0, 148 + 0, "on", "on", 0, "", "", "", "", "", "") 149 + colorize_config_option["match_limit"] = weechat.config_new_option( 150 + colorize_config_file, section_look, "match_limit", 151 + "integer", "Fall back to lazy matching if greedy matches exceeds this number", "", 152 + 20, 1000, "", "", 0, "", "", "", "", "", "") 153 + colorize_config_option["ignore_nicks_in_urls"] = weechat.config_new_option( 154 + colorize_config_file, section_look, "ignore_nicks_in_urls", 155 + "boolean", "If on, don't colorize nicks inside URLs", "", 0, 156 + 0, "off", "off", 0, "", "", "", "", "", "") 157 + 158 + def colorize_config_read(): 159 + ''' Read configuration file. ''' 160 + global colorize_config_file 161 + return weechat.config_read(colorize_config_file) 162 + 163 + def colorize_nick_color(nick, my_nick): 164 + ''' Retrieve nick color from weechat. ''' 165 + if nick == my_nick: 166 + return w.color(w.config_string(w.config_get('weechat.color.chat_nick_self'))) 167 + else: 168 + return w.info_get('irc_nick_color', nick) 169 + 170 + def colorize_cb(data, modifier, modifier_data, line): 171 + ''' Callback that does the colorizing, and returns new line if changed ''' 172 + 173 + global ignore_nicks, ignore_channels, colored_nicks 174 + 175 + 176 + full_name = modifier_data.split(';')[1] 177 + channel = '.'.join(full_name.split('.')[1:]) 178 + 179 + buffer = w.buffer_search('', full_name) 180 + # Check if buffer has colorized nicks 181 + if buffer not in colored_nicks: 182 + return line 183 + 184 + if channel and channel in ignore_channels: 185 + return line 186 + 187 + min_length = w.config_integer(colorize_config_option['min_nick_length']) 188 + reset = w.color('reset') 189 + 190 + # Don't colorize if the ignored tag is present in message 191 + tags_line = modifier_data.rsplit(';') 192 + if len(tags_line) >= 3: 193 + tags_line = tags_line[2].split(',') 194 + for i in w.config_string(colorize_config_option['ignore_tags']).split(','): 195 + if i in tags_line: 196 + return line 197 + 198 + for words in valid_nick_re.findall(line): 199 + nick = words[1] 200 + # Check that nick is not ignored and longer than minimum length 201 + if len(nick) < min_length or nick in ignore_nicks: 202 + continue 203 + 204 + # If the matched word is not a known nick, we try to match the 205 + # word without its first or last character (if not a letter). 206 + # This is necessary as "foo:" is a valid nick, which could be 207 + # adressed as "foo::". 208 + if nick not in colored_nicks[buffer]: 209 + if not nick[-1].isalpha() and not nick[0].isalpha(): 210 + if nick[1:-1] in colored_nicks[buffer]: 211 + nick = nick[1:-1] 212 + elif not nick[0].isalpha(): 213 + if nick[1:] in colored_nicks[buffer]: 214 + nick = nick[1:] 215 + elif not nick[-1].isalpha(): 216 + if nick[:-1] in colored_nicks[buffer]: 217 + nick = nick[:-1] 218 + 219 + # Check that nick is in the dictionary colored_nicks 220 + if nick in colored_nicks[buffer]: 221 + nick_color = colored_nicks[buffer][nick] 222 + 223 + try: 224 + # Let's use greedy matching. Will check against every word in a line. 225 + if w.config_boolean(colorize_config_option['greedy_matching']): 226 + cnt = 0 227 + limit = w.config_integer(colorize_config_option['match_limit']) 228 + 229 + for word in line.split(): 230 + cnt += 1 231 + assert cnt < limit 232 + # if cnt > limit: 233 + # raise RuntimeError('Exceeded colorize_nicks.look.match_limit.'); 234 + 235 + if w.config_boolean(colorize_config_option['ignore_nicks_in_urls']) and \ 236 + word.startswith(('http://', 'https://')): 237 + continue 238 + 239 + if nick in word: 240 + # Is there a nick that contains nick and has a greater lenght? 241 + # If so let's save that nick into var biggest_nick 242 + biggest_nick = "" 243 + for i in colored_nicks[buffer]: 244 + cnt += 1 245 + assert cnt < limit 246 + 247 + if nick in i and nick != i and len(i) > len(nick): 248 + if i in word: 249 + # If a nick with greater len is found, and that word 250 + # also happens to be in word, then let's save this nick 251 + biggest_nick = i 252 + # If there's a nick with greater len, then let's skip this 253 + # As we will have the chance to colorize when biggest_nick 254 + # iterates being nick. 255 + if len(biggest_nick) > 0 and biggest_nick in word: 256 + pass 257 + elif len(word) < len(biggest_nick) or len(biggest_nick) == 0: 258 + new_word = word.replace(nick, '%s%s%s' % (nick_color, nick, reset)) 259 + line = line.replace(word, new_word) 260 + 261 + # Switch to lazy matching 262 + else: 263 + raise AssertionError 264 + 265 + except AssertionError: 266 + # Let's use lazy matching for nick 267 + nick_color = colored_nicks[buffer][nick] 268 + # The two .? are in case somebody writes "nick:", "nick,", etc 269 + # to address somebody 270 + regex = r"(\A|\s).?(%s).?(\Z|\s)" % re.escape(nick) 271 + match = re.search(regex, line) 272 + if match is not None: 273 + new_line = line[:match.start(2)] + nick_color+nick+reset + line[match.end(2):] 274 + line = new_line 275 + 276 + return line 277 + 278 + def colorize_input_cb(data, modifier, modifier_data, line): 279 + ''' Callback that does the colorizing in input ''' 280 + 281 + global ignore_nicks, ignore_channels, colored_nicks 282 + 283 + min_length = w.config_integer(colorize_config_option['min_nick_length']) 284 + 285 + if not w.config_boolean(colorize_config_option['colorize_input']): 286 + return line 287 + 288 + buffer = w.current_buffer() 289 + # Check if buffer has colorized nicks 290 + if buffer not in colored_nicks: 291 + return line 292 + 293 + channel = w.buffer_get_string(buffer, 'name') 294 + if channel and channel in ignore_channels: 295 + return line 296 + 297 + reset = w.color('reset') 298 + 299 + for words in valid_nick_re.findall(line): 300 + nick = words[1] 301 + # Check that nick is not ignored and longer than minimum length 302 + if len(nick) < min_length or nick in ignore_nicks: 303 + continue 304 + if nick in colored_nicks[buffer]: 305 + nick_color = colored_nicks[buffer][nick] 306 + line = line.replace(nick, '%s%s%s' % (nick_color, nick, reset)) 307 + 308 + return line 309 + 310 + def populate_nicks(*args): 311 + ''' Fills entire dict with all nicks weechat can see and what color it has 312 + assigned to it. ''' 313 + global colored_nicks 314 + 315 + colored_nicks = {} 316 + 317 + buffers = w.infolist_get('buffer', '', '') 318 + while w.infolist_next(buffers): 319 + buffer_ptr = w.infolist_pointer(buffers, 'pointer') 320 + my_nick = w.buffer_get_string(buffer_ptr, 'localvar_nick') 321 + nicklist = w.infolist_get('nicklist', buffer_ptr, '') 322 + while w.infolist_next(nicklist): 323 + if buffer_ptr not in colored_nicks: 324 + colored_nicks[buffer_ptr] = {} 325 + 326 + if w.infolist_string(nicklist, 'type') != 'nick': 327 + continue 328 + 329 + nick = w.infolist_string(nicklist, 'name') 330 + nick_color = colorize_nick_color(nick, my_nick) 331 + 332 + colored_nicks[buffer_ptr][nick] = nick_color 333 + 334 + w.infolist_free(nicklist) 335 + 336 + w.infolist_free(buffers) 337 + 338 + return w.WEECHAT_RC_OK 339 + 340 + def add_nick(data, signal, type_data): 341 + ''' Add nick to dict of colored nicks ''' 342 + global colored_nicks 343 + 344 + # Nicks can have , in them in some protocols 345 + splitted = type_data.split(',') 346 + pointer = splitted[0] 347 + nick = ",".join(splitted[1:]) 348 + if pointer not in colored_nicks: 349 + colored_nicks[pointer] = {} 350 + 351 + my_nick = w.buffer_get_string(pointer, 'localvar_nick') 352 + nick_color = colorize_nick_color(nick, my_nick) 353 + 354 + colored_nicks[pointer][nick] = nick_color 355 + 356 + return w.WEECHAT_RC_OK 357 + 358 + def remove_nick(data, signal, type_data): 359 + ''' Remove nick from dict with colored nicks ''' 360 + global colored_nicks 361 + 362 + # Nicks can have , in them in some protocols 363 + splitted = type_data.split(',') 364 + pointer = splitted[0] 365 + nick = ",".join(splitted[1:]) 366 + 367 + if pointer in colored_nicks and nick in colored_nicks[pointer]: 368 + del colored_nicks[pointer][nick] 369 + 370 + return w.WEECHAT_RC_OK 371 + 372 + def update_blacklist(*args): 373 + ''' Set the blacklist for channels and nicks. ''' 374 + global ignore_channels, ignore_nicks 375 + ignore_channels = w.config_string(colorize_config_option['blacklist_channels']).split(',') 376 + ignore_nicks = w.config_string(colorize_config_option['blacklist_nicks']).split(',') 377 + return w.WEECHAT_RC_OK 378 + 379 + if __name__ == "__main__": 380 + if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, 381 + SCRIPT_DESC, "", ""): 382 + colorize_config_init() 383 + colorize_config_read() 384 + 385 + # Run once to get data ready 386 + update_blacklist() 387 + populate_nicks() 388 + 389 + w.hook_signal('nicklist_nick_added', 'add_nick', '') 390 + w.hook_signal('nicklist_nick_removed', 'remove_nick', '') 391 + w.hook_modifier('weechat_print', 'colorize_cb', '') 392 + # Hook config for changing colors 393 + w.hook_config('weechat.color.chat_nick_colors', 'populate_nicks', '') 394 + w.hook_config('weechat.look.nick_color_hash', 'populate_nicks', '') 395 + # Hook for working togheter with other scripts (like colorize_lines) 396 + w.hook_modifier('colorize_nicks', 'colorize_cb', '') 397 + # Hook for modifying input 398 + w.hook_modifier('250|input_text_display', 'colorize_input_cb', '') 399 + # Hook for updating blacklist (this could be improved to use fnmatch) 400 + weechat.hook_config('%s.look.blacklist*' % SCRIPT_NAME, 'update_blacklist', '')
+561
weechat/.weechat/python/go.py
··· 1 + # -*- coding: utf-8 -*- 2 + # 3 + # Copyright (C) 2009-2014 Sébastien Helleu <flashcode@flashtux.org> 4 + # Copyright (C) 2010 m4v <lambdae2@gmail.com> 5 + # Copyright (C) 2011 stfn <stfnmd@googlemail.com> 6 + # 7 + # This program is free software; you can redistribute it and/or modify 8 + # it under the terms of the GNU General Public License as published by 9 + # the Free Software Foundation; either version 3 of the License, or 10 + # (at your option) any later version. 11 + # 12 + # This program is distributed in the hope that it will be useful, 13 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + # GNU General Public License for more details. 16 + # 17 + # You should have received a copy of the GNU General Public License 18 + # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 + # 20 + 21 + # 22 + # History: 23 + # 24 + # 2017-04-01, Sébastien Helleu <flashcode@flashtux.org>: 25 + # version 2.5: add option "buffer_number" 26 + # 2017-03-02, Sébastien Helleu <flashcode@flashtux.org>: 27 + # version 2.4: fix syntax and indentation error 28 + # 2017-02-25, Simmo Saan <simmo.saan@gmail.com> 29 + # version 2.3: fix fuzzy search breaking buffer number search display 30 + # 2016-01-28, ylambda <ylambda@koalabeast.com> 31 + # version 2.2: add option "fuzzy_search" 32 + # 2015-11-12, nils_2 <weechatter@arcor.de> 33 + # version 2.1: fix problem with buffer short_name "weechat", using option 34 + # "use_core_instead_weechat", see: 35 + # https://github.com/weechat/weechat/issues/574 36 + # 2014-05-12, Sébastien Helleu <flashcode@flashtux.org>: 37 + # version 2.0: add help on options, replace option "sort_by_activity" by 38 + # "sort" (add sort by name and first match at beginning of 39 + # name and by number), PEP8 compliance 40 + # 2012-11-26, Nei <anti.teamidiot.de> 41 + # version 1.9: add auto_jump option to automatically go to buffer when it 42 + # is uniquely selected 43 + # 2012-09-17, Sébastien Helleu <flashcode@flashtux.org>: 44 + # version 1.8: fix jump to non-active merged buffers (jump with buffer name 45 + # instead of number) 46 + # 2012-01-03 nils_2 <weechatter@arcor.de> 47 + # version 1.7: add option "use_core_instead_weechat" 48 + # 2012-01-03, Sébastien Helleu <flashcode@flashtux.org>: 49 + # version 1.6: make script compatible with Python 3.x 50 + # 2011-08-24, stfn <stfnmd@googlemail.com>: 51 + # version 1.5: /go with name argument jumps directly to buffer 52 + # Remember cursor position in buffer input 53 + # 2011-05-31, Elián Hanisch <lambdae2@gmail.com>: 54 + # version 1.4: Sort list of buffers by activity. 55 + # 2011-04-25, Sébastien Helleu <flashcode@flashtux.org>: 56 + # version 1.3: add info "go_running" (used by script input_lock.rb) 57 + # 2010-11-01, Sébastien Helleu <flashcode@flashtux.org>: 58 + # version 1.2: use high priority for hooks to prevent conflict with other 59 + # plugins/scripts (WeeChat >= 0.3.4 only) 60 + # 2010-03-25, Elián Hanisch <lambdae2@gmail.com>: 61 + # version 1.1: use a space to match the end of a string 62 + # 2009-11-16, Sébastien Helleu <flashcode@flashtux.org>: 63 + # version 1.0: add new option to display short names 64 + # 2009-06-15, Sébastien Helleu <flashcode@flashtux.org>: 65 + # version 0.9: fix typo in /help go with command /key 66 + # 2009-05-16, Sébastien Helleu <flashcode@flashtux.org>: 67 + # version 0.8: search buffer by number, fix bug when window is split 68 + # 2009-05-03, Sébastien Helleu <flashcode@flashtux.org>: 69 + # version 0.7: eat tab key (do not complete input, just move buffer 70 + # pointer) 71 + # 2009-05-02, Sébastien Helleu <flashcode@flashtux.org>: 72 + # version 0.6: sync with last API changes 73 + # 2009-03-22, Sébastien Helleu <flashcode@flashtux.org>: 74 + # version 0.5: update modifier signal name for input text display, 75 + # fix arguments for function string_remove_color 76 + # 2009-02-18, Sébastien Helleu <flashcode@flashtux.org>: 77 + # version 0.4: do not hook command and init options if register failed 78 + # 2009-02-08, Sébastien Helleu <flashcode@flashtux.org>: 79 + # version 0.3: case insensitive search for buffers names 80 + # 2009-02-08, Sébastien Helleu <flashcode@flashtux.org>: 81 + # version 0.2: add help about Tab key 82 + # 2009-02-08, Sébastien Helleu <flashcode@flashtux.org>: 83 + # version 0.1: initial release 84 + # 85 + 86 + """ 87 + Quick jump to buffers. 88 + (this script requires WeeChat 0.3.0 or newer) 89 + """ 90 + 91 + from __future__ import print_function 92 + 93 + SCRIPT_NAME = 'go' 94 + SCRIPT_AUTHOR = 'Sébastien Helleu <flashcode@flashtux.org>' 95 + SCRIPT_VERSION = '2.5' 96 + SCRIPT_LICENSE = 'GPL3' 97 + SCRIPT_DESC = 'Quick jump to buffers' 98 + 99 + SCRIPT_COMMAND = 'go' 100 + 101 + IMPORT_OK = True 102 + 103 + try: 104 + import weechat 105 + except ImportError: 106 + print('This script must be run under WeeChat.') 107 + print('Get WeeChat now at: http://www.weechat.org/') 108 + IMPORT_OK = False 109 + 110 + import re 111 + 112 + # script options 113 + SETTINGS = { 114 + 'color_number': ( 115 + 'yellow,magenta', 116 + 'color for buffer number (not selected)'), 117 + 'color_number_selected': ( 118 + 'yellow,red', 119 + 'color for selected buffer number'), 120 + 'color_name': ( 121 + 'black,cyan', 122 + 'color for buffer name (not selected)'), 123 + 'color_name_selected': ( 124 + 'black,brown', 125 + 'color for a selected buffer name'), 126 + 'color_name_highlight': ( 127 + 'red,cyan', 128 + 'color for highlight in buffer name (not selected)'), 129 + 'color_name_highlight_selected': ( 130 + 'red,brown', 131 + 'color for highlight in a selected buffer name'), 132 + 'message': ( 133 + 'Go to: ', 134 + 'message to display before list of buffers'), 135 + 'short_name': ( 136 + 'off', 137 + 'display and search in short names instead of buffer name'), 138 + 'sort': ( 139 + 'number,beginning', 140 + 'comma-separated list of keys to sort buffers ' 141 + '(the order is important, sorts are performed in the given order): ' 142 + 'name = sort by name (or short name), ', 143 + 'hotlist = sort by hotlist order, ' 144 + 'number = first match a buffer number before digits in name, ' 145 + 'beginning = first match at beginning of names (or short names); ' 146 + 'the default sort of buffers is by numbers'), 147 + 'use_core_instead_weechat': ( 148 + 'off', 149 + 'use name "core" instead of "weechat" for core buffer'), 150 + 'auto_jump': ( 151 + 'off', 152 + 'automatically jump to buffer when it is uniquely selected'), 153 + 'fuzzy_search': ( 154 + 'off', 155 + 'search buffer matches using approximation'), 156 + 'buffer_number': ( 157 + 'on', 158 + 'display buffer number'), 159 + } 160 + 161 + # hooks management 162 + HOOK_COMMAND_RUN = { 163 + 'input': ('/input *', 'go_command_run_input'), 164 + 'buffer': ('/buffer *', 'go_command_run_buffer'), 165 + 'window': ('/window *', 'go_command_run_window'), 166 + } 167 + hooks = {} 168 + 169 + # input before command /go (we'll restore it later) 170 + saved_input = '' 171 + saved_input_pos = 0 172 + 173 + # last user input (if changed, we'll update list of matching buffers) 174 + old_input = None 175 + 176 + # matching buffers 177 + buffers = [] 178 + buffers_pos = 0 179 + 180 + 181 + def go_option_enabled(option): 182 + """Checks if a boolean script option is enabled or not.""" 183 + return weechat.config_string_to_boolean(weechat.config_get_plugin(option)) 184 + 185 + 186 + def go_info_running(data, info_name, arguments): 187 + """Returns "1" if go is running, otherwise "0".""" 188 + return '1' if 'modifier' in hooks else '0' 189 + 190 + 191 + def go_unhook_one(hook): 192 + """Unhook something hooked by this script.""" 193 + global hooks 194 + if hook in hooks: 195 + weechat.unhook(hooks[hook]) 196 + del hooks[hook] 197 + 198 + 199 + def go_unhook_all(): 200 + """Unhook all.""" 201 + go_unhook_one('modifier') 202 + for hook in HOOK_COMMAND_RUN: 203 + go_unhook_one(hook) 204 + 205 + 206 + def go_hook_all(): 207 + """Hook command_run and modifier.""" 208 + global hooks 209 + priority = '' 210 + version = weechat.info_get('version_number', '') or 0 211 + # use high priority for hook to prevent conflict with other plugins/scripts 212 + # (WeeChat >= 0.3.4 only) 213 + if int(version) >= 0x00030400: 214 + priority = '2000|' 215 + for hook, value in HOOK_COMMAND_RUN.items(): 216 + if hook not in hooks: 217 + hooks[hook] = weechat.hook_command_run( 218 + '%s%s' % (priority, value[0]), 219 + value[1], '') 220 + if 'modifier' not in hooks: 221 + hooks['modifier'] = weechat.hook_modifier( 222 + 'input_text_display_with_cursor', 'go_input_modifier', '') 223 + 224 + 225 + def go_start(buf): 226 + """Start go on buffer.""" 227 + global saved_input, saved_input_pos, old_input, buffers_pos 228 + go_hook_all() 229 + saved_input = weechat.buffer_get_string(buf, 'input') 230 + saved_input_pos = weechat.buffer_get_integer(buf, 'input_pos') 231 + weechat.buffer_set(buf, 'input', '') 232 + old_input = None 233 + buffers_pos = 0 234 + 235 + 236 + def go_end(buf): 237 + """End go on buffer.""" 238 + global saved_input, saved_input_pos, old_input 239 + go_unhook_all() 240 + weechat.buffer_set(buf, 'input', saved_input) 241 + weechat.buffer_set(buf, 'input_pos', str(saved_input_pos)) 242 + old_input = None 243 + 244 + 245 + def go_match_beginning(buf, string): 246 + """Check if a string matches the beginning of buffer name/short name.""" 247 + if not string: 248 + return False 249 + esc_str = re.escape(string) 250 + if re.search(r'^#?' + esc_str, buf['name']) \ 251 + or re.search(r'^#?' + esc_str, buf['short_name']): 252 + return True 253 + return False 254 + 255 + 256 + def go_match_fuzzy(name, string): 257 + """Check if string matches name using approximation.""" 258 + if not string: 259 + return False 260 + 261 + name_len = len(name) 262 + string_len = len(string) 263 + 264 + if string_len > name_len: 265 + return False 266 + if name_len == string_len: 267 + return name == string 268 + 269 + # Attempt to match all chars somewhere in name 270 + prev_index = -1 271 + for i, char in enumerate(string): 272 + index = name.find(char, prev_index+1) 273 + if index == -1: 274 + return False 275 + prev_index = index 276 + return True 277 + 278 + 279 + def go_now(buf, args): 280 + """Go to buffer specified by args.""" 281 + listbuf = go_matching_buffers(args) 282 + if not listbuf: 283 + return 284 + 285 + # prefer buffer that matches at beginning (if option is enabled) 286 + if 'beginning' in weechat.config_get_plugin('sort').split(','): 287 + for index in range(len(listbuf)): 288 + if go_match_beginning(listbuf[index], args): 289 + weechat.command(buf, 290 + '/buffer ' + str(listbuf[index]['full_name'])) 291 + return 292 + 293 + # jump to first buffer in matching buffers by default 294 + weechat.command(buf, '/buffer ' + str(listbuf[0]['full_name'])) 295 + 296 + 297 + def go_cmd(data, buf, args): 298 + """Command "/go": just hook what we need.""" 299 + global hooks 300 + if args: 301 + go_now(buf, args) 302 + elif 'modifier' in hooks: 303 + go_end(buf) 304 + else: 305 + go_start(buf) 306 + return weechat.WEECHAT_RC_OK 307 + 308 + 309 + def go_matching_buffers(strinput): 310 + """Return a list with buffers matching user input.""" 311 + global buffers_pos 312 + listbuf = [] 313 + if len(strinput) == 0: 314 + buffers_pos = 0 315 + strinput = strinput.lower() 316 + infolist = weechat.infolist_get('buffer', '', '') 317 + while weechat.infolist_next(infolist): 318 + short_name = weechat.infolist_string(infolist, 'short_name') 319 + if go_option_enabled('short_name'): 320 + name = weechat.infolist_string(infolist, 'short_name') 321 + else: 322 + name = weechat.infolist_string(infolist, 'name') 323 + if name == 'weechat' \ 324 + and go_option_enabled('use_core_instead_weechat') \ 325 + and weechat.infolist_string(infolist, 'plugin_name') == 'core': 326 + name = 'core' 327 + number = weechat.infolist_integer(infolist, 'number') 328 + full_name = weechat.infolist_string(infolist, 'full_name') 329 + if not full_name: 330 + full_name = '%s.%s' % ( 331 + weechat.infolist_string(infolist, 'plugin_name'), 332 + weechat.infolist_string(infolist, 'name')) 333 + pointer = weechat.infolist_pointer(infolist, 'pointer') 334 + matching = name.lower().find(strinput) >= 0 335 + if not matching and strinput[-1] == ' ': 336 + matching = name.lower().endswith(strinput.strip()) 337 + if not matching and go_option_enabled('fuzzy_search'): 338 + matching = go_match_fuzzy(name.lower(), strinput) 339 + if not matching and strinput.isdigit(): 340 + matching = str(number).startswith(strinput) 341 + if len(strinput) == 0 or matching: 342 + listbuf.append({ 343 + 'number': number, 344 + 'short_name': short_name, 345 + 'name': name, 346 + 'full_name': full_name, 347 + 'pointer': pointer, 348 + }) 349 + weechat.infolist_free(infolist) 350 + 351 + # sort buffers 352 + hotlist = [] 353 + infolist = weechat.infolist_get('hotlist', '', '') 354 + while weechat.infolist_next(infolist): 355 + hotlist.append( 356 + weechat.infolist_pointer(infolist, 'buffer_pointer')) 357 + weechat.infolist_free(infolist) 358 + last_index_hotlist = len(hotlist) 359 + 360 + def _sort_name(buf): 361 + """Sort buffers by name (or short name).""" 362 + return buf['name'] 363 + 364 + def _sort_hotlist(buf): 365 + """Sort buffers by hotlist order.""" 366 + try: 367 + return hotlist.index(buf['pointer']) 368 + except ValueError: 369 + # not in hotlist, always last. 370 + return last_index_hotlist 371 + 372 + def _sort_match_number(buf): 373 + """Sort buffers by match on number.""" 374 + return 0 if str(buf['number']) == strinput else 1 375 + 376 + def _sort_match_beginning(buf): 377 + """Sort buffers by match at beginning.""" 378 + return 0 if go_match_beginning(buf, strinput) else 1 379 + 380 + funcs = { 381 + 'name': _sort_name, 382 + 'hotlist': _sort_hotlist, 383 + 'number': _sort_match_number, 384 + 'beginning': _sort_match_beginning, 385 + } 386 + 387 + for key in weechat.config_get_plugin('sort').split(','): 388 + if key in funcs: 389 + listbuf = sorted(listbuf, key=funcs[key]) 390 + 391 + if not strinput: 392 + index = [i for i, buf in enumerate(listbuf) 393 + if buf['pointer'] == weechat.current_buffer()] 394 + if index: 395 + buffers_pos = index[0] 396 + 397 + return listbuf 398 + 399 + 400 + def go_buffers_to_string(listbuf, pos, strinput): 401 + """Return string built with list of buffers found (matching user input).""" 402 + string = '' 403 + strinput = strinput.lower() 404 + for i in range(len(listbuf)): 405 + selected = '_selected' if i == pos else '' 406 + buffer_name = listbuf[i]['name'] 407 + index = buffer_name.lower().find(strinput) 408 + if index >= 0: 409 + index2 = index + len(strinput) 410 + name = '%s%s%s%s%s' % ( 411 + buffer_name[:index], 412 + weechat.color(weechat.config_get_plugin( 413 + 'color_name_highlight' + selected)), 414 + buffer_name[index:index2], 415 + weechat.color(weechat.config_get_plugin( 416 + 'color_name' + selected)), 417 + buffer_name[index2:]) 418 + elif go_option_enabled("fuzzy_search") and \ 419 + go_match_fuzzy(buffer_name.lower(), strinput): 420 + name = "" 421 + prev_index = -1 422 + for char in strinput.lower(): 423 + index = buffer_name.lower().find(char, prev_index+1) 424 + if prev_index < 0: 425 + name += buffer_name[:index] 426 + name += weechat.color(weechat.config_get_plugin( 427 + 'color_name_highlight' + selected)) 428 + if prev_index >= 0 and index > prev_index+1: 429 + name += weechat.color(weechat.config_get_plugin( 430 + 'color_name' + selected)) 431 + name += buffer_name[prev_index+1:index] 432 + name += weechat.color(weechat.config_get_plugin( 433 + 'color_name_highlight' + selected)) 434 + name += buffer_name[index] 435 + prev_index = index 436 + 437 + name += weechat.color(weechat.config_get_plugin( 438 + 'color_name' + selected)) 439 + name += buffer_name[prev_index+1:] 440 + else: 441 + name = buffer_name 442 + string += ' ' 443 + if go_option_enabled('buffer_number'): 444 + string += '%s%s' % ( 445 + weechat.color(weechat.config_get_plugin( 446 + 'color_number' + selected)), 447 + str(listbuf[i]['number'])) 448 + string += '%s%s%s' % ( 449 + weechat.color(weechat.config_get_plugin( 450 + 'color_name' + selected)), 451 + name, 452 + weechat.color('reset')) 453 + return ' ' + string if string else '' 454 + 455 + 456 + def go_input_modifier(data, modifier, modifier_data, string): 457 + """This modifier is called when input text item is built by WeeChat. 458 + 459 + This is commonly called after changes in input or cursor move: it builds 460 + a new input with prefix ("Go to:"), and suffix (list of buffers found). 461 + """ 462 + global old_input, buffers, buffers_pos 463 + if modifier_data != weechat.current_buffer(): 464 + return '' 465 + names = '' 466 + new_input = weechat.string_remove_color(string, '') 467 + new_input = new_input.lstrip() 468 + if old_input is None or new_input != old_input: 469 + old_buffers = buffers 470 + buffers = go_matching_buffers(new_input) 471 + if buffers != old_buffers and len(new_input) > 0: 472 + if len(buffers) == 1 and go_option_enabled('auto_jump'): 473 + weechat.command(modifier_data, '/wait 1ms /input return') 474 + buffers_pos = 0 475 + old_input = new_input 476 + names = go_buffers_to_string(buffers, buffers_pos, new_input.strip()) 477 + return weechat.config_get_plugin('message') + string + names 478 + 479 + 480 + def go_command_run_input(data, buf, command): 481 + """Function called when a command "/input xxx" is run.""" 482 + global buffers, buffers_pos 483 + if command == '/input search_text' or command.find('/input jump') == 0: 484 + # search text or jump to another buffer is forbidden now 485 + return weechat.WEECHAT_RC_OK_EAT 486 + elif command == '/input complete_next': 487 + # choose next buffer in list 488 + buffers_pos += 1 489 + if buffers_pos >= len(buffers): 490 + buffers_pos = 0 491 + weechat.hook_signal_send('input_text_changed', 492 + weechat.WEECHAT_HOOK_SIGNAL_STRING, '') 493 + return weechat.WEECHAT_RC_OK_EAT 494 + elif command == '/input complete_previous': 495 + # choose previous buffer in list 496 + buffers_pos -= 1 497 + if buffers_pos < 0: 498 + buffers_pos = len(buffers) - 1 499 + weechat.hook_signal_send('input_text_changed', 500 + weechat.WEECHAT_HOOK_SIGNAL_STRING, '') 501 + return weechat.WEECHAT_RC_OK_EAT 502 + elif command == '/input return': 503 + # switch to selected buffer (if any) 504 + go_end(buf) 505 + if len(buffers) > 0: 506 + weechat.command( 507 + buf, '/buffer ' + str(buffers[buffers_pos]['full_name'])) 508 + return weechat.WEECHAT_RC_OK_EAT 509 + return weechat.WEECHAT_RC_OK 510 + 511 + 512 + def go_command_run_buffer(data, buf, command): 513 + """Function called when a command "/buffer xxx" is run.""" 514 + return weechat.WEECHAT_RC_OK_EAT 515 + 516 + 517 + def go_command_run_window(data, buf, command): 518 + """Function called when a command "/window xxx" is run.""" 519 + return weechat.WEECHAT_RC_OK_EAT 520 + 521 + 522 + def go_unload_script(): 523 + """Function called when script is unloaded.""" 524 + go_unhook_all() 525 + return weechat.WEECHAT_RC_OK 526 + 527 + 528 + def go_main(): 529 + """Entry point.""" 530 + if not weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, 531 + SCRIPT_LICENSE, SCRIPT_DESC, 532 + 'go_unload_script', ''): 533 + return 534 + weechat.hook_command( 535 + SCRIPT_COMMAND, 536 + 'Quick jump to buffers', '[name]', 537 + 'name: directly jump to buffer by name (without argument, list is ' 538 + 'displayed)\n\n' 539 + 'You can bind command to a key, for example:\n' 540 + ' /key bind meta-g /go\n\n' 541 + 'You can use completion key (commonly Tab and shift-Tab) to select ' 542 + 'next/previous buffer in list.', 543 + '%(buffers_names)', 544 + 'go_cmd', '') 545 + 546 + # set default settings 547 + version = weechat.info_get('version_number', '') or 0 548 + for option, value in SETTINGS.items(): 549 + if not weechat.config_is_set_plugin(option): 550 + weechat.config_set_plugin(option, value[0]) 551 + if int(version) >= 0x00030500: 552 + weechat.config_set_desc_plugin( 553 + option, '%s (default: "%s")' % (value[1], value[0])) 554 + weechat.hook_info('go_running', 555 + 'Return "1" if go is running, otherwise "0"', 556 + '', 557 + 'go_info_running', '') 558 + 559 + 560 + if __name__ == "__main__" and IMPORT_OK: 561 + go_main()
+2 -1
weechat/.weechat/relay.conf
··· 32 32 compression_level = 6 33 33 ipv6 = on 34 34 max_clients = 5 35 - password = "" 35 + password = "${sec.data.pass}" 36 36 ssl_cert_key = "%h/ssl/relay.pem" 37 37 ssl_priorities = "NORMAL:-VERS-SSL3.0" 38 38 websocket_allowed_origins = "" ··· 46 46 backlog_time_format = "[%H:%M] " 47 47 48 48 [port] 49 + weechat = 9090
+6 -2
weechat/.weechat/weechat.conf
··· 28 28 bare_display_exit_on_input = on 29 29 bare_display_time_format = "%H:%M" 30 30 buffer_auto_renumber = on 31 - buffer_notify_default = all 31 + buffer_notify_default = highlight 32 32 buffer_position = end 33 33 buffer_search_case_sensitive = off 34 34 buffer_search_force_default = off ··· 85 85 jump_smart_back_to_buffer = on 86 86 key_bind_safe = on 87 87 key_grab_delay = 800 88 - mouse = on 88 + mouse = off 89 89 mouse_timer_delay = 100 90 90 nick_color_force = "" 91 91 nick_color_hash = djb2 ··· 354 354 default.current = on 355 355 356 356 [notify] 357 + irc.darwin = message 358 + irc.hashbang = message 359 + irc.sdf = message 360 + irc.tilde = message 357 361 358 362 [filter] 359 363