Ranger: Conditional configs; how to use if else blocks in config files?

Created on 25 May 2017  路  5Comments  路  Source: ranger/ranger

Just a quick question. I couldn't find another issue about that. As I mentioned on the title how to specify a config as conditional form. For example, I want to use different column_ratios in my Android device.

So, I need to execute uname and load it correct config according to the its result.

Most helpful comment

A quick and dirty try:

eval import subprocess; fm.set_option_from_string("viewmode", "multipane") if subprocess.check_output(["uname", "-o"]) != "Android" else None

Consider using a different config on Android, for example by using some preprocessing. See:

Feel free to reuse my preprocessor (you may want to add some facts).

All 5 comments

Although it's not reliable, I did this as workaround in my shell configs. I could have set the --cmd to column_ratios.

.zshrc

if ([[ $(uname -o) == 'Android' ]] 2>/dev/null) {
    alias ranger="ranger --cmd='set viewmode multipane'"
}

You could use eval for it. rc.conf by itself doesn't support any conditionals.

Could you please show me an example? I don't know Python that much. :(

A quick and dirty try:

eval import subprocess; fm.set_option_from_string("viewmode", "multipane") if subprocess.check_output(["uname", "-o"]) != "Android" else None

Consider using a different config on Android, for example by using some preprocessing. See:

Feel free to reuse my preprocessor (you may want to add some facts).

Nice preprocessor for general use cases but I always use latest versions of programs I use, so doing like so is kind of useless for me. I have no intention to support earlier versions of one program, like you did to tmux. Although, tmux has if-shell component I don't know if you know or not; it's not so syntax-beauty though.

Thanks for eval snippet also, it helped a lot.

I guess I should close the issue because seems like I can make conditional configs via eval.

Was this page helpful?
0 / 5 - 0 ratings