Ranger: Rifle flag t only works with urxvt

Created on 11 Mar 2018  Â·  5Comments  Â·  Source: ranger/ranger

Rifle's flag t only works with urxvt (because who cares about standards?).
Urxvt passes any arguments after -e verbatim, most other terminals consume them as arguments.
Some terminals use -e, others use -x.

Most helpful comment

Starting a command in a new terminal

Summary

| Terminal Emulator | Status | Cmdflag | TERM | Unique Properties |
|:-----------------:|:------------------:|:-------:|:----------------:|:-----------------:|
| alacritty | :+1: | -e | xterm-256color | :sob: |
| cool-retro-term | :-1: | -e | xterm | COLORSCHEMES_DIR, KB_LAYOUT_DIR |
| gnome-terminal | :+1: | -- | xterm-256color | GNOME_TERMINAL_SCREEN, GNOME_TERMINAL_SERVICE |
| guake | :+1: | -n -e | xterm-256color | GDK_BACKEND, GUAKE_TAB_UUID |
| iTerm.app | :no_entry_sign: | applescript | xterm-256color | ITERM_PROFILE, ITERM_SESSION_ID, TERM_PROGRAM=iTerm.app, __CF_USER_TEXT_ENCODING |
| kitty/kitty.app | :four_leaf_clover: | -- | xterm-kitty | KITTY_WINDOW_ID, TERM=xterm-kitty, TERMINFO |
| konsole | :+1: | -e | xterm-256color | KONSOLE_DBUS_WINDOW |
| lilyterm | :+1: | -e | xterm | :sob: |
| Linux console TTY | :-1: | N/A | linux | INVOCATION_ID, JOURNAL_STREAM, TERM=linux |
| lxterminal | :+1: | -e | xterm-256color | :sob: |
| mate-terminal | :+1: | -x | xterm | :sob: |
| mlterm | :+1: | -e | xterm | MLTERM |
| pantheon-terminal | :+1: | -e | xterm | PANTHEON_TERMINAL_ID, PROMPT_COMMAND |
| roxterm | :+1: | -e | xterm | ROXTERM_ID, ROXTERM_NUM, ROXTERM_PID |
| sakura | :+1: | -e | xterm-256color | :sob: |
| screen | :-1: | `|screen|STY,TERMCAP,WINDOW| | st/stterm | :four_leaf_clover: |--|st-256color|TERM=st-256color| | Terminal.app | :no_entry_sign: | applescript |xterm-256color|TERM_PROGRAM=Apple_Terminal| | terminator | :-1: |-x|xterm-256color|TERMINATOR_DBUS_NAME,TERMINATOR_DBUS_PATH,TERMINATOR_UUID| | terminology | :four_leaf_clover: |-e|xterm|TERMINOLOGY=1| | termite | :four_leaf_clover: |-e|xterm-termite|TERM=xterm-termite| | tilda | :+1: |-c|xterm-256color| :sob: | | tilix | :+1: |-e|xterm-256color|TILIX_ID| | tmux | :-1: |new-window,split-window -h/v|screen|TMUX,TMUX_PANE| | urxvt | :four_leaf_clover: |-e|rxvt-unicode-256color|TERM=rxvt-unicode-256color| | xfce4-terminal | :+1: |-x|xterm-256color| :sob: | | xterm | :four_leaf_clover: |-e|xterm|XTERM_LOCALE,XTERM_SHELL,XTERM_VERSION| | yakuake | :no_entry_sign: | dbus |xterm-256color` | :sob: |

| Legend | |
|:------------------:|:--------------------------------------|
| :four_leaf_clover: | Works ootb. |
| :+1: | Works as TERMCMD. |
| :-1: | Works on in cli but not as TERMCMD. |
| :no_entry_sign: | Doesn't work (yet). |
| :sob: | No unique identifiers. |

Terminals by flag

`-c`
tilda
`-e`
alacritty, cool-retro-term, konsole, lilyterm, lxterminal, mate-terminal, mlterm, pantheon-terminal, roxterm, sakura, terminator, terminology, termite, tilix, urxvt, xfce4-terminal, xterm
`-n combined with -e`
guake
`-x`
lilyterm, mate-terminal, sakura, terminator, xfce4-terminal
`--command`
alacritty, lxterminal, mate-terminal, terminator, tilda
`--command=`
lxterminal, tilix, xfce4-terminal
`--exec`
terminology
`--exec=`
termite
`--execute`
lilyterm, mate-terminal, roxterm, sakura, terminator, xfce4-terminal
`--execute=`
pantheon-terminal
`--xterm-execute`
sakura
`--`
gnome-terminal, kitty, st
other
Yakuake *requires* dbus messages to do most anything, guake *can* be controlled with dbus but offers simple command line options too. Mac os is even worse in this regard: Terminal.app, iTerm2.

Detecting Terminal Emulator

Detecting which terminal emulator is running, so we can open a window of the same terminal emulator is fraught with issues. Currently rifle first looks whether TERMCMD is set and if it is assumes that's the terminal the user wants opened. If it isn't set it tries to determine the terminal used from TERM and other more specific variables as summarized in the next section. If neither of these result in a program that can be found on the PATH rifle will use customizable rules from rifle.conf (for mime type ranger/x-terminal-emulator).

These rules are by default inversely ordered by the approximate popularity of the terminals, reasoning that you probably only have a rare terminal installed if you use it. You can easily change which terminal ranger falls back to in this case by reordering or changing these rules.

References

For alacritty:

-e, --command <command>...
Command and args to execute (must be last argument)

For cool-retro-term:

-e <cmd>
Command to execute. This option will catch all following arguments, so use it as the last option.

Cool-retro-term doesn't seem to work with space seperated arguments even when enclosed in single quotes.

For gnome-terminal:

-e, --command=STRING ! deprecated, use -- to terminate the options and put the command line to execute after it
Execute the argument to this option inside the terminal.
-x, --execute ! deprecated, use -- to terminate the options and put the command line to execute after it
Execute the remainder of the command line inside the terminal.

For guake:

-e COMMAND, --execute-command=COMMAND
Execute an arbitrary command in the selected tab.
-n NEW_TAB, --new-tab=NEW_TAB
Add a new tab (with current directory set to NEW_TAB)

With guake you need the new tab because otherwise the current tab is used, which effectively doesn't open a "new window" even though in guake's terminology new windows seem to be restricted to new tabs.

For kitty/kitty.app:

kitty [options] [program-to-run ...]

So you can just provide the command as arguments, probably good to use it with -- like gnome-terminal so the command isn't interpreted as flags to kitty.

For konsole:

-e command
Execute command instead of the normal shell.

For lilyterm:

-e COMMAND | -x COMMAND | --execute COMMAND
Run a command when starting up. Must be the final option.

For lxterminal:

-e STRING --command=STRING --command STRING
This option specifies the program (and its command line arguments) to be run in the terminal. Except in the --command= form, this must be the last option on the command line.

For mate-terminal:

-e, --command
Execute the argument to this option inside the terminal
-x, --execute
Execute the remainder of the command line inside the terminal

For mlterm:

-e program [ arguments ... ]
Invoke the command in the mlterm window. This option must be the last option on the command line.

For pantheon-terminal:

-e, --execute=PATH
Execute the specified binary in terminal

For ROXterm:

-e --execute
Execute remainder of command line inside the terminal. Must be the final option.

For sakura:

-x, --execute
Execute command
-e, --xterm-execute
Execute command (compatible with xterm's -e option)

Not sure what the difference is between the options so let's use -e because it's more common.

For screen:

Command: screen [opts] [n] [cmd [args] | //group]
Establish a new window. The flow-control options (‘-f’, ‘-fn’ and ‘-fa’), title option (‘-t’), login options (‘-l’ and ‘-ln’) , terminal type option (‘-T term’), the all-capability-flag (‘-a’) and scrollback option (‘-h num’) may be specified with each command. The option (‘-M’) turns monitoring on for this window. The option (‘-L’) turns output logging on for this window. If an optional number n in the range 0…MAXWIN-1 is given, the window number n is assigned to the newly created window (or, if this number is already in-use, the next available number). If a command is specified after screen, this command (with the given arguments) is started in the window; otherwise, a shell is created. If ‘//group’ is supplied, a container-type window is created in which other windows may be created inside it. See Window Groups.

Simply calling screen <cmd> will open a new window with the command.

For st/stterm:

-e program [ arguments ... ]
executes program instead of the shell. If this is used it must be the last option on the command line, as in xterm / rxvt. This option is only intended for compability, and all the remaining arguments are used as a command even without it.

For terminator:

-e, --command
Runs the specified command instead of your default shell or profile specified command"
-x, --execute
"Runs the rest of the command line instead of your default shell or profile specified command.

For terminology:

-e, --exec <cmnd>
Specify command to execute. Defaults to $SHELL (or passwd shell or /bin/sh) When used along with -S/--split, each argument is used as a command for a split, leaving away the extra arguments. With 3 splits, one vertical, a command on the right, an horizontal split on the left with only a command on the bottom, the following arguments should be used: --split v-h-- -e command1 $SHELL command2

For termite:

-e, --exec=COMMAND
Tell termite start COMMAND instead of the shell.

Termite requires the COMMAND to be one string so 'less textfile.txt' needs the single quotes. If you need single quotes inside the single quotes you need to escape them like this ' -> '"'"', for example less 'file with spaces.txt' -> 'less '"'"'file with spaces.txt'"'"''.

For tilda:

-c, --command
Run a command at startup

For tilix:

-e --command=COMMAND
Execute all text after this parameter as a command, thus this parameter must be the last parameter.

For tmux:

tmux new-window [-adkP] [-n window-name] [-t target-window] [shell-command]
(alias: neww) Create a new window. With -a, the new window is inserted at the next index up from the specified target-window, moving windows up if necessary, otherwise target-window is the new window location.

If -d is given, the session does not make the new window the current window. target-window represents the window to be created; if the target already exists an error is shown, unless the -k flag is used, in which case it is destroyed. shell-command is the command to execute. If shell-command is not specified, the value of the default-command option is used.

When the shell command completes, the window closes. See the remain-on-exit option to change this behaviour.

The TERM environment variable must be set to ''screen'' for all programs running inside tmux. New windows will automatically have ''TERM=screen'' added to their environment, but care must be taken not to reset this in shell start-up files.

The -P option prints the location of the new window after it has been created.

tmux split-window [-dhvP] [-l size | -p percentage] [-t target-pane] [shell-command]
(alias: splitw) Create a new pane by splitting target-pane: -h does a horizontal split and -v a vertical split; if neither is specified, -v is assumed. The -l and -p options specify the size of the new pane in lines (for vertical split) or in cells (for horizontal split), or as a percentage, respectively. All other options have the same meaning as for the new-window command.

For urxvt:

-e command [arguments]
Run the command with its command-line arguments in the urxvt window; also sets the window title and icon name to be the basename of the program being executed if neither -title (-T) nor -n are given on the command line. If this option is used, it must be the last on the command-line. If there is no -e option then the default is to run the program specified by the SHELL environment variable or, failing that, sh(1).

Please note that you must specify a program with arguments. If you want to run shell commands, you have to specify the shell, like this:

urxvt -e sh -c "shell commands"

For xfce4-terminal:

−x, −−execute
Execute the remainder of the command line inside the terminal
−e, −−command=command
Execute command inside the terminal

For xterm:

-e program [ arguments ... ]
This option specifies the program (and its command line arguments) to be run in the xterm window. It also sets the window title and icon name to be the basename of the program being executed if neither -T nor -n are given on the command line. This must be the last option on the command line.

For yakuake:

?

Seems to require dbus messaging.

All 5 comments

Starting a command in a new terminal

Summary

| Terminal Emulator | Status | Cmdflag | TERM | Unique Properties |
|:-----------------:|:------------------:|:-------:|:----------------:|:-----------------:|
| alacritty | :+1: | -e | xterm-256color | :sob: |
| cool-retro-term | :-1: | -e | xterm | COLORSCHEMES_DIR, KB_LAYOUT_DIR |
| gnome-terminal | :+1: | -- | xterm-256color | GNOME_TERMINAL_SCREEN, GNOME_TERMINAL_SERVICE |
| guake | :+1: | -n -e | xterm-256color | GDK_BACKEND, GUAKE_TAB_UUID |
| iTerm.app | :no_entry_sign: | applescript | xterm-256color | ITERM_PROFILE, ITERM_SESSION_ID, TERM_PROGRAM=iTerm.app, __CF_USER_TEXT_ENCODING |
| kitty/kitty.app | :four_leaf_clover: | -- | xterm-kitty | KITTY_WINDOW_ID, TERM=xterm-kitty, TERMINFO |
| konsole | :+1: | -e | xterm-256color | KONSOLE_DBUS_WINDOW |
| lilyterm | :+1: | -e | xterm | :sob: |
| Linux console TTY | :-1: | N/A | linux | INVOCATION_ID, JOURNAL_STREAM, TERM=linux |
| lxterminal | :+1: | -e | xterm-256color | :sob: |
| mate-terminal | :+1: | -x | xterm | :sob: |
| mlterm | :+1: | -e | xterm | MLTERM |
| pantheon-terminal | :+1: | -e | xterm | PANTHEON_TERMINAL_ID, PROMPT_COMMAND |
| roxterm | :+1: | -e | xterm | ROXTERM_ID, ROXTERM_NUM, ROXTERM_PID |
| sakura | :+1: | -e | xterm-256color | :sob: |
| screen | :-1: | `|screen|STY,TERMCAP,WINDOW| | st/stterm | :four_leaf_clover: |--|st-256color|TERM=st-256color| | Terminal.app | :no_entry_sign: | applescript |xterm-256color|TERM_PROGRAM=Apple_Terminal| | terminator | :-1: |-x|xterm-256color|TERMINATOR_DBUS_NAME,TERMINATOR_DBUS_PATH,TERMINATOR_UUID| | terminology | :four_leaf_clover: |-e|xterm|TERMINOLOGY=1| | termite | :four_leaf_clover: |-e|xterm-termite|TERM=xterm-termite| | tilda | :+1: |-c|xterm-256color| :sob: | | tilix | :+1: |-e|xterm-256color|TILIX_ID| | tmux | :-1: |new-window,split-window -h/v|screen|TMUX,TMUX_PANE| | urxvt | :four_leaf_clover: |-e|rxvt-unicode-256color|TERM=rxvt-unicode-256color| | xfce4-terminal | :+1: |-x|xterm-256color| :sob: | | xterm | :four_leaf_clover: |-e|xterm|XTERM_LOCALE,XTERM_SHELL,XTERM_VERSION| | yakuake | :no_entry_sign: | dbus |xterm-256color` | :sob: |

| Legend | |
|:------------------:|:--------------------------------------|
| :four_leaf_clover: | Works ootb. |
| :+1: | Works as TERMCMD. |
| :-1: | Works on in cli but not as TERMCMD. |
| :no_entry_sign: | Doesn't work (yet). |
| :sob: | No unique identifiers. |

Terminals by flag

`-c`
tilda
`-e`
alacritty, cool-retro-term, konsole, lilyterm, lxterminal, mate-terminal, mlterm, pantheon-terminal, roxterm, sakura, terminator, terminology, termite, tilix, urxvt, xfce4-terminal, xterm
`-n combined with -e`
guake
`-x`
lilyterm, mate-terminal, sakura, terminator, xfce4-terminal
`--command`
alacritty, lxterminal, mate-terminal, terminator, tilda
`--command=`
lxterminal, tilix, xfce4-terminal
`--exec`
terminology
`--exec=`
termite
`--execute`
lilyterm, mate-terminal, roxterm, sakura, terminator, xfce4-terminal
`--execute=`
pantheon-terminal
`--xterm-execute`
sakura
`--`
gnome-terminal, kitty, st
other
Yakuake *requires* dbus messages to do most anything, guake *can* be controlled with dbus but offers simple command line options too. Mac os is even worse in this regard: Terminal.app, iTerm2.

Detecting Terminal Emulator

Detecting which terminal emulator is running, so we can open a window of the same terminal emulator is fraught with issues. Currently rifle first looks whether TERMCMD is set and if it is assumes that's the terminal the user wants opened. If it isn't set it tries to determine the terminal used from TERM and other more specific variables as summarized in the next section. If neither of these result in a program that can be found on the PATH rifle will use customizable rules from rifle.conf (for mime type ranger/x-terminal-emulator).

These rules are by default inversely ordered by the approximate popularity of the terminals, reasoning that you probably only have a rare terminal installed if you use it. You can easily change which terminal ranger falls back to in this case by reordering or changing these rules.

References

For alacritty:

-e, --command <command>...
Command and args to execute (must be last argument)

For cool-retro-term:

-e <cmd>
Command to execute. This option will catch all following arguments, so use it as the last option.

Cool-retro-term doesn't seem to work with space seperated arguments even when enclosed in single quotes.

For gnome-terminal:

-e, --command=STRING ! deprecated, use -- to terminate the options and put the command line to execute after it
Execute the argument to this option inside the terminal.
-x, --execute ! deprecated, use -- to terminate the options and put the command line to execute after it
Execute the remainder of the command line inside the terminal.

For guake:

-e COMMAND, --execute-command=COMMAND
Execute an arbitrary command in the selected tab.
-n NEW_TAB, --new-tab=NEW_TAB
Add a new tab (with current directory set to NEW_TAB)

With guake you need the new tab because otherwise the current tab is used, which effectively doesn't open a "new window" even though in guake's terminology new windows seem to be restricted to new tabs.

For kitty/kitty.app:

kitty [options] [program-to-run ...]

So you can just provide the command as arguments, probably good to use it with -- like gnome-terminal so the command isn't interpreted as flags to kitty.

For konsole:

-e command
Execute command instead of the normal shell.

For lilyterm:

-e COMMAND | -x COMMAND | --execute COMMAND
Run a command when starting up. Must be the final option.

For lxterminal:

-e STRING --command=STRING --command STRING
This option specifies the program (and its command line arguments) to be run in the terminal. Except in the --command= form, this must be the last option on the command line.

For mate-terminal:

-e, --command
Execute the argument to this option inside the terminal
-x, --execute
Execute the remainder of the command line inside the terminal

For mlterm:

-e program [ arguments ... ]
Invoke the command in the mlterm window. This option must be the last option on the command line.

For pantheon-terminal:

-e, --execute=PATH
Execute the specified binary in terminal

For ROXterm:

-e --execute
Execute remainder of command line inside the terminal. Must be the final option.

For sakura:

-x, --execute
Execute command
-e, --xterm-execute
Execute command (compatible with xterm's -e option)

Not sure what the difference is between the options so let's use -e because it's more common.

For screen:

Command: screen [opts] [n] [cmd [args] | //group]
Establish a new window. The flow-control options (‘-f’, ‘-fn’ and ‘-fa’), title option (‘-t’), login options (‘-l’ and ‘-ln’) , terminal type option (‘-T term’), the all-capability-flag (‘-a’) and scrollback option (‘-h num’) may be specified with each command. The option (‘-M’) turns monitoring on for this window. The option (‘-L’) turns output logging on for this window. If an optional number n in the range 0…MAXWIN-1 is given, the window number n is assigned to the newly created window (or, if this number is already in-use, the next available number). If a command is specified after screen, this command (with the given arguments) is started in the window; otherwise, a shell is created. If ‘//group’ is supplied, a container-type window is created in which other windows may be created inside it. See Window Groups.

Simply calling screen <cmd> will open a new window with the command.

For st/stterm:

-e program [ arguments ... ]
executes program instead of the shell. If this is used it must be the last option on the command line, as in xterm / rxvt. This option is only intended for compability, and all the remaining arguments are used as a command even without it.

For terminator:

-e, --command
Runs the specified command instead of your default shell or profile specified command"
-x, --execute
"Runs the rest of the command line instead of your default shell or profile specified command.

For terminology:

-e, --exec <cmnd>
Specify command to execute. Defaults to $SHELL (or passwd shell or /bin/sh) When used along with -S/--split, each argument is used as a command for a split, leaving away the extra arguments. With 3 splits, one vertical, a command on the right, an horizontal split on the left with only a command on the bottom, the following arguments should be used: --split v-h-- -e command1 $SHELL command2

For termite:

-e, --exec=COMMAND
Tell termite start COMMAND instead of the shell.

Termite requires the COMMAND to be one string so 'less textfile.txt' needs the single quotes. If you need single quotes inside the single quotes you need to escape them like this ' -> '"'"', for example less 'file with spaces.txt' -> 'less '"'"'file with spaces.txt'"'"''.

For tilda:

-c, --command
Run a command at startup

For tilix:

-e --command=COMMAND
Execute all text after this parameter as a command, thus this parameter must be the last parameter.

For tmux:

tmux new-window [-adkP] [-n window-name] [-t target-window] [shell-command]
(alias: neww) Create a new window. With -a, the new window is inserted at the next index up from the specified target-window, moving windows up if necessary, otherwise target-window is the new window location.

If -d is given, the session does not make the new window the current window. target-window represents the window to be created; if the target already exists an error is shown, unless the -k flag is used, in which case it is destroyed. shell-command is the command to execute. If shell-command is not specified, the value of the default-command option is used.

When the shell command completes, the window closes. See the remain-on-exit option to change this behaviour.

The TERM environment variable must be set to ''screen'' for all programs running inside tmux. New windows will automatically have ''TERM=screen'' added to their environment, but care must be taken not to reset this in shell start-up files.

The -P option prints the location of the new window after it has been created.

tmux split-window [-dhvP] [-l size | -p percentage] [-t target-pane] [shell-command]
(alias: splitw) Create a new pane by splitting target-pane: -h does a horizontal split and -v a vertical split; if neither is specified, -v is assumed. The -l and -p options specify the size of the new pane in lines (for vertical split) or in cells (for horizontal split), or as a percentage, respectively. All other options have the same meaning as for the new-window command.

For urxvt:

-e command [arguments]
Run the command with its command-line arguments in the urxvt window; also sets the window title and icon name to be the basename of the program being executed if neither -title (-T) nor -n are given on the command line. If this option is used, it must be the last on the command-line. If there is no -e option then the default is to run the program specified by the SHELL environment variable or, failing that, sh(1).

Please note that you must specify a program with arguments. If you want to run shell commands, you have to specify the shell, like this:

urxvt -e sh -c "shell commands"

For xfce4-terminal:

−x, −−execute
Execute the remainder of the command line inside the terminal
−e, −−command=command
Execute command inside the terminal

For xterm:

-e program [ arguments ... ]
This option specifies the program (and its command line arguments) to be run in the xterm window. It also sets the window title and icon name to be the basename of the program being executed if neither -T nor -n are given on the command line. This must be the last option on the command line.

For yakuake:

?

Seems to require dbus messaging.

The problem still persists for Termite. The command needs to be all one string, as your Summary indicates. It's being passed as an array.

Wait. I'm wrong. But it's still broken for me. I'll investigate.

Alright I have no idea what's going on. Pretty frustrating though.
I'm glad this issue is being looked into, since it was getting annoying to run a manual patch every time there was an update!

You're right. I didn't actually take it into account in the code and probably did it wrong in rifle.conf too. I could've sworn I tested this with termite though.

Anyone have any updates on this? It's super frustrating

Not really. I still want to fix this before the next release but it may slip another tbh.

Was this page helpful?
0 / 5 - 0 ratings