summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-04 02:24:52 +0200
committerhut <hut@lavabit.com>2011-10-04 02:24:52 +0200
commit06848dc3f83e940cf26342a5b6dfeb31c88e1f06 (patch)
tree04e9cda25aae00095a4e35ac951513e23e143cb5
parentd40d1cf901a914430190068e6d8f56e0eb29107d (diff)
downloadranger-06848dc3f83e940cf26342a5b6dfeb31c88e1f06.tar.gz
ranger.py: made the argument optional in embedded bash script
-rwxr-xr-xranger.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/ranger.py b/ranger.py
index 44fc298f..2a9c68a0 100755
--- a/ranger.py
+++ b/ranger.py
@@ -15,23 +15,24 @@
 # 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
-	tempfile='/tmp/chosendir'
-	ranger="$1"
-	shift
-	"$ranger" --choosedir="$tempfile" "${@:-$(pwd)}"
-	test -f "$tempfile" &&
-	if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
-		cd "$(cat "$tempfile")"
-		rm -f -- "$tempfile"
-	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
 """
 
 import sys