diff options
Diffstat (limited to 'ranger.py')
-rwxr-xr-x | ranger.py | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/ranger.py b/ranger.py index 5652ba69..240b3687 100755 --- a/ranger.py +++ b/ranger.py @@ -1,5 +1,5 @@ #!/usr/bin/python -O -# coding=utf-8 +# -*- coding: utf-8 -*- # # Ranger: Explore your forest of files from inside your terminal # Copyright (C) 2009, 2010 Roman Zimbelmann <romanz@lavabit.com> @@ -16,18 +16,17 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# ---------------------------------------------------------------------------- -# -# An embedded shell script. It allows you to change the directory -# after you exit ranger by starting it with: source ranger ranger + +# Embed a script which allows you to change the directory of the parent shell +# after you exit ranger. Run it with the command: source ranger ranger """": -if [ $1 ]; then +if [ ! -z "$1" ]; then + $@ --fail-unless-cd && if [ -z "$XDG_CONFIG_HOME" ]; then - "$@" --fail-unless-cd && cd "$(grep \^\' ~/.config/ranger/bookmarks | cut -b3-)" + cd "$(grep \^\' ~/.config/ranger/bookmarks | cut -b3-)" else - "$@" --fail-unless-cd && cd "$(grep \^\' "$XDG_CONFIG_HOME"/ranger/bookmarks | cut -b3-)" - fi + cd "$(grep \^\' "$XDG_CONFIG_HOME"/ranger/bookmarks | cut -b3-)" + fi && return 0 else echo "usage: source path/to/ranger.py path/to/ranger.py" fi @@ -36,21 +35,17 @@ return 1 import sys -# Redefine the docstring, since the previous one was hijacked to -# embed a shellscript. +# When using the --clean option, not even bytecode should be written. +# Thus, we need to find out if --clean is used as soon as possible. +try: + argv = sys.argv[0:sys.argv.index('--')] +except: + argv = sys.argv +sys.dont_write_bytecode = '-c' in argv or '--clean' in argv + +# Set the actual docstring __doc__ = """Ranger - file browser for the unix terminal""" -# Importing the main method may fail if the ranger directory -# is neither in the same directory as this file, nor in one of -# pythons global import paths. -try: - from ranger.__main__ import main -except ImportError: - if '-d' not in sys.argv and '--debug' not in sys.argv: - print("Can't import the main module.") - print("To run an uninstalled copy of ranger,") - print("launch ranger.py in the top directory.") - else: - raise -else: - sys.exit(main()) +# Start ranger +import ranger +sys.exit(ranger.main()) |