aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-25 21:59:51 +0100
committerhut <hut@lavabit.com>2009-12-25 21:59:51 +0100
commit5c210a96a0e4bb74cd096edb045fc3814b78450c (patch)
tree511c54091badbc91c71a7d76759d642648c9ce82
parente7f81766920a47bf4b126108a25ce92885682bc2 (diff)
downloadranger-5c210a96a0e4bb74cd096edb045fc3814b78450c.tar.gz
random updates
-rwxr-xr-xmake_doc.py2
-rwxr-xr-xranger.py19
-rw-r--r--ranger/__init__.py6
-rw-r--r--ranger/actions.py4
-rw-r--r--ranger/applications.py18
-rw-r--r--ranger/defaults/keys.py2
-rw-r--r--ranger/fm.py1
7 files changed, 45 insertions, 7 deletions
diff --git a/make_doc.py b/make_doc.py
index 9616ef11..a5c022c9 100755
--- a/make_doc.py
+++ b/make_doc.py
@@ -5,7 +5,7 @@ store important content there."""
import pydoc, os, sys
if __name__ == '__main__':
- docdir = 'doc'
+ docdir = 'doc/pydoc'
os.chdir(sys.path[0])
try: os.mkdir(docdir)
except: pass
diff --git a/ranger.py b/ranger.py
index 2e380581..64ea365e 100755
--- a/ranger.py
+++ b/ranger.py
@@ -1,25 +1,38 @@
#!/usr/bin/python -OO
# coding=utf-8
# ranger: Browse your files inside the terminal.
-
+# -----------------------------------------------------------------------------
# An embedded shell script. Assuming this file is /usr/bin/ranger,
# this hack allows you to use the cd-after-exit feature by typing:
-# source ranger ranger
+# source ranger ranger
# Now when you quit ranger, it should change the directory of the
# parent shell to where you have last been in ranger.
# Works with at least bash and zsh.
+#
+# A convenient way of using this feature is adding this line to your bashrc:
+# alias rn='source ranger ranger'
+# or, if ranger is not installed properly:
+# alias rn='source /path/to/ranger.py /path/to/ranger.py'
"""":
if [ $1 ]; then
- cd "`$1 --cd-after-exit $@ 3>&1 1>&2 2>&3 3>&-`"
+ RANGER="$1"
+ shift
+ cd "`$RANGER --cd-after-exit \"$@\" 3>&1 1>&2 2>&3 3>&-`"
else
echo "usage: source path/to/ranger.py path/to/ranger.py"
fi
return 1
"""
+# Redefine the docstring, since the previous one was hijacked to
+# embed a shellscript.
__doc__ = """Ranger - file browser for the unix terminal"""
+
+# Importing of the main method may fail if the ranger directory
+# neither is in the same directory as this file, nor in one of
+# pythons global import paths.
try:
from ranger import main
diff --git a/ranger/__init__.py b/ranger/__init__.py
index b934d80c..5eaaee4f 100644
--- a/ranger/__init__.py
+++ b/ranger/__init__.py
@@ -56,10 +56,9 @@ def main():
args, rest = parser.parse_args()
+ log(sys.argv)
if args.cd_after_exit:
sys.stderr = sys.__stdout__
- if rest[0] == sys.argv[0]:
- del rest[0]
# Initialize objects
target = ' '.join(rest)
@@ -81,7 +80,8 @@ def main():
try:
my_ui = UI()
- my_fm = FM(ui = my_ui)
+ my_fm = FM(ui=my_ui)
+ my_fm.stderr_to_out = args.cd_after_exit
# Run the file manager
my_fm.initialize()
diff --git a/ranger/actions.py b/ranger/actions.py
index a43d366f..b9ec2204 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -164,6 +164,10 @@ class Actions(EnvironmentAware, SettingsAware):
if func is not None:
self.env.settings['sort'] = str(func)
+ def spawn(self, command):
+ from ranger.applications import spawn
+ spawn(command, fm=self)
+
def force_load_preview(self):
cf = self.env.cf
if cf is not None:
diff --git a/ranger/applications.py b/ranger/applications.py
index a046a839..c9f2ec18 100644
--- a/ranger/applications.py
+++ b/ranger/applications.py
@@ -60,3 +60,21 @@ def run(*args, **kw):
waitpid_no_intr(p.pid)
if fm.ui: fm.ui.initialize()
return p
+
+def spawn(command, fm=None, suspend=True, wait=True):
+ from subprocess import Popen, STDOUT
+ from ranger.ext.waitpid_no_intr import waitpid_no_intr
+
+ if suspend and fm and fm.ui:
+ fm.ui.suspend()
+
+ try:
+ if fm and fm.stderr_to_out:
+ process = Popen(command, shell=True, stderr=STDOUT)
+ else:
+ process = Popen(command, shell=True)
+ if wait:
+ waitpid_no_intr(process.pid)
+ finally:
+ if suspend and fm and fm.ui:
+ fm.ui.initialize()
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 683214f7..9fbc5b96 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -42,6 +42,8 @@ def initialize_commands(command_list):
bind('cut', do('cut'))
bind('p', do('paste'))
+ bind('s', do('spawn', 'bash'))
+
t_hint = "show_//h//idden //p//review_files //d//irectories_first //a//uto_load_preview //c//ollapse_preview"
command_list.hint(t_hint, 't')
bind('th', do('toggle_boolean_option', 'show_hidden'))
diff --git a/ranger/fm.py b/ranger/fm.py
index a1b1339a..a68c0f15 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -12,6 +12,7 @@ TICKS_BEFORE_COLLECTING_GARBAGE = 100
class FM(Actions):
input_blocked = False
input_blocked_until = 0
+ stderr_to_out = False
def __init__(self, ui = None, bookmarks = None):
"""Initialize FM."""
Actions.__init__(self)