From 06848dc3f83e940cf26342a5b6dfeb31c88e1f06 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 4 Oct 2011 02:24:52 +0200 Subject: ranger.py: made the argument optional in embedded bash script --- ranger.py | 31 ++++++++++++++++--------------- 1 file 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 . -# 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 -- cgit 1.4.1-2-gfad0