# Regular expression for comments in config file
comment_re = re.compile(
- '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
+ '(^)[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
re.DOTALL | re.MULTILINE
)
# Config dictionary
c = {}
+def user_filepath():
+ """
+ Determine the user's config file location
+ """
+ if 'RAINBOW_CONFIG' in os.environ:
+ return os.environ['RAINBOW_CONFIG']
+
+ return os.path.expanduser("~") + os.sep + '.rainbow_config.json'
def fixup(adict, k, v):
"""
Get all config
"""
try:
- path = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
+ path = user_filepath()
data = load_config(path)
# Hard to set from prompt
data.pop('ONLY_LIST', None)
data.pop('IGNORE_LIST', None)
data.pop('FORMAT', None)
+ data.pop('QUOTE_FORMAT', None)
+ data.pop('NOTIFY_FORMAT', None)
return data
except:
return []
# Update global config
c[key] = value
# Load current user config
- path = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
+ path = user_filepath()
data = {}
try:
data = load_config(path)
"""
Delete a config key
"""
- path = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
- try:
+ path = user_filepath()
+ try:
data = load_config(path)
except:
raise Exception('Config file is messed up.')
"""
Reload config
"""
- try:
- rainbow_config = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
+ try:
+ rainbow_config = user_filepath()
data = load_config(rainbow_config)
for d in data:
c[d] = data[d]
except:
pass
# Load user's config
- rainbow_config = os.path.expanduser("~") + os.sep + '.rainbow_config.json'
+ rainbow_config = user_filepath()
try:
data = load_config(rainbow_config)
for d in data:
c[d] = data[d]
- except ValueError as e:
+ except (IOError, ValueError) as e:
c['USER_JSON_ERROR'] = str(e)
# Load default theme
theme_file = os.path.dirname(__file__) + \