BashStyle-NG startup checker changes:

- renamed check_bashstyle to CheckBashStyle and moved into config module
- renamed set_bashstyle to EnableBashStyle and moved into config module
- made popup window a tab page instead
- CheckBashStyle now not only check if a startup entry exists, but also if it has the correct installation prefix (in case a previous version of BashStyle-NG had a different installation prefix and thus the .bashrc contains an outdated entry) and whether the startup entry is not commented out (regard of how many # or if there are blanks before or whatever)
parent 9b3895f6
......@@ -6,8 +6,11 @@ Overview of changes in v9.2 "Galvanize"
++ before BashStyle-NG embedded into /etc/bash.bashrc or /etc/bashrc to add
a startup entry to ${HOME}/.bashrc
++ now if ${HOME}/.bashrc does not contain a startup entry for BashStyle-NG
the user is presented a popup window upon UI start asking whether to add
the entry or telling the user how to do it manually.
the user is presented a tab page upon UI start asking whether to add
the entry or telling the user how to do it manually. Also works when the
startup entry for BashStyle-NG is commented out, or if the entry is from
a previous installation of BashStyle-NG that had a different installation
prefix.
* PS2 / PS3 / PS4 changes:
++ before there's been an option for PS234. Setting this to ">" resulted in:
......
......@@ -255,88 +255,6 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkDialog" id="popup">
<property name="can_focus">False</property>
<property name="title" translatable="yes">BashStyle-NG</property>
<property name="window_position">center-on-parent</property>
<property name="destroy_with_parent">True</property>
<property name="icon_name">bs-ng</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="popup.enable">
<property name="label" translatable="yes">Enable</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="popup.cancel">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="popup.label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">BashStyle-NG is not loaded upon Shell start.
Click [Enable] to let the application add a startup
entry for itself into your ${HOME}/.bashrc
If you click [Cancel] changes done here won't take
effect. This popup will re-appear every time you
start the application and when there's no entry in
your ${HOME}/.bashrc
You can add the entry manually like:
source /usr/share/bashstyle-ng/rc/nx-rc
assuming /usr was the choosen install prefix. </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkAdjustment" id="readline.adjustment.query_items">
<property name="upper">10000</property>
<property name="step_increment">1</property>
......@@ -7512,6 +7430,109 @@ lsb = show branches by last activity</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="startup.box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="popup.label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">BashStyle-NG is not loaded upon Shell start.
Click [Enable] to let the application add a startup
entry for itself into your ${HOME}/.bashrc
If you click [Cancel] changes done here won't take
effect. This popup will re-appear every time you
start the application and when there's no entry in
your ${HOME}/.bashrc
You can add the entry manually like:
source /usr/share/bashstyle-ng/rc/nx-rc
assuming /usr was the choosen install prefix. </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator" id="separator2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">26</property>
<property name="margin_right">26</property>
<property name="margin_top">7</property>
<property name="margin_bottom">7</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="startup.buttonbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="spacing">15</property>
<property name="homogeneous">True</property>
<property name="layout_style">start</property>
<child>
<object class="GtkButton" id="startup.enable">
<property name="label" translatable="yes">Enable</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="startup.cancel">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">13</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="startup.label">
<property name="can_focus">False</property>
<property name="label" translatable="yes">StartUp</property>
</object>
<packing>
<property name="position">13</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
......
......@@ -57,41 +57,6 @@ class BashStyleNG(object):
gtkbuilder = widgethandler.gtkbuilder
WidgetHandler = widgethandler.WidgetHandler(config.cfo, config.udc, config.fdc)
######################## BashStyle-NG autostart stuff ##############################
def check_bashstyle():
rc = open(os.path.expanduser("~/.bashrc"), "r")
content = rc.readlines()
found = False
for line in content:
if line.find("bashstyle-ng/rc/nx-rc") != -1:
found = True
rc.close
return found
def set_bashstyle(widget, OnOff):
rc = open(os.path.expanduser("~/.bashrc"), "r")
rc_new = open(os.path.expanduser("~/.bashrc.new"), "w")
content = rc.readlines()
for line in content:
if line.find("bashstyle-ng/rc/nx-rc") == -1:
rc_new.write(line)
rc.close
if OnOff == True:
rc_new.write("\nsource " + os.getenv('BSNG_DATADIR') + "bashstyle-ng/rc/nx-rc")
rc_new.close
shutil.move(os.path.expanduser("~/.bashrc.new"), os.path.expanduser("~/.bashrc"))
popup.hide()
if check_bashstyle() == False:
popup = gtkbuilder.get_object("popup")
popup_enable = gtkbuilder.get_object("popup.enable")
popup_cancel = gtkbuilder.get_object("popup.cancel")
popup_enable.connect("clicked", set_bashstyle, True)
popup_cancel.connect("clicked", lambda w: popup.hide() or True)
popup.connect("delete-event", lambda w: w.hide() or True)
popup.show_all()
####################### Style Options ##############################################
WidgetHandler.InitWidget("use_bashstyle", "Style", "use_bashstyle", "bool", None)
WidgetHandler.InitWidget("colored_prompts", "Style", "enable_colors", "bool", None)
......
......@@ -142,3 +142,26 @@ class Config(object):
def GetFactoryConfig(self, group, setting):
print(self.fdc["%s" % group]["%s" % setting])
def CheckBashStyle(self):
rc = open(os.path.expanduser("~/.bashrc"), "r")
content = rc.readlines()
found = False
for line in content:
if line.startswith("source " + os.getenv('BSNG_DATADIR') + "bashstyle-ng/rc/nx-rc", 0) == True:
found = True
rc.close
return found
def EnableBashStyle(self, OnOff):
rc = open(os.path.expanduser("~/.bashrc"), "r")
rc_new = open(os.path.expanduser("~/.bashrc.new"), "w")
content = rc.readlines()
for line in content:
if line.find("bashstyle-ng/rc/nx-rc") == -1:
rc_new.write(line)
rc.close
if OnOff == True:
rc_new.write("\nsource " + os.getenv('BSNG_DATADIR') + "bashstyle-ng/rc/nx-rc")
rc_new.close
shutil.move(os.path.expanduser("~/.bashrc.new"), os.path.expanduser("~/.bashrc"))
......@@ -10,7 +10,7 @@
# #
#########################################################
MODULES = [ 'sys', 'widgethandler', 'subprocess' ]
MODULES = [ 'sys', 'widgethandler', 'subprocess', 'config' ]
FAILED = []
......@@ -67,7 +67,8 @@ notebook_pages = {
_("Shell Options") : 10,
_("GIT") : 9,
_("About BashStyle-NG") : 12,
_("Keybindings") : 11
_("Keybindings") : 11,
_("BashStyle-NG StartUp") : 13
}
gtkbuilder = widgethandler.gtkbuilder
......@@ -114,3 +115,22 @@ class IconBook(object):
use_keys_button.set_visible(1)
iconview.connect("item-activated", iconview_activated)
if config.Config.CheckBashStyle(self) == False:
startup_enable = gtkbuilder.get_object("startup.enable")
startup_cancel = gtkbuilder.get_object("startup.cancel")
def setBashStyle(data):
config.Config.EnableBashStyle(self, True)
notebook.set_current_page(0)
main_label.set_text(_("Choose a Category:"))
def abortBashStyle(data):
notebook.set_current_page(0)
main_label.set_text(_("Choose a Category:"))
startup_enable.connect("clicked", setBashStyle)
startup_cancel.connect("clicked", abortBashStyle)
notebook.set_current_page(13)
main_label.set_text(_("Category: ") + _("BashStyle-NG StartUp"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment