summary refs log tree commit diff stats
path: root/ranger.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-11 22:34:21 +0200
committerhut <hut@lavabit.com>2011-10-11 22:34:21 +0200
commit30a35e6a7b95a06709590dc56afb96ea7ccecb62 (patch)
treec44a71f9502dd08e5f1917ceb0f0f33fe3efe57f /ranger.py
parent6524d00c5ce0d1169645a879fe581ee29d91b33c (diff)
parent6f695ffeafd1d2f1cb7c0c201b395582a1f7ce4e (diff)
downloadranger-30a35e6a7b95a06709590dc56afb96ea7ccecb62.tar.gz
Merge branch 'master' into stable
Conflicts:
	ranger/defaults/options.py
Diffstat (limited to 'ranger.py')
-rwxr-xr-xranger.py55
1 files changed, 24 insertions, 31 deletions
diff --git a/ranger.py b/ranger.py
index 53fd8bdb..c763a8d9 100755
--- a/ranger.py
+++ b/ranger.py
@@ -1,8 +1,6 @@
 #!/usr/bin/python -O
-# -*- coding: utf-8 -*-
-#
-# Ranger: Explore your forest of files from inside your terminal
-# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
+# ranger - a vim-inspired file manager for the console  (coding: utf-8)
+# Copyright (C) 2009, 2010, 2011  Roman Zimbelmann <romanz@lavabit.com>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,42 +15,37 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# 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
+# =====================
+# This embedded bash script can be executed by sourcing this file.
+# It will cd to ranger's last location after you exit it.
+# The first argument specifies the command to run ranger, the
+# default is simply "ranger". (Not this file itself!)
+# The other arguments are passed to ranger.
 """":
-if [ ! -z "$1" ]; then
-	$@ --fail-unless-cd &&
-	if [ -z "$XDG_CONFIG_HOME" ]; then
-		cd "$(grep \^\' ~/.config/ranger/bookmarks | cut -b3-)"
-	else
-		cd "$(grep \^\' "$XDG_CONFIG_HOME"/ranger/bookmarks | cut -b3-)"
-	fi && return 0
-else
-	echo "usage: source path/to/ranger.py path/to/ranger.py"
+tempfile='/tmp/chosendir'
+ranger="${1:-ranger}"
+test -z "$1" || shift
+"$ranger" --choosedir="$tempfile" "${@:-$(pwd)}"
+returnvalue=$?
+test -f "$tempfile" &&
+if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
+	cd "$(cat "$tempfile")"
+	rm -f -- "$tempfile"
 fi
-return 1
-"""
+return $returnvalue
+""" and None
 
 import sys
-import os.path
+from os.path import exists, abspath
 
 # Need to find out whether or not the flag --clean was used ASAP,
 # because --clean is supposed to disable bytecode compilation
-try:
-	argv = sys.argv[0:sys.argv.index('--')]
-except:
-	argv = sys.argv
+argv = sys.argv[1:sys.argv.index('--')] if '--' in sys.argv else sys.argv[1:]
 sys.dont_write_bytecode = '-c' in argv or '--clean' in argv
 
-# Set the actual docstring
-__doc__ = """Ranger - file browser for the unix terminal"""
-
-# Don't import ./ranger when running an installed binary at /usr/bin/ranger
-if os.path.exists('ranger') and '/' in os.path.normpath(__file__):
-	try:
-		sys.path.remove(os.path.abspath('.'))
-	except:
-		pass
+# Don't import ./ranger when running an installed binary at /usr/.../ranger
+if __file__[:4] == '/usr' and exists('ranger') and abspath('.') in sys.path:
+	sys.path.remove(abspath('.'))
 
 # Start ranger
 import ranger