summary refs log tree commit diff stats
path: root/ranger.py
blob: 53fd8bdb352d675b91e3951a10f3f2bcc3d6ab15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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>
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# 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
"""":
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"
fi
return 1
"""

import sys
import os.path

# 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
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

# Start ranger
import ranger
sys.exit(ranger.main())
tructions in the INSTALL file for installing ranger. After starting ranger, you should see 4 columns. The third one is the main column, the directory where you're currently at. To the left you see the parent directories and to the right there's a preview of the object you're pointing at. Now use the Arrow Keys to navigate, Enter to open a file or type Q to quit. To customize ranger, copy the files from ranger/defaults/ to ~/.config/ranger/ and modify them according to your wishes. Combine Ranger With Other Applications -------------------------------------- 1. bash: Add this to your ~/.bashrc to use ranger as a directory switcher: function ranger-cd { ranger --choosedir=/tmp/chosen if [ -f /tmp/chosen -a "$(cat /tmp/chosen)" != "$(pwd | tr -d "\n")" ]; then cd "$(cat /tmp/chosen)" fi rm -f /tmp/chosen } bind '"\C-o":"ranger-cd\C-m"' Now when you run ranger-cd, browse and quit, the directory of the bash process you started ranger in will change to the last directroy in ranger. To change back to the previous directory, you can type: cd - Also, the line with "bind" will map the key <CTRL-O> to start ranger. 2. vim: Add this function to your ~/.vimrc: fun Ranger() silent !ranger --choosefile=/tmp/chosen if filereadable('/tmp/chosen') exec 'edit ' . system('cat /tmp/chosen') call system('rm /tmp/chosen') endif redraw! endfun map <leader>r :call Ranger() This starts ranger when you type <leader>r (usually \r) and if you open a file in ranger it will be opened in the original vim process. Troubleshooting, Getting Help ----------------------------- If you encounter an error, try running ranger with --debug. This will sometimes display more detailed information about the error. Also, try deactivating optimization: PYTHONOPTIMIZE="" ranger --debug Report bugs on savannah: (please include as much information as possible) http://savannah.nongnu.org/bugs/?func=additem&group=ranger Ask questions on the mailing list: http://lists.nongnu.org/mailman/listinfo/ranger-users Further Reading --------------- Check the man page for information on common features and hotkeys. The most detailed manual is accessible by pressing "?" from inside ranger. It is also available at ranger/help/, contained in the *.py files. The file ranger/defaults/keys.py contains all key combinations, so that's another place you may want to check out.