Skip to content

Commit 5f0d037

Browse files
committed
move oh_my_zsh_auto_title to util package
1 parent a761ea1 commit 5f0d037

File tree

2 files changed

+60
-20
lines changed

2 files changed

+60
-20
lines changed

tmuxp/cli.py

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,26 @@ def subcommand_load(args):
178178
logger.error('%s not found.' % configfile)
179179

180180

181+
def subcommand_convert(args):
182+
if args.configs:
183+
if '.' in args.configs:
184+
args.configs.remove('.')
185+
if config.in_cwd():
186+
args.configs.append(config.in_cwd()[0])
187+
else:
188+
print('No tmuxp configs found in current directory.')
189+
190+
for configfile in args.configs:
191+
file_user = os.path.join(config_dir, configfile)
192+
file_cwd = os.path.join(cwd_dir, configfile)
193+
if os.path.exists(file_cwd) and os.path.isfile(file_cwd):
194+
print file_cwd
195+
elif os.path.exists(file_user) and os.path.isfile(file_user):
196+
print file_uesr
197+
else:
198+
logger.error('%s not found.' % configfile)
199+
200+
181201
def subcommand_attach_session(args):
182202
commands = []
183203
try:
@@ -268,10 +288,29 @@ def cli_parser():
268288
$ tmuxp .
269289
270290
will check launch a ~/.pullv.yaml / ~/.pullv.json from the cwd.
291+
will also check for any ./*.yaml and ./*.json.
271292
''' % (cwd_dir + '/', config_dir)
272293
)
273294
load.set_defaults(callback=subcommand_load)
274295

296+
convert = subparsers.add_parser('convert')
297+
298+
convert.add_argument(
299+
dest='configs',
300+
nargs='*',
301+
type=str,
302+
default=None,
303+
help='''\
304+
Checks current working directory (%s) then $HOME/.tmuxp directory (%s).
305+
306+
$ tmuxp .
307+
308+
will check launch a ~/.pullv.yaml / ~/.pullv.json from the cwd.
309+
will also check for any ./*.yaml and ./*.json.
310+
''' % (cwd_dir + '/', config_dir)
311+
)
312+
convert.set_defaults(callback=subcommand_convert)
313+
275314
parser.add_argument('--log-level', dest='log_level', default='INFO',
276315
metavar='log-level',
277316
help='Log level e.g. INFO, DEBUG, ERROR')
@@ -302,7 +341,7 @@ def main():
302341
logger.error(e)
303342
sys.exit()
304343

305-
oh_my_zsh_auto_title()
344+
util.oh_my_zsh_auto_title()
306345

307346
if args.callback is subcommand_load:
308347
subcommand_load(args)
@@ -337,7 +376,7 @@ def complete(cline, cpoint):
337376
ctext = cline.replace('tmuxp ', '')
338377

339378
commands = []
340-
commands.extend(['attach-session', 'kill-session', 'load'])
379+
commands.extend(['attach-session', 'kill-session', 'load', 'convert'])
341380

342381
commands = [c for c in commands if ctext in c]
343382

@@ -375,23 +414,6 @@ def config_complete(command, commands, ctext):
375414
session_complete('attach-session', commands, ctext)
376415
session_complete('kill-session', commands, ctext)
377416
config_complete('load', commands, ctext)
417+
config_complete('convert', commands, ctext)
378418

379419
print(' \n'.join(commands))
380-
381-
382-
def oh_my_zsh_auto_title():
383-
'''give warning and offer to fix DISABLE_AUTO_TITLE
384-
385-
see: https://github.com/robbyrussell/oh-my-zsh/pull/257
386-
'''
387-
388-
if 'SHELL' in os.environ and 'zsh' in os.environ.get('SHELL'):
389-
if os.path.exists(os.path.expanduser('~/.oh-my-zsh')):
390-
# oh-my-zsh exists
391-
if 'DISABLE_AUTO_TITLE' not in os.environ or os.environ.get('DISABLE_AUTO_TITLE') == "false":
392-
print('Please set:\n\n'
393-
'\texport DISABLE_AUTO_TITLE = \'true\'\n\n'
394-
'in ~/.zshrc or where your zsh profile is stored.\n'
395-
'Remember the "export" at the beginning!\n\n'
396-
'Then create a new shell or type:\n\n'
397-
'\t$ source ~/.zshrc')

tmuxp/util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,24 @@ def version():
233233
return version
234234

235235

236+
def oh_my_zsh_auto_title():
237+
'''give warning and offer to fix DISABLE_AUTO_TITLE
238+
239+
see: https://github.com/robbyrussell/oh-my-zsh/pull/257
240+
'''
241+
242+
if 'SHELL' in os.environ and 'zsh' in os.environ.get('SHELL'):
243+
if os.path.exists(os.path.expanduser('~/.oh-my-zsh')):
244+
# oh-my-zsh exists
245+
if 'DISABLE_AUTO_TITLE' not in os.environ or os.environ.get('DISABLE_AUTO_TITLE') == "false":
246+
print('Please set:\n\n'
247+
'\texport DISABLE_AUTO_TITLE = \'true\'\n\n'
248+
'in ~/.zshrc or where your zsh profile is stored.\n'
249+
'Remember the "export" at the beginning!\n\n'
250+
'Then create a new shell or type:\n\n'
251+
'\t$ source ~/.zshrc')
252+
253+
236254
# http://www.rfk.id.au/blog/entry/preparing-pyenchant-for-python-3/
237255
try:
238256
unicode = unicode

0 commit comments

Comments
 (0)