Package plugins :: Package core :: Package shell :: Module bash

[hide private]
[frames] | no frames]

# Source Code for Module plugins.core.shell.bash

     1  #-*- coding: utf8 -*
     2  #
     3  # Max E. Kuznecov ~syhpoon <mek@mek.uz.ua> 2008-2009
     4  #
     5  # This file is part of XYZCommander.
     6  # XYZCommander is free software: you can redistribute it and/or modify
     7  # it under the terms of the GNU Lesser Public License as published by
     8  # the Free Software Foundation, either version 3 of the License, or
     9  # (at your option) any later version.
    10  # XYZCommander is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  # GNU Lesser Public License for more details.
    14  # You should have received a copy of the GNU Lesser Public License
    15  # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>.
    16
    17  """
    18  Bash setup function
    19  """
    20
    21  import subprocess
    22  import re
    23
    24  from libxyz.core.dsl import XYZ
    25  from libxyz.core.utils import ustring
    26
    27 -def bash_setup(path):
    28      # Fake PS1 in order to process .bashrc
    29
    30      aliasre = re.compile(r"^alias\s+(.+?)='(.+?)'\s*$")
    31
    32      try:
    33          result = subprocess.Popen([
    34              path, "-c", "PS1='.'; source ~/.bashrc ; alias"],
    35                                    stdout=subprocess.PIPE
    36                                    ).communicate()[0].strip()
    37
    38          if result:
    39              for line in result.split("\n"):
    40                  match = aliasre.search(line)
    41
    42                  if match:
    43                      XYZ.alias(match.group(1), match.group(2))
    44      except Exception, e:
    45          xyzlog.warning(_(u"Error setting up bash: %s") % ustring(str(e)))
    46