Mercurial > dotfiles
annotate .irssi/scripts/tmux_away.pl @ 325:64e73453e43f
xmonad: Pull apart custom layout into something readable
This change doesn't affect any behavior, but it does document the custom
layout by naming function parameters. Hopefully, this will make things
easier to fix the next time the XMonad developers break us.
author | Lucas Bergman <lucas@bergmans.us> |
---|---|
date | Tue, 11 Mar 2014 12:49:05 -0500 |
parents | 139f30ce463a |
children |
rev | line source |
---|---|
304
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
1 use Irssi; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 use strict; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
3 use FileHandle; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
4 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 use vars qw($VERSION %IRSSI); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
6 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
7 $VERSION = "0.9.7.1"; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
8 %IRSSI = ( |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
9 authors => 'Andreas \'ads\' Scherbaum <ads@wars-nicht.de>, Moritz Wilhelmy <crap@wzff.de>', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
10 name => 'tmux_away', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
11 description => 'set (un)away, if tmux is attached/detached', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
12 license => 'GPL v2', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
13 url => 'none', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
14 ); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
15 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
16 # tmux_away irssi module |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
17 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
18 # written by Andreas 'ads' Scherbaum <ads@ufp.de> |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
19 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
20 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
21 # changes: |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
22 # 07.02.2004 fix error with away mode |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
23 # thanks to Michael Schiansky for reporting and fixing this one |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
24 # 07.08.2004 new function for changing nick on away |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
25 # 24.08.2004 fixing bug where the away nick was not storedcorrectly |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
26 # thanks for Harald Wurpts for help debugging this one |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
27 # 17.09.2004 rewrote init part to use $ENV{'STY'} |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
28 # 05.12.2004 add patch for remember away state |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
29 # thanks to Jilles Tjoelker <jilles@stack.nl> |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
30 # change "chatnet" to "tag" |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
31 # 18.05.2007 fix '-one' for SILC networks |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
32 # 27.02.2010 changed screen_away to tmux_away and changed functionality to support tmux |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
33 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
34 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
35 # usage: |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
36 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
37 # put this script into your autorun directory and/or load it with |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
38 # /SCRIPT LOAD <name> |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
39 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
40 # there are 5 settings available: |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
41 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
42 # /set tmux_away_active ON/OFF/TOGGLE |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
43 # /set tmux_away_repeat <integer> |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
44 # /set tmux_away_message <string> |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
45 # /set tmux_away_window <string> |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
46 # /set tmux_away_nick <string> |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
47 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
48 # active means, that you will be only set away/unaway, if this |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
49 # flag is set, default is ON |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
50 # repeat is the number of seconds, after the script will check the |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
51 # screen status again, default is 5 seconds |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
52 # message is the away message sent to the server, default: not here ... |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
53 # window is a window number or name, if set, the script will switch |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
54 # to this window, if it sets you away, default is '1' |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
55 # nick is the new nick, if the script goes away |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
56 # will only be used it not empty |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
57 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
58 # normal you should be able to rename the script to something other |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
59 # than 'tmux_away' (as example, if you dont like the name) by simple |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
60 # changing the 'name' parameter in the %IRSSI hash at the top of this script |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
61 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
62 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
63 # variables |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
64 my $timer_name = undef; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
65 my $away_status = 0; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
66 my %old_nicks = (); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
67 my %away = (); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
68 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
69 # Register formats |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
70 Irssi::theme_register( |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
71 [ |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
72 'tmux_away_crap', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
73 '{line_start}{hilight ' . $IRSSI{'name'} . ':} $0' |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
74 ]); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
75 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
76 # if we are running |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
77 my $tmux_away_used = 0; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
78 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
79 # try to find out, if we are running in a screen |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
80 # (see, if $ENV{STY} is set |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
81 if (!defined($ENV{TMUX})) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
82 # just return, we will never be called again |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
83 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
84 "could not open status file for parent process (pid: " . getppid() . "): $!"); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
85 return; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
86 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
87 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
88 my ($socket_name, $socket_path); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
89 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
90 # search for socket |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
91 # normal we could search the socket file, ... if we know the path |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
92 # but so we have to call one time the screen executable |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
93 # disable locale |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
94 # the quotes around C force perl 5.005_03 to use the shell |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
95 # thanks to Jilles Tjoelker <jilles@stack.nl> for pointing this out |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
96 my $socket = `LC_ALL="C" tmux ls 2>&1`; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
97 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
98 my $running_in_tmux = $? == 0; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
99 # locale doesnt seems to be an problem (yet) |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
100 if ($socket !~ /^server not found: No such file or directory/s) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
101 # ok, should have only one socket |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
102 @_ = split /,/, $ENV{'TMUX'}; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
103 $socket = ${_[0]}; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
104 $tmux_away_used = 1; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
105 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
106 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
107 # last check |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
108 if ($tmux_away_used == 0) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
109 # we will never be called again |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
110 return; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
111 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
112 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
113 # register config variables |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
114 Irssi::settings_add_bool('misc', $IRSSI{'name'} . '_active', 1); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
115 Irssi::settings_add_int('misc', $IRSSI{'name'} . '_repeat', 5); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
116 Irssi::settings_add_str('misc', $IRSSI{'name'} . '_message', "not here ..."); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
117 Irssi::settings_add_str('misc', $IRSSI{'name'} . '_window', "1"); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
118 Irssi::settings_add_str('misc', $IRSSI{'name'} . '_nick', ""); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
119 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
120 # init process |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
121 tmux_away(); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
122 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
123 # tmux_away() |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
124 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
125 # check, set or reset the away status |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
126 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
127 # parameter: |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
128 # none |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
129 # return: |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
130 # 0 (OK) |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
131 sub tmux_away { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
132 my ($away, @screen, $screen); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
133 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
134 # only run, if activated |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
135 if (Irssi::settings_get_bool($IRSSI{'name'} . '_active') == 1) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
136 if ($away_status == 0) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
137 # display init message at first time |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
138 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
139 "activating $IRSSI{'name'} (interval: " . Irssi::settings_get_int($IRSSI{'name'} . '_repeat') . " seconds)"); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
140 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
141 # get actual screen status |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
142 my @screen = stat($socket); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
143 # 00100 is the mode for "user has execute permissions", see stat.h |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
144 if (($screen[2] & 00100) == 0) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
145 # no execute permissions, Detached |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
146 $away = 1; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
147 } else { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
148 # execute permissions, Attached |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
149 $away = 2; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
150 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
151 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
152 # check if status has changed |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
153 if ($away == 1 and $away_status != 1) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
154 # set away |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
155 if (length(Irssi::settings_get_str($IRSSI{'name'} . '_window')) > 0) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
156 # if length of window is greater then 0, make this window active |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
157 Irssi::command('window goto ' . Irssi::settings_get_str($IRSSI{'name'} . '_window')); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
158 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
159 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
160 "Set away"); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
161 my $message = Irssi::settings_get_str($IRSSI{'name'} . '_message'); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
162 if (length($message) == 0) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
163 # we have to set a message or we wouldnt go away |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
164 $message = "not here ..."; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
165 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
166 my ($server); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
167 foreach $server (Irssi::servers()) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
168 if (!$server->{usermode_away}) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
169 # user isnt yet away |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
170 $away{$server->{'tag'}} = 0; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
171 $server->command("AWAY " . (($server->{chat_type} ne 'SILC') ? "-one " : "") . "$message") if (!$server->{usermode_away}); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
172 if (length(Irssi::settings_get_str($IRSSI{'name'} . '_nick')) > 0) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
173 # only change, if actual nick isnt already the away nick |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
174 if (Irssi::settings_get_str($IRSSI{'name'} . '_nick') ne $server->{nick}) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
175 # keep old nick |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
176 $old_nicks{$server->{'tag'}} = $server->{nick}; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
177 # set new nick |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
178 $server->command("NICK " . Irssi::settings_get_str($IRSSI{'name'} . '_nick')); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
179 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
180 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
181 } else { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
182 # user is already away, remember this |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
183 $away{$server->{'tag'}} = 1; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
184 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
185 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
186 $away_status = $away; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
187 } elsif ($away == 2 and $away_status != 2) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
188 # unset away |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
189 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'tmux_away_crap', |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
190 "Reset away"); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
191 my ($server); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
192 foreach $server (Irssi::servers()) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
193 if ($away{$server->{'tag'}} == 1) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
194 # user was already away, dont reset away |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
195 $away{$server->{'tag'}} = 0; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
196 next; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
197 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
198 $server->command("AWAY" . (($server->{chat_type} ne 'SILC') ? " -one" : "")) if ($server->{usermode_away}); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
199 if (defined($old_nicks{$server->{'tag'}}) and length($old_nicks{$server->{'tag'}}) > 0) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
200 # set old nick |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
201 $server->command("NICK " . $old_nicks{$server->{'tag'}}); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
202 $old_nicks{$server->{'tag'}} = ""; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
203 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
204 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
205 $away_status = $away; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
206 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
207 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
208 # but everytimes install a new timer |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
209 register_tmux_away_timer(); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
210 return 0; |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
211 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
212 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
213 # register_tmux_away_timer() |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
214 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
215 # remove old timer and install a new one |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
216 # |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
217 # parameter: |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
218 # none |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
219 # return: |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
220 # none |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
221 sub register_tmux_away_timer { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
222 if (defined($timer_name)) { |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
223 # remove old timer, if defined |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
224 Irssi::timeout_remove($timer_name); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
225 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
226 # add new timer with new timeout (maybe the timeout has been changed) |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
227 $timer_name = Irssi::timeout_add(Irssi::settings_get_int($IRSSI{'name'} . '_repeat') * 1000, 'tmux_away', ''); |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
228 } |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
229 |
139f30ce463a
irssi: install and autorun tmux_away.pl
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
230 |