个人工具

UbuntuHelp:DefaultFileManager

来自Ubuntu中文

跳转至: 导航, 搜索

Default File Manager in Gnome

Introduction

The default file manager in Ubuntu is Nautilus. Some people prefer other file managers. Unfortunately, it's difficult to make other file managers the default, especially since Nautilus manages the desktop icons in Gnome (Ubuntu's desktop environment).

Disclaimer

The first version of this script has been written by a non-programmer. It has been tested and works but, as you can see from the comments in the script, it could still be tweaked to be "better."

Script to change Thunar to be the default file manager

To run this script, paste this block of code into a text file and save it as a file named defaultthunar in your home folder.

#!/bin/bash


makethunardefault()
{
echo -e "\nMaking sure Thunar is installed\n"
sudo apt-get update && sudo apt-get install thunar --no-install-recommends

echo -e "\nChanging to application launcher directory\n"
cd /usr/share/applications
echo -e "\nMaking backup directory\n"

sudo mkdir nonautilusplease
echo -e "\nModifying folder handler launcher\n"
sudo cp nautilus-folder-handler.desktop nonautilusplease/

sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-folder-handler.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-folder-handler.desktop
echo -e "\nModifying browser launcher\n"
sudo cp nautilus-browser.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop --browser/thunar/g' nautilus-browser.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-browser.desktop
echo -e "\nModifying computer icon launcher\n"
sudo cp nautilus-computer.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-computer.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-computer.desktop
echo -e "\nModifying home icon launcher\n"
sudo cp nautilus-home.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-home.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-home.desktop
echo -e "\nModifying general Nautilus launcher\n"
sudo cp nautilus.desktop nonautilusplease/
sudo sed -i -n 's/Exec=nautilus/Exec=thunar/g' nautilus.desktop

echo -e "\nChanging base Nautilus launcher\n"
sudo dpkg-divert --divert /usr/bin/nautilus.old --rename /usr/bin/nautilus && sudo ln -s /usr/bin/thunar /usr/bin/nautilus 
echo -e "\nRemoving Nautilus as desktop manager\n"
killall nautilus
echo -e "\nThunar is now the default file manager. To return Nautilus to the default, run this script again.\n"
}

restorenautilusdefault()
{
echo -e "\nChanging to application launcher directory\n"
cd /usr/share/applications
echo -e "\nRestoring backup files\n"
sudo cp nonautilusplease/nautilus-folder-handler.desktop .
sudo cp nonautilusplease/nautilus-browser.desktop .
sudo cp nonautilusplease/nautilus-computer.desktop .
sudo cp nonautilusplease/nautilus-home.desktop .
sudo cp nonautilusplease/nautilus.desktop .
echo -e "\nRemoving backup folder\n"
sudo rm -r nonautilusplease
echo -e "\nRestoring Nautilus launcher\n"
sudo rm /usr/bin/nautilus && sudo dpkg-divert --rename --remove /usr/bin/nautilus
echo -e "\nMaking Nautilus manage the desktop again\n"
nautilus --no-default-window &

}



set -o errexit
trap 'echo "Previous command did not complete successfully. Exiting."' ERR


if [[ -e /usr/share/applications/nonautilusplease ]]; then 

restorenautilusdefault 

else

makethunardefault

fi;

Then paste these commands into the|terminal

chmod +x defaultthunar
./defaultthunar

Restoring Nautilus as a default

Just run the script again

./defaultthunar

Script to change Dolphin to be the default file manager

To do later when the Thunar script has been improved upon

Alternative method

Same thing can be done adding the new .desktop files to ~/.local/share/applications/ instead of modifying the installation files in /usr/share/applications.

Using Midnight Commander

First copy this script to /usr/local/bin/mcterm

#!/usr/bin/env python
# mcterm 1.0
# Daniel Gonzalez Gasull <[email protected]>
# License: GPL
#
# Handles packages with Midnight Commander.  
# Opens a gnome-terminal with Midnight Commander in it.
# mcterm can be used inside Firefox in Edit -> Preferences -> Aplications
# with zip files, bz2 files, rar files and 7z files.
import os
import subprocess
import sys


def main():
    if len(sys.argv) > 1:
        filename = sys.argv[1]
        file_output, dummy = subprocess.Popen('/usr/bin/file -b %s' % filename,
                shell=True, stdout=subprocess.PIPE).communicate()
        filetype = file_output.strip().split()[0]
        # switch statement
        try:
            dirname = {
                    'Zip': lambda: '%s#uzip' % filename,
                    'gzip': lambda: '%s#utar' % filename,
                    '7-zip': lambda: '%s#u7z' % filename,
                    'RAR': lambda: '%s#urar' % filename,
                    'bzip2': lambda: '%s#utar' % filename,
                    }[filetype]()
        except KeyError:
            dirname = filename
    else:
        dirname = ''
    os.system('gnome-terminal --hide-menubar -x mc -s %s' % dirname)


if __name__ == "__main__":
    main()

Give yourself permission to execute the script:

sudo chmod 755 /usr/local/bin/mcterm

Now copy this file to ~/.local/share/applications/nautilus-browser.desktop

[Desktop Entry]
Encoding=UTF-8
Name=File Browser
Comment=Browse the file system with the file manager
TryExec=mcterm
Exec=mcterm %U
Icon=system-file-manager
Terminal=false
StartupNotify=true
Type=Application
NoDisplay=true
Categories=GNOME;GTK;System;Utility;Core;
OnlyShowIn=GNOME;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=nautilus
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=2.28.1
X-Ubuntu-Gettext-Domain=nautilus

This other file to ~/.local/share/applications/nautilus-folder-handler.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=Open Folder
TryExec=mcterm
Exec=mcterm %U
NoDisplay=true
Terminal=false
Icon=folder-open
StartupNotify=true
Type=Application
MimeType=x-directory/gnome-default-handler;x-directory/normal;inode/directory;application/x-gnome-saved-search;
OnlyShowIn=GNOME;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=nautilus
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=2.28.1
X-Ubuntu-Gettext-Domain=nautilus

And this last file to ~/.local/share/applications/nautilus-home.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=Home Folder
Comment=Open your personal folder
TryExec=mcterm
Exec=mcterm
Icon=user-home
Terminal=false
StartupNotify=true
Type=Application
Categories=GNOME;GTK;Core;
OnlyShowIn=GNOME;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=nautilus
X-GNOME-Bugzilla-Component=general
X-Ubuntu-Gettext-Domain=nautilus