Skip to content

Commit

Permalink
Factored out initialization of global variable d
Browse files Browse the repository at this point in the history
  • Loading branch information
marczuo committed Jul 21, 2016
1 parent 828d996 commit 14c97c7
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions dmenu_extended.py
Expand Up @@ -109,6 +109,17 @@
"indicator_alias": "" # Symbol to indecate an aliased command
}

def initialize_d(launch_args):
global d
if d is None:
d = dmenu()
d.launch_args = launch_args

if '--debug' in d.launch_args:
d.debug = True
d.launch_args.remove('--debug')
print('Debugging enabled')
print('Launch arguments: ' + str(launch_args))

def setup_user_files():
""" Returns nothing
Expand Down Expand Up @@ -185,6 +196,10 @@ def setup_user_files():


def load_plugins(debug=False):
global d

initialize_d([])

if debug:
print('Loading plugins')

Expand Down Expand Up @@ -781,7 +796,7 @@ def parse_alias_file(self, path):
parts = line[6:].replace('\n','').replace('\'','').replace('"','').split('=')
out.append([parts[0], parts[1]])
return out


def cache_build(self):
self.load_preferences()
Expand Down Expand Up @@ -1266,18 +1281,9 @@ def handle_command(d, out):


def run(*args):
global d

launch_args = list(args[1:])

d = dmenu()
d.launch_args = launch_args

if '--debug' in d.launch_args:
d.debug = True
d.launch_args.remove('--debug')
print('Debugging enabled')
print('Launch arguments: ' + str(launch_args))
initialize_d(launch_args)

d.load_preferences()
cache = d.cache_load()
Expand Down Expand Up @@ -1390,7 +1396,7 @@ def run(*args):
print("No")

# If removing a command - an alias would be detected as a command

if action == '-' and type(item) == list:
if d.debug:
print("Is (-) " + str(d.format_alias(item[0], item[1])) + " == " + str(command) + "?")
Expand Down Expand Up @@ -1422,7 +1428,7 @@ def run(*args):
print("Alias is now: " + str(alias))
break
elif d.debug:
print("No")
print("No")

if d.debug:
print("Is (-) " + str(item[0]) + " == " + str(command) + "?")
Expand All @@ -1438,7 +1444,7 @@ def run(*args):
print("Alias is now: " + str(alias))
break
elif d.debug:
print("No")
print("No")

if type(item) != list:
if d.debug:
Expand Down Expand Up @@ -1468,7 +1474,7 @@ def run(*args):
answer = d.menu("Alias '" + str(alias) + "' was not found in store\n"+option)
if answer != option:
sys.exit()
action = '+'
action = '+'


cache_scanned = d.cache_open(file_cache)[:-1]
Expand Down Expand Up @@ -1546,7 +1552,7 @@ def run(*args):
sys.exit()

d.save_preferences()
d.cache_save(cache_scanned, file_cache)
d.cache_save(cache_scanned, file_cache)
d.message_close()

# Give the user some feedback
Expand Down

0 comments on commit 14c97c7

Please sign in to comment.