def init_zshrc():
import fileinput
exist_conf = load_conf()
if exist_conf:
print('Thunderbolt100k has initialized before, delete the corresponding contents in `~/.zshrc` and try again')
return
# Set default settings
print('Initializing default settings...')
write_conf('VERSION', __VERSION__, first_write=True)
for key in constants.DEFAULT_CONFIG:
write_conf(key, constants.DEFAULT_CONFIG[key])
# Bind polling command to a custom PL9K element
write_conf('POWERLEVEL9K_CUSTOM_POLLING', '"thunderbolt100k polling"', without_prefix=True)
elements_names = ['custom_polling']
# Set PL9K custom command
for m in sys.modules['thunderbolt100k.widgets'].modules:
if m.endswith('__init__.py'):
continue
widget_name = os.path.basename(m).replace('.py', '')
print('Initializing [{0}] widget...'.format(widget_name))
widget = getattr(sys.modules['thunderbolt100k.widgets'], widget_name)
write_conf('POWERLEVEL9K_CUSTOM_{0}'.format(widget_name.upper()),
'"thunderbolt100k display {0}"'.format(widget_name), without_prefix=True)
elements_names.append('custom_{0}'.format(widget_name))
# Ask for extra info for each widgets
result = widget.user_input()
for k in result:
write_conf(k, result[k])
# Add the custom elements to PL9K
home = os.path.expanduser("~")
path = os.path.join(home, '.zshrc')
for line in fileinput.input(path, inplace=True):
if line.startswith('POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS'):
print(line.replace(')', ' {0})'.format(' '.join(elements_names))).rstrip())
else:
print(line.rstrip())
fileinput.close()
print('Initialization done! Open a new shell session and enjoy the view!')
print('You may also want to rearrange the widgets locations by editing `POWERLEVEL9K_LEFT_PROMPT_ELEMENTS` and \n' +
'`POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS` in `~/.zshrc` file')
print('If you want to set configurations for THUNDERBOLT100K, please refer to https://github.com/cuyu/thunderbolt100k#configuration')
评论列表
文章目录