Skip to content

Commit d389506

Browse files
committed
[emrun] Simplify which helper. NFC
1 parent 7f385f3 commit d389506

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

emrun.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,19 +1144,15 @@ def is_exe(fpath):
11441144
if is_exe(program):
11451145
return program
11461146
else:
1147-
for path in os.environ["PATH"].split(os.pathsep):
1147+
exe_suffixes = ['']
1148+
if WINDOWS and '.' not in fname:
1149+
exe_suffixes = ['.exe', '.cmd', '.bat']
1150+
for path in os.environ['PATH'].split(os.pathsep):
11481151
path = path.strip('"')
11491152
exe_file = os.path.join(path, program)
1150-
if is_exe(exe_file):
1151-
return exe_file
1152-
1153-
if WINDOWS and '.' not in fname:
1154-
if is_exe(exe_file + '.exe'):
1155-
return exe_file + '.exe'
1156-
if is_exe(exe_file + '.cmd'):
1157-
return exe_file + '.cmd'
1158-
if is_exe(exe_file + '.bat'):
1159-
return exe_file + '.bat'
1153+
for ext in exe_suffixes:
1154+
if is_exe(exe_file + ext):
1155+
return exe_file + ext
11601156

11611157
return None
11621158

@@ -1192,17 +1188,8 @@ def find_browser(name):
11921188
if MACOS and name == 'open':
11931189
return [name]
11941190

1195-
if os.path.isfile(os.path.abspath(name)):
1196-
return [name]
1197-
if os.path.isfile(os.path.abspath(name) + '.exe'):
1198-
return [os.path.abspath(name) + '.exe']
1199-
if os.path.isfile(os.path.abspath(name) + '.cmd'):
1200-
return [os.path.abspath(name) + '.cmd']
1201-
if os.path.isfile(os.path.abspath(name) + '.bat'):
1202-
return [os.path.abspath(name) + '.bat']
1203-
12041191
path_lookup = which(name)
1205-
if path_lookup is not None:
1192+
if path_lookup:
12061193
return [path_lookup]
12071194

12081195
browser_locations = []
@@ -1246,7 +1233,7 @@ def find_browser(name):
12461233

12471234
for alias, browser_exe in browser_locations:
12481235
if name == alias:
1249-
if browser_exe is not None and os.path.isfile(browser_exe):
1236+
if browser_exe and os.path.isfile(browser_exe):
12501237
return [browser_exe]
12511238

12521239
return None # Could not find the browser

0 commit comments

Comments
 (0)