diff options
author | toonn <toonn@toonn.io> | 2018-06-23 22:57:23 +0200 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2018-06-23 23:31:17 +0200 |
commit | 5def08ab1aa0231f174f1090fb26ddab20387a64 (patch) | |
tree | f8cc885aa57d89778b2b76aebef3397f6a6440ad | |
parent | 2bb4c49acd42058378da59cc8d580f9aab1a9f6f (diff) | |
download | ranger-5def08ab1aa0231f174f1090fb26ddab20387a64.tar.gz |
Change rifle fallback mechanism for flag t
Rifle used to just fall back to using `xterm` when `flag t` was used and `TERMCMD` didn't yield a valid command or the terminal emulator couldn't be determined from the `TERM` variable. Now when the need to fallback occurs rifle uses its own rules with a custom mime type i.e. `ranger/x-terminal-emulator`. This way we can provide a default sequence from rarer to more common terminal emulators and users can change the fallback by editing `rifle.conf` Fixes #1108
-rw-r--r-- | ranger/config/rifle.conf | 28 | ||||
-rwxr-xr-x | ranger/ext/rifle.py | 35 |
2 files changed, 54 insertions, 9 deletions
diff --git a/ranger/config/rifle.conf b/ranger/config/rifle.conf index b1a9bb71..83254a87 100644 --- a/ranger/config/rifle.conf +++ b/ranger/config/rifle.conf @@ -211,6 +211,34 @@ ext rar, has unrar = unrar l "$1" | less ext rar, has unrar = for file in "$@"; do unrar x "$file"; done #------------------------------------------- +# Flag t fallback terminals +#------------------------------------------- +# Rarely installed terminal emulators get higher priority; It is assumed that +# if you install a rare terminal emulator, you probably use it. +# gnome-terminal/konsole/xterm on the other hand are often installed as part of +# a desktop environment or as fallback terminal emulators. +mime ^ranger/x-terminal-emulator, has terminology = terminology -e "$@" +mime ^ranger/x-terminal-emulator, has kitty = kitty -- "$@" +mime ^ranger/x-terminal-emulator, has alacritty = alacritty -e "$@" +mime ^ranger/x-terminal-emulator, has sakura = sakura -e "$@" +mime ^ranger/x-terminal-emulator, has lilyterm = lilyterm -e "$@" +#mime ^ranger/x-terminal-emulator, has cool-retro-term = cool-retro-term -e "$@" +mime ^ranger/x-terminal-emulator, has termite = termite -x '"$@"' +#mime ^ranger/x-terminal-emulator, has yakuake = yakuake -e "$@" +mime ^ranger/x-terminal-emulator, has guake = guake -ne "$@" +mime ^ranger/x-terminal-emulator, has tilda = tilda -c "$@" +mime ^ranger/x-terminal-emulator, has st = st -e "$@" +mime ^ranger/x-terminal-emulator, has terminator = terminator -x "$@" +mime ^ranger/x-terminal-emulator, has urxvt = urxvt -e "$@" +mime ^ranger/x-terminal-emulator, has pantheon-terminal = pantheon-terminal -e "$@" +mime ^ranger/x-terminal-emulator, has lxterminal = lxterminal -e "$@" +mime ^ranger/x-terminal-emulator, has mate-terminal = mate-terminal -x "$@" +mime ^ranger/x-terminal-emulator, has xfce4-terminal = xfce4-terminal -x "$@" +mime ^ranger/x-terminal-emulator, has konsole = konsole -e "$@" +mime ^ranger/x-terminal-emulator, has gnome-terminal = gnome-terminal -- "$@" +mime ^ranger/x-terminal-emulator, has xterm = xterm -e "$@" + +#------------------------------------------- # Misc #------------------------------------------- label wallpaper, number 11, mime ^image, has feh, X = feh --bg-scale "$1" diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index 650b8796..6106656e 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -365,11 +365,19 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes if 't' in flags: term = os.environ.get('TERMCMD', os.environ['TERM']) - # Handle aliases of xterm and urxvt, rxvt. + # Handle aliases of xterm and urxvt, rxvt and st and + # termite # Match 'xterm', 'xterm-256color' - if term.startswith('xterm'): + if term in ['xterm', 'xterm-256color']: term = 'xterm' - if term in ['urxvt', 'rxvt-unicode']: + if term in ['xterm-kitty']: + term = 'kitty' + if term in ['xterm-termite']: + term = 'termite' + if term in ['st', 'st-256color']: + term = 'st' + if term in ['urxvt', 'rxvt-unicode', + 'rxvt-unicode-256color']: term = 'urxvt' if term in ['rxvt', 'rxvt-256color']: if 'rxvt' in get_executables(): @@ -378,20 +386,27 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes term = 'urxvt' if term not in get_executables(): - self.hook_logger("Can not determine terminal command. " - "Please set $TERMCMD manually.") - # A fallback terminal that is likely installed: - term = 'xterm' + self.hook_logger("Can not determine terminal command, " + "using rifle to determine fallback. " + "Please set $TERMCMD manually or " + "change fallbacks in rifle.conf.") + self._mimetype = 'ranger/x-terminal-emulator' + self.execute( + files=[command.split(';')[1].split('--')[0].strip()] + + files, flags='f', + mimetype='ranger/x-terminal-emulator') + return None # Choose correct cmdflag accordingly - if term in ['xfce4-terminal', 'mate-terminal', 'terminator']: + if term in ['xfce4-terminal', 'mate-terminal', + 'terminator']: cmdflag = '-x' elif term in ['xterm', 'urxvt', 'rxvt', 'lxterminal', 'konsole', 'lilyterm', 'cool-retro-term', 'terminology', 'pantheon-terminal', 'termite', 'st', 'stterm']: cmdflag = '-e' - elif term in ['gnome-terminal', ]: + elif term in ['gnome-terminal', 'kitty']: cmdflag = '--' elif term in ['tilda', ]: cmdflag = '-c' @@ -409,6 +424,8 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes app = command.split(';')[1].split('--')[0].strip() cmd = [os.environ['TERMCMD'], cmdflag, '%s %s' % (app, target)] + elif term in ['guake']: + cmd = [os.environ['TERMCMD'], '-n', '${PWD}', cmdflag] + cmd else: cmd = [os.environ['TERMCMD'], cmdflag] + cmd |