From 2d4e505b0462bf08aa368941941d17979812e285 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Thu, 8 Aug 2019 19:06:57 +0100 Subject: [PATCH 01/16] vim: provide default location for clang-tidy syntastic --- vim/vimrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vim/vimrc b/vim/vimrc index b9acfe6..9995296 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -600,6 +600,8 @@ let g:syntastic_style_warning_symbol='S' let g:syntastic_always_populate_loc_list=1 nmap y :SyntasticCheck +let g:syntastic_cpp_clang_tidy_post_args = "-p build*" + if ! &diff let g:syntastic_check_on_open=1 endif -- 2.49.0 From abc4878101c227a526ee0701b51e358e452ec7d9 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Thu, 8 Aug 2019 19:07:29 +0100 Subject: [PATCH 02/16] vim: errorformat for CMake --- vim/ftplugin/cmake.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vim/ftplugin/cmake.vim b/vim/ftplugin/cmake.vim index 7702eb0..6eb785b 100644 --- a/vim/ftplugin/cmake.vim +++ b/vim/ftplugin/cmake.vim @@ -7,3 +7,8 @@ let g:switch_custom_definitions = \ [ \ ['ON', 'OFF'] \ ] + +setlocal errorformat= +setlocal errorformat+=%+ICall\ Stack%.%#:,%Z\ \ %f:%l\ (%o) +setlocal errorformat+=%ECMake\ %trror%.%#\ at\ %f:%l\ (%o):,%Z\ \ %m +setlocal errorformat+=%WCMake\ %tarning%.%#\ at\ %f:%l\ (%o):,%Z\ \ %m -- 2.49.0 From 62f723d271d39da9dd884026fdbd40b3b321c692 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Fri, 9 Aug 2019 08:48:11 +0100 Subject: [PATCH 03/16] ssh: Finally found a way to securely add ssh_config This will not expose any users to the wider world. --- Makefile | 5 +++++ ssh/config | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 ssh/config diff --git a/Makefile b/Makefile index 855a5c5..1477771 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ dircolors: $(XDG_CONFIG_HOME) gdb: mkdir $(XDG_DATA_HOME)/gdb + ln -sfT $(APATH)/gdb $(XDG_CONFIG_HOME)/gdb ln -sfT $(APATH)/gdbinit ~/.gdbinit ln -sfT $(APATH)/cgdb ~/.cgdb .PHONY: gdb @@ -63,6 +64,10 @@ qutebrowser: $(XDG_CONFIG_HOME) mkdir -p ~/downloads .PHONY: qutebrowser +ssh: + ln -sfT $(APATH)/ssh/config ~/.ssh/config +.PHONY: ssh + systemd: $(XDG_CONFIG_HOME) ln -sfT $(APATH)/$@ $(XDG_CONFIG_HOME)/$@ .PHONY: systemd diff --git a/ssh/config b/ssh/config new file mode 100644 index 0000000..d159ed2 --- /dev/null +++ b/ssh/config @@ -0,0 +1,51 @@ +Include private-config + +Host rmz.io +ForwardAgent yes + +Host deepthought +ForwardAgent yes + +Host uh-nuc01 +HostName localhost +Port 22222 +ForwardAgent yes +ProxyJump rmz.io + +Host tardis tardis.uni.cx tardis.rmz.io +HostName tardis.rmz.io +ForwardAgent yes +StreamLocalBindUnlink yes + +Host kelmis +HostName kelmis.uni.cx +Port 5555 +DynamicForward 1080 +IdentityFile ~/.ssh/old/id_rsa + +Host chronos +IdentityFile ~/.ssh/old/id_rsa + +Host buildserver +Port 5555 +HostName dezponia.se +# RemoteForward /home/ramsi/.config/gnupg/S.gpg-agent /home/ramsi/.config/gnupg/S.gpg-agent +# ExitOnForwardFailure yes + +Host bulbasaur bulbasaur.chakralinux.org +HostName bulbasaur.chakralinux.org + +Host rsync.chakralinux.org +HostName rsync.chakralinux.org +IdentityFile ~/.ssh/old/id_rsa + +Host chakra-sf +HostName frs.sourceforge.net +IdentityFile ~/.ssh/old/id_rsa_github + +Host * +ControlMaster auto +ControlPersist 1h +ServerAliveInterval 30 +ServerAliveCountMax 4 +AddKeysToAgent yes -- 2.49.0 From 903201832956f881110097e79f70658c99046106 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Fri, 9 Aug 2019 08:54:33 +0100 Subject: [PATCH 04/16] ssh: clean old servers --- ssh/config | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/ssh/config b/ssh/config index d159ed2..580aac1 100644 --- a/ssh/config +++ b/ssh/config @@ -1,3 +1,5 @@ +# vim: ft=sshconfig + Include private-config Host rmz.io @@ -12,37 +14,6 @@ Port 22222 ForwardAgent yes ProxyJump rmz.io -Host tardis tardis.uni.cx tardis.rmz.io -HostName tardis.rmz.io -ForwardAgent yes -StreamLocalBindUnlink yes - -Host kelmis -HostName kelmis.uni.cx -Port 5555 -DynamicForward 1080 -IdentityFile ~/.ssh/old/id_rsa - -Host chronos -IdentityFile ~/.ssh/old/id_rsa - -Host buildserver -Port 5555 -HostName dezponia.se -# RemoteForward /home/ramsi/.config/gnupg/S.gpg-agent /home/ramsi/.config/gnupg/S.gpg-agent -# ExitOnForwardFailure yes - -Host bulbasaur bulbasaur.chakralinux.org -HostName bulbasaur.chakralinux.org - -Host rsync.chakralinux.org -HostName rsync.chakralinux.org -IdentityFile ~/.ssh/old/id_rsa - -Host chakra-sf -HostName frs.sourceforge.net -IdentityFile ~/.ssh/old/id_rsa_github - Host * ControlMaster auto ControlPersist 1h -- 2.49.0 From 2853b0a2519ac22350f6fb41e2c23e1fc854f0de Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Fri, 9 Aug 2019 08:55:45 +0100 Subject: [PATCH 05/16] Makefile: add ssh to core_files to be installed --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1477771..87fa04d 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ DOTFILES := goobookrc msmtp* profile tmux.conf weechat Xresources CONFIGFILES := compton.conf mpv offlineimap ranger retroarch xbindkeys xkb .PHONY: core_files -core_files: dircolors git systemd vim zsh +core_files: dircolors git ssh systemd vim zsh .PHONY: install $(FILES) $(DOTFILES) $(CONFIGFILES) install: $(FILES) $(DOTFILES) $(CONFIGFILES) -- 2.49.0 From 32a180d2d9ce65bca5e463d42c3e6d6ab918b8b7 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Sat, 10 Aug 2019 17:20:38 +0100 Subject: [PATCH 06/16] vim: use Termdebug in new tab and close when finished --- vim/ftplugin/cpp.vim | 10 ++++++++++ vim/vimrc | 3 --- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/vim/ftplugin/cpp.vim b/vim/ftplugin/cpp.vim index 06d4861..a8c9a51 100644 --- a/vim/ftplugin/cpp.vim +++ b/vim/ftplugin/cpp.vim @@ -63,6 +63,16 @@ setlocal errorformat+=%X%*\\a:\ Leaving\ directory\ [`']%f' setlocal errorformat+=%*[^[]\[%tRROR\]%m\ \[%f:%l\] setlocal errorformat+=%*[^[]\[%tARNING\]%m\ \[%f:%l\] +packadd termdebug +let g:termdebug_wide = 1 +function! s:Debug(...) + tabedit % + let t:debug_tab=1 + au BufDelete !gdb ++once if exists('t:debug_tab') | tabclose | endif +endfunction +command! -nargs=* -complete=file -bang Debug call Debug() | Termdebug +command! -nargs=+ -complete=file -bang DebugCommand call Debug() | TermdebugCommand + setlocal foldmethod=syntax " set foldlevel according to number of matches of 'namespace' and 'class' not " containing ';' diff --git a/vim/vimrc b/vim/vimrc index 9995296..6192c9f 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -333,9 +333,6 @@ augroup terminal au! au TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif augroup END -" vertical split TermDebug -let g:termdebug_wide = 1 -command! -nargs=* -bang -complete=file Debug tabedit % | Termdebug " bindings {{{1 -- 2.49.0 From 70daf4df6ee0b3be03d0bdcbb69d4642a30f426f Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Wed, 28 Aug 2019 13:44:23 +0100 Subject: [PATCH 07/16] systemd: allow installing backdoor timer --- systemd/user/backdoor@.timer | 3 +++ 1 file changed, 3 insertions(+) diff --git a/systemd/user/backdoor@.timer b/systemd/user/backdoor@.timer index 2e39009..4fb0574 100644 --- a/systemd/user/backdoor@.timer +++ b/systemd/user/backdoor@.timer @@ -6,3 +6,6 @@ Description=Reverse SSH Tunnel Timer OnBootSec=5min # If unit becomes inactive, try again later OnUnitInactiveSec=10min + +[Install] +WantedBy=timers.target -- 2.49.0 From ee75082b81d3948635ad88ba8ca3d446bc978e59 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Mon, 2 Sep 2019 12:22:05 +0100 Subject: [PATCH 08/16] weechat: add script to run wee-slack in tmux --- bin/wee-slack | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 bin/wee-slack diff --git a/bin/wee-slack b/bin/wee-slack new file mode 100755 index 0000000..85a5ed3 --- /dev/null +++ b/bin/wee-slack @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +tmux -u new-session -As wee-slack /usr/bin/weechat -- 2.49.0 From c65e06ca25d7ed75712f2141d232795561c90d81 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Mon, 2 Sep 2019 12:27:44 +0100 Subject: [PATCH 09/16] weechat: update config --- weechat/relay.conf | 5 +++++ weechat/{aspell.conf => spell.conf} | 2 +- weechat/weechat.conf | 2 ++ weechat/xfer.conf | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) rename weechat/{aspell.conf => spell.conf} (96%) diff --git a/weechat/relay.conf b/weechat/relay.conf index ef5619a..f9ab68b 100644 --- a/weechat/relay.conf +++ b/weechat/relay.conf @@ -47,4 +47,9 @@ backlog_since_last_message = off backlog_tags = "irc_privmsg" backlog_time_format = "[%H:%M] " +[weechat] +commands = "" + [port] + +[path] diff --git a/weechat/aspell.conf b/weechat/spell.conf similarity index 96% rename from weechat/aspell.conf rename to weechat/spell.conf index 27b16b8..04ec3a6 100644 --- a/weechat/aspell.conf +++ b/weechat/spell.conf @@ -1,5 +1,5 @@ # -# weechat -- aspell.conf +# weechat -- spell.conf # # WARNING: It is NOT recommended to edit this file by hand, # especially if WeeChat is running. diff --git a/weechat/weechat.conf b/weechat/weechat.conf index 8864280..1a7be38 100644 --- a/weechat/weechat.conf +++ b/weechat/weechat.conf @@ -35,6 +35,7 @@ buffer_search_force_default = off buffer_search_regex = off buffer_search_where = message buffer_time_format = "${color:253}%H:${color:245}%M" +buffer_time_same = "" color_basic_force_bold = off color_inactive_buffer = off color_inactive_message = on @@ -111,6 +112,7 @@ prefix_join = "▬▬▶" prefix_network = "--" prefix_quit = "◀▬▬" prefix_same_nick = "" +prefix_same_nick_middle = "" prefix_suffix = "│" quote_nick_prefix = "<" quote_nick_suffix = ">" diff --git a/weechat/xfer.conf b/weechat/xfer.conf index fd8b814..d1dea52 100644 --- a/weechat/xfer.conf +++ b/weechat/xfer.conf @@ -31,7 +31,8 @@ fast_send = on own_ip = "" port_range = "" send_ack = on -speed_limit = 0 +speed_limit_recv = 0 +speed_limit_send = 0 timeout = 300 [file] -- 2.49.0 From c8a632a3ff5226a6e61ddc19b479abfe565ba3dd Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Mon, 2 Sep 2019 12:37:05 +0100 Subject: [PATCH 10/16] weechat: update plugins --- weechat/perl/highmon.pl | 13 ++++-- weechat/python/autosort.py | 87 +++++++++++++++++++++++++++++--------- weechat/python/grep.py | 68 +++++++++++++++-------------- 3 files changed, 114 insertions(+), 54 deletions(-) diff --git a/weechat/perl/highmon.pl b/weechat/perl/highmon.pl index 1c07712..066fa43 100644 --- a/weechat/perl/highmon.pl +++ b/weechat/perl/highmon.pl @@ -1,6 +1,6 @@ # # highmon.pl - Highlight Monitoring for weechat 0.3.0 -# Version 2.5 +# Version 2.6 # # Add 'Highlight Monitor' buffer/bar to log all highlights in one spot # @@ -73,6 +73,8 @@ # Bugs and feature requests at: https://github.com/KenjiE20/highmon # History: +# 2019-05-13, HubbeKing +# v2.6: -add: send "logger_backlog" signal on buffer open if logging is enabled # 2014-08-16, KenjiE20 : # v2.5: -add: clearbar command to clear bar output # -add: firstrun output prompt to check the help text for set up hints as they were being missed @@ -306,7 +308,7 @@ sub highmon_buffer_open # Turn off notify, highlights if ($highmon_buffer ne "") { - if (weechat::config_get_plugin("hotlist_show" eq "off")) + if (weechat::config_get_plugin("hotlist_show") eq "off") { weechat::buffer_set($highmon_buffer, "notify", "0"); } @@ -317,6 +319,11 @@ sub highmon_buffer_open { weechat::buffer_set($highmon_buffer, "localvar_set_no_log", "1"); } + # send "logger_backlog" signal if logging is enabled to display backlog + if (weechat::config_get_plugin("logging") eq "on") + { + weechat::hook_signal_send("logger_backlog", weechat::WEECHAT_HOOK_SIGNAL_POINTER, $highmon_buffer) + } } return weechat::WEECHAT_RC_OK; } @@ -1124,7 +1131,7 @@ sub format_buffer_name } # Check result of register, and attempt to behave in a sane manner -if (!weechat::register("highmon", "KenjiE20", "2.5", "GPL3", "Highlight Monitor", "", "")) +if (!weechat::register("highmon", "KenjiE20", "2.6", "GPL3", "Highlight Monitor", "", "")) { # Double load weechat::print ("", "\tHighmon is already loaded"); diff --git a/weechat/python/autosort.py b/weechat/python/autosort.py index 46a840c..8f7c263 100644 --- a/weechat/python/autosort.py +++ b/weechat/python/autosort.py @@ -25,6 +25,10 @@ # # Changelog: +# 3.6: +# * Add more documentation on provided info hooks. +# 3.5: +# * Add ${info:autosort_escape,...} to escape arguments for other info hooks. # 3.4: # * Fix rate-limit of sorting to prevent high CPU load and lock-ups. # * Fix bug in parsing empty arguments for info hooks. @@ -76,7 +80,7 @@ import weechat SCRIPT_NAME = 'autosort' SCRIPT_AUTHOR = 'Maarten de Vries ' -SCRIPT_VERSION = '3.4' +SCRIPT_VERSION = '3.6' SCRIPT_LICENSE = 'GPL3' SCRIPT_DESC = 'Flexible automatic (or manual) buffer sorting based on eval expressions.' @@ -184,7 +188,7 @@ class Config: 'irc_last': '${if:${buffer.plugin.name}==irc}', 'irc_raw_first': '${if:${buffer.full_name}!=irc.irc_raw}', 'irc_raw_last': '${if:${buffer.full_name}==irc.irc_raw}', - 'hashless_name': '${info:autosort_replace,#,,${buffer.name}}', + 'hashless_name': '${info:autosort_replace,#,,${info:autosort_escape,${buffer.name}}}', }) default_signal_delay = 5 @@ -746,6 +750,17 @@ def parse_args(args, max = None): if args is None: break return result, args +def on_info_escape(pointer, name, arguments): + result = '' + for c in arguments: + if c == '\\': + result += '\\\\' + elif c == ',': + result += '\\,' + else: + result +=c + return result + def on_info_replace(pointer, name, arguments): arguments, rest = parse_args(arguments, 3) if rest or len(arguments) < 3: @@ -910,6 +925,36 @@ Rename a helper variable. Swap the expressions of two helper variables in the list. +{*white}# Info hooks{reset} +Autosort comes with a number of info hooks to add some extra functionality to regular weechat eval strings. +Info hooks can be used in eval strings in the form of {cyan}${{info:some_hook,arguments}}{reset}. + +Commas and backslashes in arguments to autosort info hooks (except for {cyan}${{info:autosort_escape}}{reset}) must be escaped with a backslash. + +{*white}${{info:{brown}autosort_replace{white},{cyan}pattern{white},{cyan}replacement{white},{cyan}source{white}}}{reset} +Replace all occurrences of {cyan}pattern{reset} with {cyan}replacement{reset} in the string {cyan}source{reset}. +Can be used to ignore certain strings when sorting by replacing them with an empty string. + +For example: {cyan}${{info:autosort_replace,cat,dog,the dog is meowing}}{reset} expands to "the cat is meowing". + +{*white}${{info:{brown}autosort_order{white},{cyan}value{white},{cyan}option0{white},{cyan}option1{white},{cyan}option2{white},{cyan}...{white}}} +Generate a zero-padded number that corresponds to the index of {cyan}value{reset} in the list of options. +If one of the options is the special value {brown}*{reset}, then any value not explicitly mentioned will be sorted at that position. +Otherwise, any value that does not match an option is assigned the highest number available. +Can be used to easily sort buffers based on a manual sequence. + +For example: {cyan}${{info:autosort_order,${{server}},freenode,oftc,efnet}}{reset} will sort freenode before oftc, followed by efnet and then any remaining servers. +Alternatively, {cyan}${{info:autosort_order,${{server}},freenode,oftc,*,efnet}}{reset} will sort any unlisted servers after freenode and oftc, but before efnet. + +{*white}${{info:{brown}autosort_escape{white},{cyan}text{white}}}{reset} +Escape commas and backslashes in {cyan}text{reset} by prepending them with a backslash. +This is mainly useful to pass arbitrary eval strings as arguments to other autosort info hooks. +Otherwise, an eval string that expands to something with a comma would be interpreted as multiple arguments. + +For example, it can be used to safely pass buffer names to {cyan}${{info:autosort_replace}}{reset} like so: +{cyan}${{info:autosort_replace,##,#,${{info:autosort_escape,${{buffer.name}}}}}}{reset}. + + {*white}# Description Autosort is a weechat script to automatically keep your buffers sorted. The sort order can be customized by defining your own sort rules, but the default should @@ -934,17 +979,6 @@ readable. They can be used in the main sort rules as variables. For example, a helper variable named `{cyan}foo{reset}` can be accessed in a main rule with the string `{cyan}${{foo}}{reset}`. -{*white}# Replacing substrings{reset} -There is no default method for replacing text inside eval expressions. However, -autosort adds a `replace` info hook that can be used inside eval expressions: - {cyan}${{info:autosort_replace,from,to,text}}{reset} - -For example, to strip all hashes from a buffer name, you could write: - {cyan}${{info:autosort_replace,#,,${{buffer.name}}}}{reset} - -You can escape commas and backslashes inside the arguments by prefixing them with -a backslash. - {*white}# Automatic or manual sorting{reset} By default, autosort will automatically sort your buffer list whenever a buffer is opened, merged, unmerged or renamed. This should keep your buffers sorted in @@ -973,15 +1007,29 @@ structure with the following setting (modify to suit your need): command_completion = '%(plugin_autosort) %(plugin_autosort) %(plugin_autosort) %(plugin_autosort) %(plugin_autosort)' -info_replace_description = 'Replace all occurences of `from` with `to` in the string `text`.' -info_replace_arguments = 'from,to,text' +info_replace_description = ( + 'Replace all occurrences of `pattern` with `replacement` in the string `source`. ' + 'Can be used to ignore certain strings when sorting by replacing them with an empty string. ' + 'See /help autosort for examples.' +) +info_replace_arguments = 'pattern,replacement,source' info_order_description = ( - 'Get a zero padded index of a value in a list of possible values.' - 'If the value is not found, the index for `*` is returned.' - 'If there is no `*` in the list, the highest index + 1 is returned.' + 'Generate a zero-padded number that corresponds to the index of `value` in the list of options. ' + 'If one of the options is the special value `*`, then any value not explicitly mentioned will be sorted at that position. ' + 'Otherwise, any value that does not match an option is assigned the highest number available. ' + 'Can be used to easily sort buffers based on a manual sequence. ' + 'See /help autosort for examples.' +) +info_order_arguments = 'value,first,second,third,...' + +info_escape_description = ( + 'Escape commas and backslashes in `text` by prepending them with a backslash. ' + 'This is mainly useful to pass arbitrary eval strings as arguments to other autosort info hooks. ' + 'Otherwise, an eval string that expands to something with a comma would be interpreted as multiple arguments.' + 'See /help autosort for examples.' ) -info_order_arguments = 'value,first,second,third,...' +info_escape_arguments = 'text' if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): @@ -1014,6 +1062,7 @@ if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, weechat.hook_config('autosort.*', 'on_config_changed', '') weechat.hook_completion('plugin_autosort', '', 'on_autosort_complete', '') weechat.hook_command('autosort', command_description.format(**colors), '', '', command_completion, 'on_autosort_command', '') + weechat.hook_info('autosort_escape', info_escape_description, info_escape_arguments, 'on_info_escape', '') weechat.hook_info('autosort_replace', info_replace_description, info_replace_arguments, 'on_info_replace', '') weechat.hook_info('autosort_order', info_order_description, info_order_arguments, 'on_info_order', '') diff --git a/weechat/python/grep.py b/weechat/python/grep.py index 1941531..64dbc52 100644 --- a/weechat/python/grep.py +++ b/weechat/python/grep.py @@ -69,6 +69,10 @@ # # History: # +# 2019-06-30, dabbill +# and Sébastien Helleu +# version 0.8.2: make script compatible with Python 3 +# # 2018-04-10, Sébastien Helleu # version 0.8.1: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long # integer instead of a string) @@ -117,9 +121,9 @@ # * supress highlights when printing in grep buffer # # 2010-10-06 -# version 0.6.7: by xt +# version 0.6.7: by xt # * better temporary file: -# use tempfile.mkstemp. to create a temp file in log dir, +# use tempfile.mkstemp. to create a temp file in log dir, # makes it safer with regards to write permission and multi user # # 2010-04-08 @@ -226,7 +230,7 @@ except ImportError: SCRIPT_NAME = "grep" SCRIPT_AUTHOR = "Elián Hanisch " -SCRIPT_VERSION = "0.8.1" +SCRIPT_VERSION = "0.8.2" SCRIPT_LICENSE = "GPL3" SCRIPT_DESC = "Search in buffers and logs" SCRIPT_COMMAND = "grep" @@ -259,14 +263,14 @@ class linesDict(dict): def get_matches_count(self): """Return the sum of total matches stored.""" if dict.__len__(self): - return sum(map(lambda L: L.matches_count, self.itervalues())) + return sum(map(lambda L: L.matches_count, self.values())) else: return 0 def __len__(self): """Return the sum of total lines stored.""" if dict.__len__(self): - return sum(map(len, self.itervalues())) + return sum(map(len, self.values())) else: return 0 @@ -274,7 +278,7 @@ class linesDict(dict): """Returns buffer count or buffer name if there's just one stored.""" n = len(self.keys()) if n == 1: - return self.keys()[0] + return list(self.keys())[0] elif n > 1: return '%s logs' %n else: @@ -282,18 +286,18 @@ class linesDict(dict): def items(self): """Returns a list of items sorted by line count.""" - items = dict.items(self) + items = list(dict.items(self)) items.sort(key=lambda i: len(i[1])) return items def items_count(self): """Returns a list of items sorted by match count.""" - items = dict.items(self) + items = list(dict.items(self)) items.sort(key=lambda i: i[1].matches_count) return items def strip_separator(self): - for L in self.itervalues(): + for L in self.values(): L.strip_separator() def get_last_lines(self, n): @@ -302,7 +306,7 @@ class linesDict(dict): if n >= total_lines: # nothing to do return - for k, v in reversed(self.items()): + for k, v in reversed(list(self.items())): l = len(v) if n > 0: if l > n: @@ -487,7 +491,7 @@ def dir_list(dir, filter_list=(), filter_excludes=True, include_dir=False): return cache_dir[key] except KeyError: pass - + filter_list = filter_list or get_config_log_filter() dir_len = len(dir) if filter_list: @@ -657,8 +661,8 @@ def make_regexp(pattern, matchcase=False): regexp = re.compile(pattern, re.IGNORECASE) else: regexp = re.compile(pattern) - except Exception, e: - raise Exception, 'Bad pattern, %s' %e + except Exception as e: + raise Exception('Bad pattern, %s' % e) return regexp def check_string(s, regexp, hilight='', exact=False): @@ -716,7 +720,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi return s else: check = lambda s: check_string(s, regexp, hilight, exact) - + try: file_object = open(file, 'r') except IOError: @@ -736,7 +740,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi before_context, after_context = after_context, before_context if before_context: - before_context_range = range(1, before_context + 1) + before_context_range = list(range(1, before_context + 1)) before_context_range.reverse() limit = tail or head @@ -800,7 +804,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi while id < after_context + offset: id += 1 try: - context_line = file_object.next() + context_line = next(file_object) _context_line = check(context_line) if _context_line: offset = id @@ -1002,7 +1006,7 @@ def grep_process(*args): global grep_options, log_pairs for log_name, log in log_pairs: result[log_name] = grep_file(log, *grep_options) - except Exception, e: + except Exception as e: result = e return pickle.dumps(result) @@ -1038,7 +1042,7 @@ def grep_process_cb(data, command, return_code, out, err): if isinstance(data, Exception): raise data matched_lines.update(data) - except Exception, e: + except Exception as e: set_buffer_error(repr(e)) return WEECHAT_RC_OK else: @@ -1180,7 +1184,7 @@ def buffer_update(): # free matched_lines so it can be removed from memory del matched_lines - + def split_line(s): """Splits log's line 's' in 3 parts, date, nick and msg.""" global weechat_format @@ -1280,12 +1284,12 @@ def buffer_input(data, buffer, input_data): weechat.infolist_free(infolist) try: cmd_grep_parsing(input_data) - except Exception, e: - error('Argument error, %s' %e, buffer=buffer) + except Exception as e: + error('Argument error, %s' % e, buffer=buffer) return WEECHAT_RC_OK try: show_matching_lines() - except Exception, e: + except Exception as e: error(e) except NameError: error("There isn't any previous search to repeat.", buffer=buffer) @@ -1342,11 +1346,11 @@ def cmd_grep_parsing(args): args = ' '.join(args) # join pattern for keep spaces if args: - pattern_tmpl = args + pattern_tmpl = args pattern = _tmplRe.sub(tmplReplacer, args) debug('Using regexp: %s', pattern) if not pattern: - raise Exception, 'No pattern for grep the logs.' + raise Exception('No pattern for grep the logs.') def positive_number(opt, val): try: @@ -1359,7 +1363,7 @@ def cmd_grep_parsing(args): opt = '-' + opt else: opt = '--' + opt - raise Exception, "argument for %s must be a positive integer." %opt + raise Exception("argument for %s must be a positive integer." % opt) for opt, val in opts: opt = opt.strip('-') @@ -1454,8 +1458,8 @@ def cmd_grep(data, buffer, args): # parse try: cmd_grep_parsing(args) - except Exception, e: - error('Argument error, %s' %e) + except Exception as e: + error('Argument error, %s' % e) return WEECHAT_RC_OK # find logs @@ -1501,7 +1505,7 @@ def cmd_grep(data, buffer, args): # grepping try: show_matching_lines() - except Exception, e: + except Exception as e: error(e) return WEECHAT_RC_OK @@ -1520,8 +1524,8 @@ def cmd_logs(data, buffer, args): opt = opt.strip('-') if opt in ('size', 's'): sort_by_size = True - except Exception, e: - error('Argument error, %s' %e) + except Exception as e: + error('Argument error, %s' % e) return WEECHAT_RC_OK # is there's a filter, filter_excludes should be False @@ -1703,7 +1707,7 @@ Examples: 'completion_grep_args', '') # settings - for opt, val in settings.iteritems(): + for opt, val in settings.items(): if not weechat.config_is_set_plugin(opt): weechat.config_set_plugin(opt, val) @@ -1716,7 +1720,7 @@ Examples: color_summary = weechat.color('lightcyan') color_delimiter = weechat.color('chat_delimiters') color_script_nick = weechat.color('chat_nick') - + # pretty [grep] script_nick = '%s[%s%s%s]%s' %(color_delimiter, color_script_nick, SCRIPT_NAME, color_delimiter, color_reset) -- 2.49.0 From a2bb3c026103a224833cc1eb9cc2fc85d83019c1 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Mon, 2 Sep 2019 12:40:32 +0100 Subject: [PATCH 11/16] weechat: update wee-slack --- weechat/plugins.conf | 6 +++++- weechat/python/wee-slack | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/weechat/plugins.conf b/weechat/plugins.conf index 0dc184f..3fc0832 100644 --- a/weechat/plugins.conf +++ b/weechat/plugins.conf @@ -93,6 +93,7 @@ python.slack.map_underline_to = "_" python.slack.migrated = "true" python.slack.muted_channels_activity = "personal_highlights" python.slack.never_away = "false" +python.slack.notify_usergroup_handle_updated = "false" python.slack.record_events = "false" python.slack.render_bold_as = "bold" python.slack.render_italic_as = "italic" @@ -111,6 +112,7 @@ python.slack.trigger_value = "0" python.slack.unfurl_auto_link_display = "both" python.slack.unfurl_ignore_alt_text = "0" python.slack.unhide_buffers_with_activity = "false" +python.slack.use_full_names = "false" python.slack_extension.colorize_messages = "0" python.slack_extension.colorize_nicks = "1" python.slack_extension.colorize_private_chats = "0" @@ -187,11 +189,12 @@ python.slack.debug_level = "Show only this level of debug info (or higher) when python.slack.debug_mode = "Open a dedicated buffer for debug messages and start logging to it. How verbose the logging is depends on log_level." python.slack.distracting_channels = "List of channels to hide." python.slack.external_user_suffix = "The suffix appended to nicks to indicate external users." -python.slack.files_download_location = "If set, file attachments will be automatically downloaded to this location." +python.slack.files_download_location = "If set, file attachments will be automatically downloaded to this location. "%h" will be replaced by WeeChat home, "~/.weechat" by default." python.slack.group_name_prefix = "The prefix of buffer names for groups (private channels)." python.slack.map_underline_to = "When sending underlined text to slack, use this formatting character for it. The default ("_") sends it as italics. Use "*" to send bold instead." python.slack.muted_channels_activity = "Control which activity you see from muted channels, either none, personal_highlights, all_highlights or all. none: Don't show any activity. personal_highlights: Only show personal highlights, i.e. not @channel and @here. all_highlights: Show all highlights, but not other messages. all: Show all activity, like other channels." python.slack.never_away = "Poke Slack every five minutes so that it never marks you "away"." +python.slack.notify_usergroup_handle_updated = "Control if you want to see notification when a usergroup's handle has changed, either true or false." python.slack.record_events = "Log all traffic from Slack to disk as JSON." python.slack.render_bold_as = "When receiving bold text from Slack, render it as this in weechat." python.slack.render_italic_as = "When receiving bold text from Slack, render it as this in weechat. If your terminal lacks italic support, consider using "underline" instead." @@ -209,6 +212,7 @@ python.slack.thread_suffix_color = "Color to use for the [thread: XXX] suffix on python.slack.unfurl_auto_link_display = "When displaying ("unfurling") links to channels/users/etc, determine what is displayed when the text matches the url without the protocol. This happens when Slack automatically creates links, e.g. from words separated by dots or email addresses. Set it to "text" to only display the text written by the user, "url" to only display the url or "both" (the default) to display both." python.slack.unfurl_ignore_alt_text = "When displaying ("unfurling") links to channels/users/etc, ignore the "alt text" present in the message and instead use the canonical name of the thing being linked to." python.slack.unhide_buffers_with_activity = "When activity occurs on a buffer, unhide it even if it was previously hidden (whether by the user or by the distracting_channels setting)." +python.slack.use_full_names = "Use full names as the nicks for all users. When this is false (the default), display names will be used if set, with a fallback to the full name if display name is not set." ruby.colorizer.buffer_regex = "Only colorize text in buffers with names that match this regex. Leaving this empty matches all buffer names." ruby.colorizer.rule.0 = "A colorizing rule of the form: / Empty rules are ignored." ruby.colorizer.rule.1 = "A colorizing rule of the form: / Empty rules are ignored." diff --git a/weechat/python/wee-slack b/weechat/python/wee-slack index 76ccd47..eb2d447 160000 --- a/weechat/python/wee-slack +++ b/weechat/python/wee-slack @@ -1 +1 @@ -Subproject commit 76ccd47a404b9f2ad8ba34750b473371b6cff5a6 +Subproject commit eb2d44760d4f2d4b12888bf98e6a73fc1486c919 -- 2.49.0 From c65045d86dee108bf8b556dee6b3fc5e570618c6 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Mon, 2 Sep 2019 12:58:11 +0100 Subject: [PATCH 12/16] vim: fix clang_format --- vim/vimrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vim/vimrc b/vim/vimrc index 6192c9f..78b44f4 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -31,6 +31,8 @@ Plug 'majutsushi/tagbar' Plug 'octol/vim-cpp-enhanced-highlight' Plug 'raimondi/delimitmate' Plug 'ram-z/vim-clang-format', { 'branch': 'fix-undo' } +" fix some issue with vim-clang-format not finding .clang-format +let g:clang_format#detect_style_file = 1 Plug 'vimwiki/vimwiki', { 'branch': 'dev' } Plug 'scrooloose/syntastic' Plug 'sgeb/vim-diff-fold' -- 2.49.0 From f11b95c457d4a1b7a3bd1625a12c1ee848a3ffe1 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Mon, 2 Sep 2019 12:59:34 +0100 Subject: [PATCH 13/16] zsh: add virtualenv prompt --- zsh/lib/prompt.zsh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zsh/lib/prompt.zsh b/zsh/lib/prompt.zsh index 683fab4..c8ca45b 100644 --- a/zsh/lib/prompt.zsh +++ b/zsh/lib/prompt.zsh @@ -6,7 +6,7 @@ hostcolor=green [[ $(hostname) == "tardis" ]] && hostcolor=red precmd() { - PROMPT='%T %n@%{$fg[$hostcolor]%}%m%(1j. $fg_bold[white]↵%{$fg_bold[red]%}%j.)%{$reset_color%}%-0>..>$(git_prompt_status)%>> + PROMPT='%T $(virtualenv_prompt)%n@%{$fg[$hostcolor]%}%m%(1j. $fg_bold[white]↵%{$fg_bold[red]%}%j.)%{$reset_color%}%-0>..>$(git_prompt_status)%>> %(?..%{$fg_bold[white]%}%?)%{$reset_color%}$(vi_prompt_info)%{%(!.$fg[red]❰.$fg[green]❱)%1G%} ' RPROMPT='%{$fg[green]%}%~%{$reset_color%}' } @@ -108,6 +108,14 @@ git_prompt_status() { echo $git_status } +function virtualenv_prompt() { + if [[ -z $VIRTUAL_ENV ]] then + echo "" + else + echo "(${VIRTUAL_ENV##*/}) " + fi +} + function print_if_fits() { local zero length -- 2.49.0 From e834edeb49fea47fb1ec214ac91af8c393c95726 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Tue, 1 Oct 2019 12:38:45 +0100 Subject: [PATCH 14/16] xkb: Add slash to --- xkb/symbols/dvorak | 1 + 1 file changed, 1 insertion(+) diff --git a/xkb/symbols/dvorak b/xkb/symbols/dvorak index 716e9f1..608c6f1 100644 --- a/xkb/symbols/dvorak +++ b/xkb/symbols/dvorak @@ -141,6 +141,7 @@ xkb_symbols "kinesis" { //{{{1 key { [ equal, plus ] }; key { [ bracketleft, braceleft ] }; key { [ bracketright, braceright, dead_tilde, NoSymbol ] }; + key { [ slash, question, U2E2E, U2E2E ] }; }; //}}}1 -- 2.49.0 From b2532fa3cad2f790b1e72df330c15723047c79a3 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Thu, 10 Oct 2019 10:47:07 +0000 Subject: [PATCH 15/16] weechat: update config and plugins --- weechat/plugins.conf | 28 ++ weechat/python/go.py | 563 ++++++++++++++++++++++++++++++++++++ weechat/python/text_item.py | 18 +- weechat/weechat.conf | 1 + 4 files changed, 605 insertions(+), 5 deletions(-) create mode 100644 weechat/python/go.py diff --git a/weechat/plugins.conf b/weechat/plugins.conf index 3fc0832..86e2f48 100644 --- a/weechat/plugins.conf +++ b/weechat/plugins.conf @@ -54,6 +54,19 @@ perl.highmon.nick_suffix = ">" perl.highmon.output = "buffer" perl.highmon.short_names = "on" python.check_license = "off" +python.go.auto_jump = "off" +python.go.buffer_number = "on" +python.go.color_name = "black,cyan" +python.go.color_name_highlight = "red,cyan" +python.go.color_name_highlight_selected = "red,brown" +python.go.color_name_selected = "black,brown" +python.go.color_number = "yellow,magenta" +python.go.color_number_selected = "yellow,red" +python.go.fuzzy_search = "off" +python.go.message = "Go to: " +python.go.short_name = "off" +python.go.sort = "number,beginning" +python.go.use_core_instead_weechat = "off" python.grep.clear_buffer = "off" python.grep.default_tail_head = "10" python.grep.go_to_buffer = "on" @@ -126,6 +139,7 @@ python.slack_extension.slack_timeout = "20000" python.slack_extension.switch_buffer_on_join = "1" python.slack_extension.trigger_value = "0" python.slack_extension.unfurl_ignore_alt_text = "0" +python.text_item.interval = "0" python.text_item.nick = "channel|window_switch ${color:lightcyan}${nick}" ruby.check_license = "off" ruby.colorizer.buffer_regex = "" @@ -166,6 +180,19 @@ perl.beep.bell_always = "use $bell on private messages and/or highlights regardl perl.beep.blacklist_nicks = "comma-separated list of "server.nick": if not empty, these nicks will not be able to trigger execution of commands. Cannot be used in conjuction with whitelist (example: "freenode.nick1,freenode.nick2") (default: "")" perl.beep.whitelist_channels = "comma-separated list of "server.#channel": if not empty, only these channels will trigger execution of commands (example: "freenode.#weechat,freenode.#channel2") (default: "")" perl.beep.whitelist_nicks = "comma-separated list of "server.nick": if not empty, only these nicks will trigger execution of commands (example: "freenode.nick1,freenode.nick2") (default: "")" +python.go.auto_jump = "automatically jump to buffer when it is uniquely selected (default: "off")" +python.go.buffer_number = "display buffer number (default: "on")" +python.go.color_name = "color for buffer name (not selected) (default: "black,cyan")" +python.go.color_name_highlight = "color for highlight in buffer name (not selected) (default: "red,cyan")" +python.go.color_name_highlight_selected = "color for highlight in a selected buffer name (default: "red,brown")" +python.go.color_name_selected = "color for a selected buffer name (default: "black,brown")" +python.go.color_number = "color for buffer number (not selected) (default: "yellow,magenta")" +python.go.color_number_selected = "color for selected buffer number (default: "yellow,red")" +python.go.fuzzy_search = "search buffer matches using approximation (default: "off")" +python.go.message = "message to display before list of buffers (default: "Go to: ")" +python.go.short_name = "display and search in short names instead of buffer name (default: "off")" +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")" +python.go.use_core_instead_weechat = "use name "core" instead of "weechat" for core buffer (default: "off")" python.screen_away.away_suffix = "What to append to your nick when you're away." python.screen_away.command_on_attach = "Commands to execute on attach, separated by semicolon" python.screen_away.command_on_detach = "Commands to execute on detach, separated by semicolon" @@ -213,6 +240,7 @@ python.slack.unfurl_auto_link_display = "When displaying ("unfurling") links to python.slack.unfurl_ignore_alt_text = "When displaying ("unfurling") links to channels/users/etc, ignore the "alt text" present in the message and instead use the canonical name of the thing being linked to." python.slack.unhide_buffers_with_activity = "When activity occurs on a buffer, unhide it even if it was previously hidden (whether by the user or by the distracting_channels setting)." python.slack.use_full_names = "Use full names as the nicks for all users. When this is false (the default), display names will be used if set, with a fallback to the full name if display name is not set." +python.text_item.interval = "How often (in seconds) to force an update of all items. 0 means deactivated" ruby.colorizer.buffer_regex = "Only colorize text in buffers with names that match this regex. Leaving this empty matches all buffer names." ruby.colorizer.rule.0 = "A colorizing rule of the form: / Empty rules are ignored." ruby.colorizer.rule.1 = "A colorizing rule of the form: / Empty rules are ignored." diff --git a/weechat/python/go.py b/weechat/python/go.py new file mode 100644 index 0000000..2ab47ed --- /dev/null +++ b/weechat/python/go.py @@ -0,0 +1,563 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2009-2014 Sébastien Helleu +# Copyright (C) 2010 m4v +# Copyright (C) 2011 stfn +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# +# History: +# +# 2019-07-11, Simmo Saan +# version 2.6: fix detection of "/input search_text_here" +# 2017-04-01, Sébastien Helleu : +# version 2.5: add option "buffer_number" +# 2017-03-02, Sébastien Helleu : +# version 2.4: fix syntax and indentation error +# 2017-02-25, Simmo Saan +# version 2.3: fix fuzzy search breaking buffer number search display +# 2016-01-28, ylambda +# version 2.2: add option "fuzzy_search" +# 2015-11-12, nils_2 +# version 2.1: fix problem with buffer short_name "weechat", using option +# "use_core_instead_weechat", see: +# https://github.com/weechat/weechat/issues/574 +# 2014-05-12, Sébastien Helleu : +# version 2.0: add help on options, replace option "sort_by_activity" by +# "sort" (add sort by name and first match at beginning of +# name and by number), PEP8 compliance +# 2012-11-26, Nei +# version 1.9: add auto_jump option to automatically go to buffer when it +# is uniquely selected +# 2012-09-17, Sébastien Helleu : +# version 1.8: fix jump to non-active merged buffers (jump with buffer name +# instead of number) +# 2012-01-03 nils_2 +# version 1.7: add option "use_core_instead_weechat" +# 2012-01-03, Sébastien Helleu : +# version 1.6: make script compatible with Python 3.x +# 2011-08-24, stfn : +# version 1.5: /go with name argument jumps directly to buffer +# Remember cursor position in buffer input +# 2011-05-31, Elián Hanisch : +# version 1.4: Sort list of buffers by activity. +# 2011-04-25, Sébastien Helleu : +# version 1.3: add info "go_running" (used by script input_lock.rb) +# 2010-11-01, Sébastien Helleu : +# version 1.2: use high priority for hooks to prevent conflict with other +# plugins/scripts (WeeChat >= 0.3.4 only) +# 2010-03-25, Elián Hanisch : +# version 1.1: use a space to match the end of a string +# 2009-11-16, Sébastien Helleu : +# version 1.0: add new option to display short names +# 2009-06-15, Sébastien Helleu : +# version 0.9: fix typo in /help go with command /key +# 2009-05-16, Sébastien Helleu : +# version 0.8: search buffer by number, fix bug when window is split +# 2009-05-03, Sébastien Helleu : +# version 0.7: eat tab key (do not complete input, just move buffer +# pointer) +# 2009-05-02, Sébastien Helleu : +# version 0.6: sync with last API changes +# 2009-03-22, Sébastien Helleu : +# version 0.5: update modifier signal name for input text display, +# fix arguments for function string_remove_color +# 2009-02-18, Sébastien Helleu : +# version 0.4: do not hook command and init options if register failed +# 2009-02-08, Sébastien Helleu : +# version 0.3: case insensitive search for buffers names +# 2009-02-08, Sébastien Helleu : +# version 0.2: add help about Tab key +# 2009-02-08, Sébastien Helleu : +# version 0.1: initial release +# + +""" +Quick jump to buffers. +(this script requires WeeChat 0.3.0 or newer) +""" + +from __future__ import print_function + +SCRIPT_NAME = 'go' +SCRIPT_AUTHOR = 'Sébastien Helleu ' +SCRIPT_VERSION = '2.6' +SCRIPT_LICENSE = 'GPL3' +SCRIPT_DESC = 'Quick jump to buffers' + +SCRIPT_COMMAND = 'go' + +IMPORT_OK = True + +try: + import weechat +except ImportError: + print('This script must be run under WeeChat.') + print('Get WeeChat now at: http://www.weechat.org/') + IMPORT_OK = False + +import re + +# script options +SETTINGS = { + 'color_number': ( + 'yellow,magenta', + 'color for buffer number (not selected)'), + 'color_number_selected': ( + 'yellow,red', + 'color for selected buffer number'), + 'color_name': ( + 'black,cyan', + 'color for buffer name (not selected)'), + 'color_name_selected': ( + 'black,brown', + 'color for a selected buffer name'), + 'color_name_highlight': ( + 'red,cyan', + 'color for highlight in buffer name (not selected)'), + 'color_name_highlight_selected': ( + 'red,brown', + 'color for highlight in a selected buffer name'), + 'message': ( + 'Go to: ', + 'message to display before list of buffers'), + 'short_name': ( + 'off', + 'display and search in short names instead of buffer name'), + 'sort': ( + 'number,beginning', + '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), ', + 'hotlist = sort by hotlist order, ' + 'number = first match a buffer number before digits in name, ' + 'beginning = first match at beginning of names (or short names); ' + 'the default sort of buffers is by numbers'), + 'use_core_instead_weechat': ( + 'off', + 'use name "core" instead of "weechat" for core buffer'), + 'auto_jump': ( + 'off', + 'automatically jump to buffer when it is uniquely selected'), + 'fuzzy_search': ( + 'off', + 'search buffer matches using approximation'), + 'buffer_number': ( + 'on', + 'display buffer number'), +} + +# hooks management +HOOK_COMMAND_RUN = { + 'input': ('/input *', 'go_command_run_input'), + 'buffer': ('/buffer *', 'go_command_run_buffer'), + 'window': ('/window *', 'go_command_run_window'), +} +hooks = {} + +# input before command /go (we'll restore it later) +saved_input = '' +saved_input_pos = 0 + +# last user input (if changed, we'll update list of matching buffers) +old_input = None + +# matching buffers +buffers = [] +buffers_pos = 0 + + +def go_option_enabled(option): + """Checks if a boolean script option is enabled or not.""" + return weechat.config_string_to_boolean(weechat.config_get_plugin(option)) + + +def go_info_running(data, info_name, arguments): + """Returns "1" if go is running, otherwise "0".""" + return '1' if 'modifier' in hooks else '0' + + +def go_unhook_one(hook): + """Unhook something hooked by this script.""" + global hooks + if hook in hooks: + weechat.unhook(hooks[hook]) + del hooks[hook] + + +def go_unhook_all(): + """Unhook all.""" + go_unhook_one('modifier') + for hook in HOOK_COMMAND_RUN: + go_unhook_one(hook) + + +def go_hook_all(): + """Hook command_run and modifier.""" + global hooks + priority = '' + version = weechat.info_get('version_number', '') or 0 + # use high priority for hook to prevent conflict with other plugins/scripts + # (WeeChat >= 0.3.4 only) + if int(version) >= 0x00030400: + priority = '2000|' + for hook, value in HOOK_COMMAND_RUN.items(): + if hook not in hooks: + hooks[hook] = weechat.hook_command_run( + '%s%s' % (priority, value[0]), + value[1], '') + if 'modifier' not in hooks: + hooks['modifier'] = weechat.hook_modifier( + 'input_text_display_with_cursor', 'go_input_modifier', '') + + +def go_start(buf): + """Start go on buffer.""" + global saved_input, saved_input_pos, old_input, buffers_pos + go_hook_all() + saved_input = weechat.buffer_get_string(buf, 'input') + saved_input_pos = weechat.buffer_get_integer(buf, 'input_pos') + weechat.buffer_set(buf, 'input', '') + old_input = None + buffers_pos = 0 + + +def go_end(buf): + """End go on buffer.""" + global saved_input, saved_input_pos, old_input + go_unhook_all() + weechat.buffer_set(buf, 'input', saved_input) + weechat.buffer_set(buf, 'input_pos', str(saved_input_pos)) + old_input = None + + +def go_match_beginning(buf, string): + """Check if a string matches the beginning of buffer name/short name.""" + if not string: + return False + esc_str = re.escape(string) + if re.search(r'^#?' + esc_str, buf['name']) \ + or re.search(r'^#?' + esc_str, buf['short_name']): + return True + return False + + +def go_match_fuzzy(name, string): + """Check if string matches name using approximation.""" + if not string: + return False + + name_len = len(name) + string_len = len(string) + + if string_len > name_len: + return False + if name_len == string_len: + return name == string + + # Attempt to match all chars somewhere in name + prev_index = -1 + for i, char in enumerate(string): + index = name.find(char, prev_index+1) + if index == -1: + return False + prev_index = index + return True + + +def go_now(buf, args): + """Go to buffer specified by args.""" + listbuf = go_matching_buffers(args) + if not listbuf: + return + + # prefer buffer that matches at beginning (if option is enabled) + if 'beginning' in weechat.config_get_plugin('sort').split(','): + for index in range(len(listbuf)): + if go_match_beginning(listbuf[index], args): + weechat.command(buf, + '/buffer ' + str(listbuf[index]['full_name'])) + return + + # jump to first buffer in matching buffers by default + weechat.command(buf, '/buffer ' + str(listbuf[0]['full_name'])) + + +def go_cmd(data, buf, args): + """Command "/go": just hook what we need.""" + global hooks + if args: + go_now(buf, args) + elif 'modifier' in hooks: + go_end(buf) + else: + go_start(buf) + return weechat.WEECHAT_RC_OK + + +def go_matching_buffers(strinput): + """Return a list with buffers matching user input.""" + global buffers_pos + listbuf = [] + if len(strinput) == 0: + buffers_pos = 0 + strinput = strinput.lower() + infolist = weechat.infolist_get('buffer', '', '') + while weechat.infolist_next(infolist): + short_name = weechat.infolist_string(infolist, 'short_name') + if go_option_enabled('short_name'): + name = weechat.infolist_string(infolist, 'short_name') + else: + name = weechat.infolist_string(infolist, 'name') + if name == 'weechat' \ + and go_option_enabled('use_core_instead_weechat') \ + and weechat.infolist_string(infolist, 'plugin_name') == 'core': + name = 'core' + number = weechat.infolist_integer(infolist, 'number') + full_name = weechat.infolist_string(infolist, 'full_name') + if not full_name: + full_name = '%s.%s' % ( + weechat.infolist_string(infolist, 'plugin_name'), + weechat.infolist_string(infolist, 'name')) + pointer = weechat.infolist_pointer(infolist, 'pointer') + matching = name.lower().find(strinput) >= 0 + if not matching and strinput[-1] == ' ': + matching = name.lower().endswith(strinput.strip()) + if not matching and go_option_enabled('fuzzy_search'): + matching = go_match_fuzzy(name.lower(), strinput) + if not matching and strinput.isdigit(): + matching = str(number).startswith(strinput) + if len(strinput) == 0 or matching: + listbuf.append({ + 'number': number, + 'short_name': short_name, + 'name': name, + 'full_name': full_name, + 'pointer': pointer, + }) + weechat.infolist_free(infolist) + + # sort buffers + hotlist = [] + infolist = weechat.infolist_get('hotlist', '', '') + while weechat.infolist_next(infolist): + hotlist.append( + weechat.infolist_pointer(infolist, 'buffer_pointer')) + weechat.infolist_free(infolist) + last_index_hotlist = len(hotlist) + + def _sort_name(buf): + """Sort buffers by name (or short name).""" + return buf['name'] + + def _sort_hotlist(buf): + """Sort buffers by hotlist order.""" + try: + return hotlist.index(buf['pointer']) + except ValueError: + # not in hotlist, always last. + return last_index_hotlist + + def _sort_match_number(buf): + """Sort buffers by match on number.""" + return 0 if str(buf['number']) == strinput else 1 + + def _sort_match_beginning(buf): + """Sort buffers by match at beginning.""" + return 0 if go_match_beginning(buf, strinput) else 1 + + funcs = { + 'name': _sort_name, + 'hotlist': _sort_hotlist, + 'number': _sort_match_number, + 'beginning': _sort_match_beginning, + } + + for key in weechat.config_get_plugin('sort').split(','): + if key in funcs: + listbuf = sorted(listbuf, key=funcs[key]) + + if not strinput: + index = [i for i, buf in enumerate(listbuf) + if buf['pointer'] == weechat.current_buffer()] + if index: + buffers_pos = index[0] + + return listbuf + + +def go_buffers_to_string(listbuf, pos, strinput): + """Return string built with list of buffers found (matching user input).""" + string = '' + strinput = strinput.lower() + for i in range(len(listbuf)): + selected = '_selected' if i == pos else '' + buffer_name = listbuf[i]['name'] + index = buffer_name.lower().find(strinput) + if index >= 0: + index2 = index + len(strinput) + name = '%s%s%s%s%s' % ( + buffer_name[:index], + weechat.color(weechat.config_get_plugin( + 'color_name_highlight' + selected)), + buffer_name[index:index2], + weechat.color(weechat.config_get_plugin( + 'color_name' + selected)), + buffer_name[index2:]) + elif go_option_enabled("fuzzy_search") and \ + go_match_fuzzy(buffer_name.lower(), strinput): + name = "" + prev_index = -1 + for char in strinput.lower(): + index = buffer_name.lower().find(char, prev_index+1) + if prev_index < 0: + name += buffer_name[:index] + name += weechat.color(weechat.config_get_plugin( + 'color_name_highlight' + selected)) + if prev_index >= 0 and index > prev_index+1: + name += weechat.color(weechat.config_get_plugin( + 'color_name' + selected)) + name += buffer_name[prev_index+1:index] + name += weechat.color(weechat.config_get_plugin( + 'color_name_highlight' + selected)) + name += buffer_name[index] + prev_index = index + + name += weechat.color(weechat.config_get_plugin( + 'color_name' + selected)) + name += buffer_name[prev_index+1:] + else: + name = buffer_name + string += ' ' + if go_option_enabled('buffer_number'): + string += '%s%s' % ( + weechat.color(weechat.config_get_plugin( + 'color_number' + selected)), + str(listbuf[i]['number'])) + string += '%s%s%s' % ( + weechat.color(weechat.config_get_plugin( + 'color_name' + selected)), + name, + weechat.color('reset')) + return ' ' + string if string else '' + + +def go_input_modifier(data, modifier, modifier_data, string): + """This modifier is called when input text item is built by WeeChat. + + This is commonly called after changes in input or cursor move: it builds + a new input with prefix ("Go to:"), and suffix (list of buffers found). + """ + global old_input, buffers, buffers_pos + if modifier_data != weechat.current_buffer(): + return '' + names = '' + new_input = weechat.string_remove_color(string, '') + new_input = new_input.lstrip() + if old_input is None or new_input != old_input: + old_buffers = buffers + buffers = go_matching_buffers(new_input) + if buffers != old_buffers and len(new_input) > 0: + if len(buffers) == 1 and go_option_enabled('auto_jump'): + weechat.command(modifier_data, '/wait 1ms /input return') + buffers_pos = 0 + old_input = new_input + names = go_buffers_to_string(buffers, buffers_pos, new_input.strip()) + return weechat.config_get_plugin('message') + string + names + + +def go_command_run_input(data, buf, command): + """Function called when a command "/input xxx" is run.""" + global buffers, buffers_pos + if command.startswith('/input search_text') or command.startswith('/input jump'): + # search text or jump to another buffer is forbidden now + return weechat.WEECHAT_RC_OK_EAT + elif command == '/input complete_next': + # choose next buffer in list + buffers_pos += 1 + if buffers_pos >= len(buffers): + buffers_pos = 0 + weechat.hook_signal_send('input_text_changed', + weechat.WEECHAT_HOOK_SIGNAL_STRING, '') + return weechat.WEECHAT_RC_OK_EAT + elif command == '/input complete_previous': + # choose previous buffer in list + buffers_pos -= 1 + if buffers_pos < 0: + buffers_pos = len(buffers) - 1 + weechat.hook_signal_send('input_text_changed', + weechat.WEECHAT_HOOK_SIGNAL_STRING, '') + return weechat.WEECHAT_RC_OK_EAT + elif command == '/input return': + # switch to selected buffer (if any) + go_end(buf) + if len(buffers) > 0: + weechat.command( + buf, '/buffer ' + str(buffers[buffers_pos]['full_name'])) + return weechat.WEECHAT_RC_OK_EAT + return weechat.WEECHAT_RC_OK + + +def go_command_run_buffer(data, buf, command): + """Function called when a command "/buffer xxx" is run.""" + return weechat.WEECHAT_RC_OK_EAT + + +def go_command_run_window(data, buf, command): + """Function called when a command "/window xxx" is run.""" + return weechat.WEECHAT_RC_OK_EAT + + +def go_unload_script(): + """Function called when script is unloaded.""" + go_unhook_all() + return weechat.WEECHAT_RC_OK + + +def go_main(): + """Entry point.""" + if not weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, + SCRIPT_LICENSE, SCRIPT_DESC, + 'go_unload_script', ''): + return + weechat.hook_command( + SCRIPT_COMMAND, + 'Quick jump to buffers', '[name]', + 'name: directly jump to buffer by name (without argument, list is ' + 'displayed)\n\n' + 'You can bind command to a key, for example:\n' + ' /key bind meta-g /go\n\n' + 'You can use completion key (commonly Tab and shift-Tab) to select ' + 'next/previous buffer in list.', + '%(buffers_names)', + 'go_cmd', '') + + # set default settings + version = weechat.info_get('version_number', '') or 0 + for option, value in SETTINGS.items(): + if not weechat.config_is_set_plugin(option): + weechat.config_set_plugin(option, value[0]) + if int(version) >= 0x00030500: + weechat.config_set_desc_plugin( + option, '%s (default: "%s")' % (value[1], value[0])) + weechat.hook_info('go_running', + 'Return "1" if go is running, otherwise "0"', + '', + 'go_info_running', '') + + +if __name__ == "__main__" and IMPORT_OK: + go_main() diff --git a/weechat/python/text_item.py b/weechat/python/text_item.py index 08c1536..975878a 100644 --- a/weechat/python/text_item.py +++ b/weechat/python/text_item.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2012-2018 by nils_2 +# Copyright (c) 2012-2019 by nils_2 # # add a plain text or evaluated content to item bar # @@ -17,6 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # +# 2019-05-23: FlashCode, (freenode.#weechat) +# 0.9 : fix eval_expression() for split windows +# # 2018-08-18: nils_2, (freenode.#weechat) # 0.8 : add new option "interval" # @@ -49,6 +52,13 @@ # Development is currently hosted at # https://github.com/weechatter/weechat-scripts +# TODO +# plugins.var.python.text_item..enabled +# plugins.var.python.text_item..type +# plugins.var.python.text_item..signal +# plugins.var.python.text_item..text +# plugins.var.python.text_item..interval + try: import weechat,re @@ -59,7 +69,7 @@ except Exception: SCRIPT_NAME = "text_item" SCRIPT_AUTHOR = "nils_2 " -SCRIPT_VERSION = "0.8" +SCRIPT_VERSION = "0.9" SCRIPT_LICENSE = "GPL" SCRIPT_DESC = "add a plain text or evaluated content to item bar" @@ -72,7 +82,6 @@ TIMER = None settings = { 'interval': ('0', 'How often (in seconds) to force an update of all items. 0 means deactivated'), } - # ================================[ hooks ]=============================== def add_hook(signal, item): global hooks @@ -183,8 +192,7 @@ def bar_item_update_cb(signal, callback, callback_data): def substitute_colors(text,window): if int(version) >= 0x00040200: bufpointer = weechat.window_get_pointer(window,"buffer") - return weechat.string_eval_expression(text, {"buffer": bufpointer}, {}, {}) -# return weechat.string_eval_expression(text,{},{},{}) + return weechat.string_eval_expression(text, {"window": window, "buffer": bufpointer}, {}, {}) # substitute colors in output return re.sub(regex_color, lambda match: weechat.color(match.group(1)), text) diff --git a/weechat/weechat.conf b/weechat/weechat.conf index 1a7be38..67cabdb 100644 --- a/weechat/weechat.conf +++ b/weechat/weechat.conf @@ -406,6 +406,7 @@ four_rooms.current = on irc.freenode.#chakra = message irc.freenode.#chakra-devel = message irc.freenode.#livlug = message +perl.highmon = none [filter] irc_smart = on;*;irc_smart_filter;* -- 2.49.0 From 1dd589ac06e5899c1071e562c6827771f84ec132 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Thu, 10 Oct 2019 10:47:34 +0000 Subject: [PATCH 16/16] weechat: attach to local tmux session if available --- bin/weechat | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/weechat b/bin/weechat index 9971965..f13ff1e 100755 --- a/bin/weechat +++ b/bin/weechat @@ -3,4 +3,8 @@ jobs -Z weechat host=rmz.io -autossh -M0 -t $host "LANG=en_GB.UTF-8 tmux -L weechat attach" +if tmux -L weechat has-session -t weechat; then + tmux -L weechat attach +else + autossh -M0 -t $host "tmux -L weechat attach" +fi -- 2.49.0