@@ -43,14 +43,13 @@ def __init__(self, server=None, **kwargs):
4343 self .server ._update_windows ()
4444
4545 @property
46- def _info (self , * args ):
46+ def _info (self ):
4747
4848 attrs = {
4949 'session_id' : str (self ._session_id )
5050 }
5151
52- # from https://github.com/serkanyersen/underscore.py
53- def by (val , * args ):
52+ def by (val ):
5453 for key , value in attrs .items ():
5554 try :
5655 if attrs [key ] != val [key ]:
@@ -324,7 +323,7 @@ def attached_pane(self):
324323
325324 return self .attached_window .attached_pane
326325
327- def set_option (self , option , value ):
326+ def set_option (self , option , value , g = False ):
328327 """Set option ``$ tmux set-option <option> <value>``.
329328
330329 todo: needs tests
@@ -334,6 +333,8 @@ def set_option(self, option, value):
334333 :param value: window value. True/False will turn in 'on' and 'off'. You
335334 can also enter 'on' or 'off' directly.
336335 :type value: bool
336+ :param global: check for option globally across all servers (-g)
337+ :type global: bool
337338
338339 """
339340
@@ -342,14 +343,22 @@ def set_option(self, option, value):
342343 elif isinstance (value , bool ) and not value :
343344 value = 'off'
344345
346+ tmux_args = tuple ()
347+
348+ if g :
349+ tmux_args += ('-g' ,)
350+
351+ tmux_args += (option , value ,)
352+
345353 proc = self .cmd (
346- 'set-option' , option , value
354+ 'set-option' , * tmux_args
347355 )
348356
349- if proc .stderr :
350- if isinstance (proc .stderr , list ) and len (proc .stderr ) == int (1 ):
351- proc .stderr = proc .stderr [0 ]
352- raise ValueError ('tmux set-option stderr: %s' % proc .stderr )
357+ if isinstance (proc .stderr , list ) and len (proc .stderr ):
358+ error = proc .stderr [0 ]
359+ if 'unknown option' in error :
360+ raise exc .UnknownOption (error )
361+ raise ValueError ('tmux set-option stderr: %s' % error )
353362
354363 def show_options (self , option = None , g = False ):
355364 """Return a dict of options for the window.
@@ -359,7 +368,7 @@ def show_options(self, option=None, g=False):
359368
360369 :param option: optional. show a single option.
361370 :type option: string
362- :param g: Pass ``-g`` flag for global variable
371+ :param g: Pass ``-g`` flag for global variable (server-wide)
363372 :type g: bool
364373 :rtype: :py:obj:`dict`
365374
@@ -395,6 +404,8 @@ def show_option(self, option, g=False):
395404
396405 :param option: option to return.
397406 :type option: string
407+ :param global: check for option globally across all servers (-g)
408+ :type global: bool
398409 :rtype: string, int or bool
399410
400411 """
@@ -404,15 +415,28 @@ def show_option(self, option, g=False):
404415 if g :
405416 tmux_args += ('-g' ,)
406417
407- window_option = self .cmd (
408- 'show-options' , option , * tmux_args
409- ).stdout
410- window_option = [tuple (item .split (' ' )) for item in window_option ][0 ]
418+ tmux_args += (option ,)
419+
420+ cmd = self .cmd (
421+ 'show-options' , * tmux_args
422+ )
423+
424+ if isinstance (cmd .stderr , list ) and len (cmd .stderr ):
425+ error = cmd .stderr [0 ]
426+ if 'unknown option' in error :
427+ raise exc .UnknownOption (error )
428+ else :
429+ raise exc .LibTmuxException (error )
430+
431+ if not len (cmd .stdout ):
432+ return None
433+
434+ option = [item .split (' ' ) for item in cmd .stdout ][0 ]
411435
412- if window_option [1 ].isdigit ():
413- window_option = (window_option [0 ], int (window_option [1 ]))
436+ if option [1 ].isdigit ():
437+ option = (option [0 ], int (option [1 ]))
414438
415- return window_option [1 ]
439+ return option [1 ]
416440
417441 def __repr__ (self ):
418442 return "%s(%s %s)" % (
0 commit comments