@@ -138,7 +138,7 @@ def build_workspace(config_file, args):
138
138
139
139
140
140
def subcommand_load (args ):
141
- if args .list_configs :
141
+ if args .list :
142
142
startup (config_dir )
143
143
configs_in_user = config .in_dir (config_dir )
144
144
configs_in_cwd = config .in_cwd ()
@@ -159,15 +159,15 @@ def subcommand_load(args):
159
159
160
160
print (output )
161
161
162
- elif args .configs :
163
- if '.' in args .configs :
164
- args .configs .remove ('.' )
162
+ elif args .config :
163
+ if '.' in args .config :
164
+ args .config .remove ('.' )
165
165
if config .in_cwd ():
166
- args .configs .append (config .in_cwd ()[0 ])
166
+ args .config .append (config .in_cwd ()[0 ])
167
167
else :
168
168
print ('No tmuxp configs found in current directory.' )
169
169
170
- for configfile in args .configs :
170
+ for configfile in args .config :
171
171
file_user = os .path .join (config_dir , configfile )
172
172
file_cwd = os .path .join (cwd_dir , configfile )
173
173
if os .path .exists (file_cwd ) and os .path .isfile (file_cwd ):
@@ -187,16 +187,16 @@ def subcommand_import_tmuxinator(args):
187
187
188
188
189
189
def subcommand_convert (args ):
190
- if args .configs :
191
- if '.' in args .configs :
192
- args .configs .remove ('.' )
190
+ if args .config :
191
+ if '.' in args .config :
192
+ args .config .remove ('.' )
193
193
if config .in_cwd ():
194
- args .configs .append (config .in_cwd ()[0 ])
194
+ args .config .append (config .in_cwd ()[0 ])
195
195
else :
196
196
print ('No tmuxp configs found in current directory.' )
197
197
198
198
try :
199
- configfile = args .configs [ 0 ]
199
+ configfile = args .config
200
200
except Exception :
201
201
print ('Please enter a config' )
202
202
@@ -242,17 +242,16 @@ def subcommand_convert(args):
242
242
243
243
def subcommand_attach_session (args ):
244
244
commands = []
245
- try :
246
- ctext = args .session_name [0 ]
247
- except IndexError as e :
248
- return
245
+ ctext = args .session_name
249
246
250
- t = Server ()
247
+ t = Server (
248
+ socket_name = args .socket_name or None ,
249
+ socket_path = args .socket_path or None
250
+ )
251
251
try :
252
- session = [s for s in t .sessions if s .get ('session_name' ) == ctext ][0 ]
253
- except IndexError as e :
254
- print ('Session not found.' )
255
- return
252
+ session = next ((s for s in t .sessions if s .get ('session_name' ) == ctext ), None )
253
+ if not session :
254
+ raise Exception ('Session not found.' )
256
255
except Exception as e :
257
256
print (e .message [0 ])
258
257
return
@@ -268,20 +267,25 @@ def subcommand_attach_session(args):
268
267
269
268
def subcommand_kill_session (args ):
270
269
commands = []
271
- ctext = args .session_name [0 ]
270
+ ctext = args .session_name
271
+
272
+ t = Server (
273
+ socket_name = args .socket_name or None ,
274
+ socket_path = args .socket_path or None
275
+ )
272
276
273
- t = Server ()
274
277
try :
275
- sessions = [s for s in t .sessions if s .get ('session_name' ) == ctext ]
278
+ session = next ((s for s in t .sessions if s .get ('session_name' ) == ctext ), None )
279
+ if not session :
280
+ raise Exception ('Session not found.' )
276
281
except Exception as e :
277
282
print (e .message [0 ])
278
283
return
279
284
280
- if (len (sessions ) == 1 ):
281
- try :
282
- sessions [0 ].kill_session ()
283
- except Exception as e :
284
- logger .error (e )
285
+ try :
286
+ session .kill_session ()
287
+ except Exception as e :
288
+ logger .error (e )
285
289
286
290
287
291
def cli_parser ():
@@ -301,7 +305,6 @@ def cli_parser():
301
305
302
306
kill_session .add_argument (
303
307
dest = 'session_name' ,
304
- nargs = 1 ,
305
308
type = str ,
306
309
default = None ,
307
310
)
@@ -311,22 +314,20 @@ def cli_parser():
311
314
312
315
attach_session .add_argument (
313
316
dest = 'session_name' ,
314
- nargs = 1 ,
315
317
type = str ,
316
- default = None ,
317
318
)
318
319
319
320
load = subparsers .add_parser ('load' )
320
321
321
- load .add_argument (
322
- '-l' , '--list' , dest = 'list_configs' , action = 'store_true' ,
322
+ loadgroup = load .add_mutually_exclusive_group (required = True )
323
+ loadgroup .add_argument (
324
+ '-l' , '--list' , dest = 'list' , action = 'store_true' ,
323
325
help = 'List config files available' )
324
326
325
- load .add_argument (
326
- dest = 'configs' ,
327
- nargs = 1 ,
327
+ loadgroup .add_argument (
328
+ dest = 'config' ,
328
329
type = str ,
329
- default = None ,
330
+ nargs = '?' ,
330
331
help = '''\
331
332
List of config files to launch session from.
332
333
@@ -343,8 +344,7 @@ def cli_parser():
343
344
convert = subparsers .add_parser ('convert' )
344
345
345
346
convert .add_argument (
346
- dest = 'configs' ,
347
- nargs = 1 ,
347
+ dest = 'config' ,
348
348
type = str ,
349
349
default = None ,
350
350
help = '''\
@@ -367,7 +367,6 @@ def cli_parser():
367
367
368
368
import_teamocil .add_argument (
369
369
dest = 'config' ,
370
- nargs = 1 ,
371
370
type = str ,
372
371
default = None ,
373
372
help = '''\
@@ -380,7 +379,6 @@ def cli_parser():
380
379
381
380
import_tmuxinator .add_argument (
382
381
dest = 'config' ,
383
- nargs = 1 ,
384
382
type = str ,
385
383
default = None ,
386
384
help = '''\
@@ -428,6 +426,10 @@ def main():
428
426
subcommand_load (args )
429
427
elif args .callback is subcommand_convert :
430
428
subcommand_convert (args )
429
+ elif args .callback is subcommand_import_teamocil :
430
+ subcommand_import_teamocil (args )
431
+ elif args .callback is subcommand_import_tmuxinator :
432
+ subcommand_import_tmuxinator (args )
431
433
elif args .callback is subcommand_attach_session :
432
434
subcommand_attach_session (args )
433
435
elif args .callback is subcommand_kill_session :
0 commit comments