summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2016-08-26 23:57:53 +0200
committerhut <hut@lepus.uberspace.de>2016-08-26 23:57:53 +0200
commitb5ed90134fa9fce00231f11b8899e9184272d113 (patch)
treea4f1ed483b2bb9e825e2d5e652d5c2e4a6ebafc5
parent4b47c0a3379dbd3ce7640ed6435cfc7e24e988fe (diff)
parent058a7ebe563e4c30ff9bd15b2861c1f86df7d23b (diff)
downloadranger-b5ed90134fa9fce00231f11b8899e9184272d113.tar.gz
Merge branch 'open_terminal_with_options' of https://github.com/Vifon/ranger
-rwxr-xr-xranger/config/commands.py10
-rw-r--r--ranger/core/runner.py8
-rw-r--r--ranger/ext/get_executables.py14
3 files changed, 18 insertions, 14 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index a5117696..18efbfc1 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -493,14 +493,8 @@ class terminal(Command):
     Spawns an "x-terminal-emulator" starting in the current directory.
     """
     def execute(self):
-        import os
-        from ranger.ext.get_executables import get_executables
-        command = os.environ.get('TERMCMD', os.environ.get('TERM'))
-        if command not in get_executables():
-            command = 'x-terminal-emulator'
-        if command not in get_executables():
-            command = 'xterm'
-        self.fm.run(command, flags='f')
+        from ranger.ext.get_executables import get_term
+        self.fm.run(get_term(), flags='f')
 
 
 class delete(Command):
diff --git a/ranger/core/runner.py b/ranger/core/runner.py
index 6d03f8fb..78d52764 100644
--- a/ranger/core/runner.py
+++ b/ranger/core/runner.py
@@ -25,7 +25,7 @@ t: run application in a new terminal window
 import os
 import sys
 from subprocess import Popen, PIPE
-from ranger.ext.get_executables import get_executables
+from ranger.ext.get_executables import get_executables, get_term
 from ranger.ext.popen_forked import Popen_forked
 
 
@@ -194,11 +194,7 @@ class Runner(object):
         if 't' in context.flags:
             if 'DISPLAY' not in os.environ:
                 return self._log("Can not run with 't' flag, no display found!")
-            term = os.environ.get('TERMCMD', os.environ.get('TERM'))
-            if term not in get_executables():
-                term = 'x-terminal-emulator'
-            if term not in get_executables():
-                term = 'xterm'
+            term = get_term()
             if isinstance(action, str):
                 action = term + ' -e ' + action
             else:
diff --git a/ranger/ext/get_executables.py b/ranger/ext/get_executables.py
index ee988e49..f2a31345 100644
--- a/ranger/ext/get_executables.py
+++ b/ranger/ext/get_executables.py
@@ -4,6 +4,7 @@
 from stat import S_IXOTH, S_IFREG
 from ranger.ext.iter_tools import unique
 from os import listdir, environ, stat
+import shlex
 
 
 _cached_executables = None
@@ -44,3 +45,16 @@ def get_executables_uncached(*paths):
             if filestat.st_mode & (S_IXOTH | S_IFREG):
                 executables.add(item)
     return executables
+
+
+def get_term():
+    """Get the user terminal executable name.
+
+    Either $TERMCMD, $TERM, "x-terminal-emulator" or "xterm", in this order.
+    """
+    command = environ.get('TERMCMD', environ.get('TERM'))
+    if shlex.split(command)[0] not in get_executables():
+        command = 'x-terminal-emulator'
+        if command not in get_executables():
+            command = 'xterm'
+    return command
1' href='#n291'>291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517