2 # ranger - a vim-inspired file manager for the console (coding: utf-8)
3 # Copyright (C) 2009, 2010, 2011 Roman Zimbelmann <romanz@lavabit.com>
4 # This software is distributed under the terms of the GNU GPL version 3.
6 # =====================
7 # This embedded bash script can be executed by sourcing this file.
8 # It will cd to ranger's last location after you exit it.
9 # The first argument specifies the command to run ranger, the
10 # default is simply "ranger". (Not this file itself!)
11 # The other arguments are passed to ranger.
13 tempfile='/tmp/chosendir'
16 "$ranger" --choosedir="$tempfile" "${@:-$(pwd)}"
18 test -f "$tempfile" &&
19 if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
20 cd "$(cat "$tempfile")"
27 from os
.path
import exists
, abspath
29 # Need to find out whether or not the flag --clean was used ASAP,
30 # because --clean is supposed to disable bytecode compilation
31 argv
= sys
.argv
[1:sys
.argv
.index('--')] if '--' in sys
.argv
else sys
.argv
[1:]
32 sys
.dont_write_bytecode
= '-c' in argv
or '--clean' in argv
34 # Don't import ./ranger when running an installed binary at /usr/.../ranger
35 if __file__
[:4] == '/usr' and exists('ranger') and abspath('.') in sys
.path
:
36 sys
.path
.remove(abspath('.'))
40 sys
.exit(ranger
.main())