Есть ли способ перенаправить определенные URL-адреса в определенные веб-браузеры в Linux?

1173
jraxxo

Я использую Chrome в качестве браузера по умолчанию в Ubuntu 12.10. Мне нужно использовать Firefox для деловых целей (некоторые сайты, относящиеся к моей работе, работают только с Firefox). Есть ли способ заставить Ubuntu использовать Firefox для определенных типов URL-адресов (может быть, как это определено регулярным выражением), сохраняя при этом Chrome в качестве браузера по умолчанию для всех других моих задач? Возможно, как сценарий оболочки работает в фоновом режиме? Я хотел бы, чтобы это работало в масштабе всей системы, включая ссылки на сам Chrome, а также файлы PDF / ODT и т. Д.

Я искал решения, но не смог найти ничего, кроме OpenWith, расширения Firefox, которое добавляет кнопку для открытия определенных ссылок в других браузерах, что снова потребовало бы от меня открытия Firefox заранее, что мне совсем не помогает.

У кого-нибудь есть какие-либо идеи? Что-то вроде Choosy для Linux?

3
Связанный: http://superuser.com/questions/198179/always-open-specific-domains-in-a-different-browser-from-firefox?rq=1 Ƭᴇcʜιᴇ007 10 лет назад 1
Ну, я использую Linux, так что это не так актуально ... jraxxo 10 лет назад 0

1 ответ на вопрос

5
hololeap

The executable in Linux that opens a resource with your "favorite" program is called xdg-open. It is somewhat complicated, but you can add additional rules using xdg-mime install. However, I don't know if you can even do this for something like a specific URL.

This becomes further complicated in that specific desktop environments use different executables and methods for opening their default programs. For instance KDE has kde-open, but not every KDE application seems to use this.

Regardless, I got this partially working just using a shell script and a list of domains/URLs in a file. You can tweak it to your liking.

Note: You may need to repeat this process for other executables depending on your desktop environment. For example, Gnome has gvfs-open, KDE has kde-open, and XFCE has exo-open. (Even then, it might not work for every application.)

Note: The shell script is dependent on pcregrep being installed on your system.

  1. Find the xdg-open executable

    which xdg-open 
  2. Create a new directory in your home folder

    mkdir -p ~/.local/bin 
  3. Add the following to your ~/.bashrc file

    ~/.bashrc

    export PATH="$/.local/bin:$" 
  4. Create the shell script in the newly created folder. (Be sure to edit the top four variables so they are correct for your system!)

    ~/.local/bin/xdg-open

    #!/bin/bash DOMAIN_LIST_FILE=~/'domains.txt' OTHER_BROWSER='/path/to/other-browser' # For instance /usr/bin/firefox BROWSER_OPTIONS='' # Optional, for command line options passed to browser XDG_OPEN='/path/to/xdg-open' if echo "$1" | pcregrep -q '^https?://'; then matching=0 while read domain; do if echo "$1" | pcregrep -q "^https?://$"; then matching=1 break fi done < "$DOMAIN_LIST_FILE" if [[ $matching -eq 1 ]]; then "$OTHER_BROWSER" $BROWSER_OPTIONS ${*} exit 0 fi fi "$XDG_OPEN" ${*} 
  5. Create the list of domains in your home folder

    ~/domains.txt

    stackexchange.com stackoverflow.com superuser.com 
  6. Log out and log back in to have the settings take effect

замените `pcregrep -q '^ https?: //'` на `grep -q '^ http \?: \ / \ /'`, если у вас нет pcregrep (что бы это ни было :)) Boris Churzin 7 лет назад 1