ext.img_display: moved code to generate input to separate function
[ranger.git] / ranger.py
blobd2e90ae74ba4654982da268a2d37ed56eaf3950a
1 #!/usr/bin/python -O
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.
12 """":
13 tempfile='/tmp/chosendir'
14 ranger="${1:-ranger}"
15 test -z "$1" || shift
16 "$ranger" --choosedir="$tempfile" "${@:-$(pwd)}"
17 returnvalue=$?
18 test -f "$tempfile" &&
19 if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
20 cd "$(cat "$tempfile")"
21 rm -f -- "$tempfile"
23 return $returnvalue
24 """ and None
26 import sys
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('.'))
38 # Start ranger
39 import ranger
40 sys.exit(ranger.main())