From: Samir Benmendil Date: Fri, 6 Feb 2015 19:03:24 +0000 (+0000) Subject: weechat: install screen_away X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/27ff225a10eda0f6fedaba76f41ce5a6093c94fa?hp=1ea0168eaadac60df993d654d5e76e39aab45430 weechat: install screen_away --- diff --git a/weechat/alias.conf b/weechat/alias.conf index 51a5bb0..c5a5b1f 100644 --- a/weechat/alias.conf +++ b/weechat/alias.conf @@ -1,5 +1,5 @@ # -# alias.conf -- weechat v1.1 +# alias.conf -- weechat v1.1.1 # [cmd] diff --git a/weechat/aspell.conf b/weechat/aspell.conf index 4fbeb6e..0f35241 100644 --- a/weechat/aspell.conf +++ b/weechat/aspell.conf @@ -1,5 +1,5 @@ # -# aspell.conf -- weechat v1.1 +# aspell.conf -- weechat v1.1.1 # [color] diff --git a/weechat/buffer_autoset.conf b/weechat/buffer_autoset.conf index 301fe65..92ccf11 100644 --- a/weechat/buffer_autoset.conf +++ b/weechat/buffer_autoset.conf @@ -1,5 +1,5 @@ # -# buffer_autoset.conf -- weechat v1.1 +# buffer_autoset.conf -- weechat v1.1.1 # [buffer] diff --git a/weechat/buffers.conf b/weechat/buffers.conf index d04517f..4d25469 100644 --- a/weechat/buffers.conf +++ b/weechat/buffers.conf @@ -1,5 +1,5 @@ # -# buffers.conf -- weechat v1.1 +# buffers.conf -- weechat v1.1.1 # [color] diff --git a/weechat/charset.conf b/weechat/charset.conf index ccb87aa..c319dd3 100644 --- a/weechat/charset.conf +++ b/weechat/charset.conf @@ -1,5 +1,5 @@ # -# charset.conf -- weechat v1.1 +# charset.conf -- weechat v1.1.1 # [default] diff --git a/weechat/exec.conf b/weechat/exec.conf index 895c99e..f7f6212 100644 --- a/weechat/exec.conf +++ b/weechat/exec.conf @@ -1,5 +1,5 @@ # -# exec.conf -- weechat v1.1 +# exec.conf -- weechat v1.1.1 # [command] diff --git a/weechat/iset.conf b/weechat/iset.conf index 8d6e318..32f3c61 100644 --- a/weechat/iset.conf +++ b/weechat/iset.conf @@ -1,5 +1,5 @@ # -# iset.conf -- weechat v1.1 +# iset.conf -- weechat v1.1.1 # [color] diff --git a/weechat/logger.conf b/weechat/logger.conf index c98c4a0..82a5cfd 100644 --- a/weechat/logger.conf +++ b/weechat/logger.conf @@ -1,5 +1,5 @@ # -# logger.conf -- weechat v1.1 +# logger.conf -- weechat v1.1.1 # [look] diff --git a/weechat/plugins.conf b/weechat/plugins.conf index 4d23b88..42ba279 100644 --- a/weechat/plugins.conf +++ b/weechat/plugins.conf @@ -1,5 +1,5 @@ # -# plugins.conf -- weechat v1.1 +# plugins.conf -- weechat v1.1.1 # [var] @@ -45,6 +45,15 @@ python.grep.log_filter = "" python.grep.max_lines = "4000" python.grep.show_summary = "on" python.grep.size_limit = "2048" +python.screen_away.away_suffix = "" +python.screen_away.command_on_attach = "" +python.screen_away.command_on_detach = "" +python.screen_away.ignore = "" +python.screen_away.ignore_relays = "off" +python.screen_away.interval = "5" +python.screen_away.message = "Detached from tmux" +python.screen_away.set_away = "on" +python.screen_away.time_format = "since %Y-%m-%d %H:%M:%S%z" ruby.check_license = "off" tcl.check_license = "off" @@ -66,3 +75,12 @@ 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.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" +python.screen_away.ignore = "Comma-separated list of servers to ignore." +python.screen_away.ignore_relays = "Only check screen status and ignore relay interfaces" +python.screen_away.interval = "How often in seconds to check screen status" +python.screen_away.message = "Away message" +python.screen_away.set_away = "Set user as away." +python.screen_away.time_format = "time format append to away message" diff --git a/weechat/python/autoload/screen_away.py b/weechat/python/autoload/screen_away.py new file mode 120000 index 0000000..e485b70 --- /dev/null +++ b/weechat/python/autoload/screen_away.py @@ -0,0 +1 @@ +../screen_away.py \ No newline at end of file diff --git a/weechat/python/grep.py b/weechat/python/grep.py index 6d08ecd..fd9ca2b 100644 --- a/weechat/python/grep.py +++ b/weechat/python/grep.py @@ -65,6 +65,9 @@ # # # History: +# 2015-01-14, nils_2 +# version 0.7.4: make q work to quit grep buffer (requested by: gb) +# # 2014-03-29, Felix Eckhofer # version 0.7.3: fix typo # @@ -191,7 +194,7 @@ except ImportError: SCRIPT_NAME = "grep" SCRIPT_AUTHOR = "Elián Hanisch " -SCRIPT_VERSION = "0.7.3" +SCRIPT_VERSION = "0.7.4" SCRIPT_LICENSE = "GPL3" SCRIPT_DESC = "Search in buffers and logs" SCRIPT_COMMAND = "grep" @@ -1144,7 +1147,7 @@ def buffer_update(): note = ' (last %s lines shown)' %len(matched_lines) else: note = '' - title = "Search in %s%s%s %s matches%s | pattern \"%s%s%s\"%s %s | %.4f seconds (%.2f%%)" \ + title = "'q': close buffer | Search in %s%s%s %s matches%s | pattern \"%s%s%s\"%s %s | %.4f seconds (%.2f%%)" \ %(color_title, matched_lines, color_reset, matched_lines.get_matches_count(), note, color_title, pattern_tmpl, color_reset, invert and ' (inverted)' or '', format_options(), time_total, time_grep_pct) @@ -1239,6 +1242,9 @@ def buffer_input(data, buffer, input_data): cmd_grep_stop(buffer, input_data) except: return WEECHAT_RC_OK + if input_data in ('q', 'Q'): + weechat.buffer_close(buffer) + return weechat.WEECHAT_RC_OK global search_in_buffers, search_in_files global pattern diff --git a/weechat/python/screen_away.py b/weechat/python/screen_away.py new file mode 100644 index 0000000..8f68505 --- /dev/null +++ b/weechat/python/screen_away.py @@ -0,0 +1,197 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2009 by xt +# Copyright (c) 2009 by penryu +# Copyright (c) 2010 by Blake Winton +# Copyright (c) 2010 by Aron Griffis +# Copyright (c) 2010 by Jani Kesänen +# +# 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 . +# + +# +# (this script requires WeeChat 0.3.0 or newer) +# +# History: +# 2014-08-02, Nils Görs +# version 0.14: add time to detach message. (idea by Mikaela) +# 2014-06-19, Anders Bergh +# version 0.13: Fix a simple typo in an option description. +# 2014-01-12, Phyks (Lucas Verney) +# version 0.12: Added an option to check status of relays to set unaway in +# case of a connected relay. +# 2013-08-30, Anders Einar Hilden +# version: 0.11: Fix reading of set_away +# 2013-06-16, Renato Botelho +# version 0.10: add option to don't set away, only change nick +# allow multiple commands on attach/dettach +# do not add suffix if nick already have it +# 2012-12-29, David Flatz +# version 0.9: add option to ignore servers and don't set away status for them +# add descriptions to config options +# 2010-08-07, Filip H.F. "FiXato" Slagter +# version 0.8: add command on attach feature +# 2010-05-07, Jani Kesänen +# version 0.7: add command on detach feature +# 2010-03-07, Aron Griffis +# version 0.6: move socket check to register, +# add hook_config for interval, +# reduce default interval from 60 to 5 +# 2010-02-19, Blake Winton +# version 0.5: add option to change nick when away +# 2010-01-18, xt +# version 0.4: only update servers that are connected +# 2009-11-30, xt +# version 0.3: do not touch servers that are manually set away +# 2009-11-27, xt +# version 0.2: code for TMUX from penryu +# 2009-11-27, xt +# version 0.1: initial release + +import weechat as w +import re +import os +import datetime, time + +SCRIPT_NAME = "screen_away" +SCRIPT_AUTHOR = "xt " +SCRIPT_VERSION = "0.14" +SCRIPT_LICENSE = "GPL3" +SCRIPT_DESC = "Set away status on screen detach" + +settings = { + 'message': ('Detached from screen', 'Away message'), + 'time_format': ('since %Y-%m-%d %H:%M:%S%z', 'time format append to away message'), + 'interval': ('5', 'How often in seconds to check screen status'), + 'away_suffix': ('', 'What to append to your nick when you\'re away.'), + 'command_on_attach': ('', 'Commands to execute on attach, separated by semicolon'), + 'command_on_detach': ('', 'Commands to execute on detach, separated by semicolon'), + 'ignore': ('', 'Comma-separated list of servers to ignore.'), + 'set_away': ('on', 'Set user as away.'), + 'ignore_relays': ('off', 'Only check screen status and ignore relay interfaces'), +} + +TIMER = None +SOCK = None +AWAY = False +CONNECTED_RELAY = False + +def set_timer(): + '''Update timer hook with new interval''' + + global TIMER + if TIMER: + w.unhook(TIMER) + TIMER = w.hook_timer(int(w.config_get_plugin('interval')) * 1000, + 0, 0, "screen_away_timer_cb", '') + +def screen_away_config_cb(data, option, value): + if option.endswith(".interval"): + set_timer() + return w.WEECHAT_RC_OK + +def get_servers(): + '''Get the servers that are not away, or were set away by this script''' + + ignores = w.config_get_plugin('ignore').split(',') + infolist = w.infolist_get('irc_server','','') + buffers = [] + while w.infolist_next(infolist): + if not w.infolist_integer(infolist, 'is_connected') == 1 or \ + w.infolist_string(infolist, 'name') in ignores: + continue + if not w.config_string_to_boolean(w.config_get_plugin('set_away')) or \ + not w.infolist_integer(infolist, 'is_away') or \ + w.config_get_plugin('message') in w.infolist_string(infolist, 'away_message'): +# w.infolist_string(infolist, 'away_message') == \ +# w.config_get_plugin('message'): + buffers.append((w.infolist_pointer(infolist, 'buffer'), + w.infolist_string(infolist, 'nick'))) + w.infolist_free(infolist) + return buffers + +def screen_away_timer_cb(buffer, args): + '''Check if screen is attached, update awayness''' + + global AWAY, SOCK, CONNECTED_RELAY + + set_away = w.config_string_to_boolean(w.config_get_plugin('set_away')) + check_relays = not w.config_string_to_boolean(w.config_get_plugin('ignore_relays')) + suffix = w.config_get_plugin('away_suffix') + attached = os.access(SOCK, os.X_OK) # X bit indicates attached + + # Check wether a client is connected on relay or not + CONNECTED_RELAY = False + if check_relays: + infolist = w.infolist_get('relay', '', '') + if infolist: + while w.infolist_next(infolist): + status = w.infolist_string(infolist, 'status_string') + if status == 'connected': + CONNECTED_RELAY = True + break + w.infolist_free(infolist) + + if (attached and AWAY) or (check_relays and CONNECTED_RELAY and not attached and AWAY): + w.prnt('', '%s: Screen attached. Clearing away status' % SCRIPT_NAME) + for server, nick in get_servers(): + if set_away: + w.command(server, "/away") + if suffix and nick.endswith(suffix): + nick = nick[:-len(suffix)] + w.command(server, "/nick %s" % nick) + AWAY = False + for cmd in w.config_get_plugin("command_on_attach").split(";"): + w.command("", cmd) + + elif not attached and not AWAY: + if not CONNECTED_RELAY: + w.prnt('', '%s: Screen detached. Setting away status' % SCRIPT_NAME) + for server, nick in get_servers(): + if suffix and not nick.endswith(suffix): + w.command(server, "/nick %s%s" % (nick, suffix)); + if set_away: + w.command(server, "/away %s %s" % (w.config_get_plugin('message'), time.strftime(w.config_get_plugin('time_format')))) + AWAY = True + for cmd in w.config_get_plugin("command_on_detach").split(";"): + w.command("", cmd) + + return w.WEECHAT_RC_OK + + +if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, + SCRIPT_DESC, "", ""): + version = w.info_get('version_number', '') or 0 + for option, default_desc in settings.iteritems(): + if not w.config_is_set_plugin(option): + w.config_set_plugin(option, default_desc[0]) + if int(version) >= 0x00030500: + w.config_set_desc_plugin(option, default_desc[1]) + + if 'STY' in os.environ.keys(): + # We are running under screen + cmd_output = os.popen('env LC_ALL=C screen -ls').read() + match = re.search(r'Sockets? in (/.+)\.', cmd_output) + if match: + SOCK = os.path.join(match.group(1), os.environ['STY']) + + if not SOCK and 'TMUX' in os.environ.keys(): + # We are running under tmux + socket_data = os.environ['TMUX'] + SOCK = socket_data.rsplit(',',2)[0] + + if SOCK: + set_timer() + w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", + "screen_away_config_cb", "") diff --git a/weechat/relay.conf b/weechat/relay.conf index dbd6b8c..f5de350 100644 --- a/weechat/relay.conf +++ b/weechat/relay.conf @@ -1,5 +1,5 @@ # -# relay.conf -- weechat v1.1 +# relay.conf -- weechat v1.1.1 # [look] diff --git a/weechat/script.conf b/weechat/script.conf index 59fc23a..866bb1d 100644 --- a/weechat/script.conf +++ b/weechat/script.conf @@ -1,5 +1,5 @@ # -# script.conf -- weechat v1.1 +# script.conf -- weechat v1.1.1 # [look] diff --git a/weechat/sec.conf b/weechat/sec.conf index 899f2a1..53c1e2f 100644 --- a/weechat/sec.conf +++ b/weechat/sec.conf @@ -1,5 +1,5 @@ # -# sec.conf -- weechat v1.1 +# sec.conf -- weechat v1.1.1 # [crypt] diff --git a/weechat/trigger.conf b/weechat/trigger.conf index da31567..2f638e3 100644 --- a/weechat/trigger.conf +++ b/weechat/trigger.conf @@ -1,5 +1,5 @@ # -# trigger.conf -- weechat v1.1 +# trigger.conf -- weechat v1.1.1 # [look] diff --git a/weechat/weechat.conf b/weechat/weechat.conf index a3d6288..fd92411 100644 --- a/weechat/weechat.conf +++ b/weechat/weechat.conf @@ -1,5 +1,5 @@ # -# weechat.conf -- weechat v1.1 +# weechat.conf -- weechat v1.1.1 # [debug] diff --git a/weechat/xfer.conf b/weechat/xfer.conf index 43ec7b2..43d1444 100644 --- a/weechat/xfer.conf +++ b/weechat/xfer.conf @@ -1,5 +1,5 @@ # -# xfer.conf -- weechat v1.1 +# xfer.conf -- weechat v1.1.1 # [look]