Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to set file association in Ranger

📅 2015-Mar-12 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ file association, ranger ⬩ 📚 Archive

File association is used to determine what program to use to open a file. All the file associations for Ranger can be found in ~/.config/ranger/rifle.conf file. This file is well documented and should answer most of your queries. Note that the file is read from top to bottom and the rule that matches first is chosen and applied.

In Ranger, you can choose a program to open a file based on its extension. For example, to open a JPEG file with Feh image viewer, add this line at the top of rifle.conf:

ext jpg = feh "$@"

After the specific file associations, I like to have a rule to catch all the rest of the files and open them using xdg-open:

has xdg-open, flag f = xdg-open "$1"

For more info on configuring Ranger, refer to the excellent documentation by Arch here.

Tried with: Ranger 1.6.1 and Ubuntu 14.04

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧