From d92c4af3688e01836a87b7684228d9327a828c7e Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 8 Oct 2011 22:51:42 +0200 Subject: mv ranger/data/config_examples/* ranger/data/ --- ranger/core/fm.py | 8 +-- ranger/data/apps.py | 102 +++++++++++++++++++++++++++++++ ranger/data/commands.py | 103 ++++++++++++++++++++++++++++++++ ranger/data/config_examples/apps.py | 102 ------------------------------- ranger/data/config_examples/commands.py | 103 -------------------------------- ranger/data/config_examples/options.py | 103 -------------------------------- ranger/data/config_examples/rc.conf | 60 ------------------- ranger/data/options.py | 103 ++++++++++++++++++++++++++++++++ ranger/data/rc.conf | 60 +++++++++++++++++++ 9 files changed, 372 insertions(+), 372 deletions(-) create mode 100644 ranger/data/apps.py create mode 100644 ranger/data/commands.py delete mode 100644 ranger/data/config_examples/apps.py delete mode 100644 ranger/data/config_examples/commands.py delete mode 100644 ranger/data/config_examples/options.py delete mode 100644 ranger/data/config_examples/rc.conf create mode 100644 ranger/data/options.py create mode 100644 ranger/data/rc.conf (limited to 'ranger') diff --git a/ranger/core/fm.py b/ranger/core/fm.py index f68942bd..f51a7834 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -126,10 +126,10 @@ class FM(Actions, SignalDispatcher): if ranger.arg.clean: return import shutil - files = {'data/config_examples/apps.py': 'apps.py', - 'data/config_examples/rc.conf': 'rc.conf', - 'data/config_examples/commands.py': 'commands.py', - 'data/config_examples/options.py': 'options.py', + files = {'data/apps.py': 'apps.py', + 'data/rc.conf': 'rc.conf', + 'data/commands.py': 'commands.py', + 'data/options.py': 'options.py', 'data/scope.sh': 'scope.sh'} copied_any = False for fname, target in files.items(): diff --git a/ranger/data/apps.py b/ranger/data/apps.py new file mode 100644 index 00000000..2bb7e9cd --- /dev/null +++ b/ranger/data/apps.py @@ -0,0 +1,102 @@ +# =================================================================== +# This is the configuration file for file type detection and application +# handling. It's all in python; lines beginning with # are comments. +# +# Scroll down for a few examples. +# =================================================================== +# This system is based on things called MODES and FLAGS. You can read +# in the man page about them. To remind you, here's a list of all flags. +# An uppercase flag inverts previous flags of the same name. +# s Silent mode. Output will be discarded. +# d Detach the process. (Run in background) +# p Redirect output to the pager +# w Wait for an Enter-press when the process is done +# c Run the current file only, instead of the selection +# +# To implement flags in this file, you could do this: +# context.flags += "d" +# Another example: +# context.flags += "Dw" +# +# To implement modes in this file, you can do something like: +# if context.mode == 1: +# +# elif context.mode == 2: +# +# =================================================================== +# The methods are called with a "context" object which provides some +# attributes that transfer information. Relevant attributes are: +# +# mode -- a number, mainly used in determining the action in app_xyz() +# flags -- a string with flags which change the way programs are run +# files -- a list containing files, mainly used in app_xyz +# filepaths -- a list of the paths of each file +# file -- an arbitrary file from that list (or None) +# fm -- the filemanager instance +# popen_kws -- keyword arguments which are directly passed to Popen +# =================================================================== +# The return value of the functions should be either: +# 1. A reference to another app, like: +# return self.app_editor(context) +# +# 2. A call to the "either" method, which uses the first program that +# is installed on your system. If none are installed, None is returned. +# return self.either(context, "libreoffice", "soffice", "ooffice") +# +# 3. A tuple of arguments that should be run. +# return "mplayer", "-fs", context.file.path +# If you use lists instead of strings, they will be flattened: +# args = ["-fs", "-shuf"] +# return "mplayer", args, context.filepaths +# "context.filepaths" can, and will often be abbreviated with just "context": +# return "mplayer", context +# =================================================================== + +# Import the basics +from ranger.defaults.apps import CustomApplications as DefaultApps +from ranger.api.apps import * + +# +# Here, the class "CustomApplications" is defined as a subclass of the default +# application handler class. It is located at ranger/defaults/apps.py and +# contains a whole lot of definitions. The reason why we don't put them here +# is that when you update, this file doesn't change. +class CustomApplications(DefaultApps): + # By default, this just inherits all methods from DefaultApps + pass + +# def app_kaffeine(self, context): +# return 'kaffeine', context +# +# def app_feh_fullscreen_by_default(self, context): +# return 'feh', '-F', context +# +# # app_default is the function that is always called to determine which +# # application to run, unless you specify one manually with :open_with +# def app_default(self, context): +# f = context.file #shortcut +# if f.video or f.audio: +# return self.app_kaffeine(context) +# +# if f.image and context.mode == 0: +# return self.app_feh_fullscreen_by_default(context) +# +# return DefaultApps.app_default(self, context) +# +# # You could write this to use an entirely different program to open files: +# def app_default(self, context): +# return "mimeopen", context + + +## Often a programs invocation is trivial. For example: +## vim test.py readme.txt [...] +## This could be implemented like: +## @depends_on("vim") +## def app_vim(self, context): +## return "vim", context +## Instead of creating such a generic function for each program, just add +## its name here and it will be automatically done for you. +#CustomApplications.generic('zsnes', 'javac') + +## By setting flags='d', this programs will not block ranger's terminal: +#CustomApplications.generic('gimp', 'evince', flags='d') diff --git a/ranger/data/commands.py b/ranger/data/commands.py new file mode 100644 index 00000000..03178354 --- /dev/null +++ b/ranger/data/commands.py @@ -0,0 +1,103 @@ +# =================================================================== +# This configuration file contains custom commands. It's all in python; +# lines beginning with # are comments. +# +# Scroll down for a few examples. +# +# Every class defined here which is a subclass of `Command' will be used as a +# command in ranger. Several methods are defined to interface with ranger: +# execute(): called when the command is executed. +# cancel(): called when closing the console. +# tab(): called when is pressed. +# quick(): called after each keypress. +# +# The return values for tab() can be either: +# None: There is no tab completion +# A string: Change the console to this string +# A list/tuple/generator: cycle through every item in it +# +# The return value for quick() can be: +# False: Nothing happens +# True: Execute the command afterwards +# +# The return value for execute() and cancel() doesn't matter. +# +# =================================================================== +# Commands have certain attributes and methods that facilitate parsing of +# the arguments: +# +# self.line: The whole line that was written in the console. +# self.args: A list of all (space-separated) arguments to the command. +# self.quantifier: If this command was mapped to the key "X" and +# the user pressed 6X, self.quantifier will be 6. +# self.arg(n): The n-th argument, or an empty string if it doesn't exist. +# self.rest(n): The n-th argument plus everything that followed. For example, +# If the command was "search foo bar a b c", rest(2) will be "bar a b c" +# self.start(n): The n-th argument and anything before it. For example, +# If the command was "search foo bar a b c", rest(2) will be "bar a b c" +# +# =================================================================== +# And this is a little reference for common ranger functions and objects: +# +# self.fm: A reference to the "fm" object which contains most information +# about ranger. +# self.fm.notify(string): Print the given string on the screen. +# self.fm.notify(string, bad=True): Print the given string in RED. +# self.fm.reload_cwd(): Reload the current working directory. +# self.fm.env.cwd: The current working directory. (A File object.) +# self.fm.env.cf: The current file. (A File object too.) +# self.fm.env.cwd.get_selection(): A list of all selected files. +# self.fm.execute_console(string): Execute the string as a ranger command. +# self.fm.open_console(string): Open the console with the given string +# already typed in for you. +# self.fm.move(direction): Moves the cursor in the given direction, which +# can be something like down=3, up=5, right=1, left=1, to=6, ... +# +# File objects (for example self.fm.env.cf) have these useful attributes and +# methods: +# +# cf.path: The path to the file. +# cf.basename: The base name only. +# cf.load_content(): Force a loading of the directories content (which +# obviously works with directories only) +# cf.is_directory: True/False depending on whether it's a directory. +# +# For advanced commands it is unavoidable to dive a bit into the source code +# of ranger. +# =================================================================== +# Here are some example commands: + +from ranger.api.commands import * + +#class tabnew(Command): +# def execute(self): +# self.fm.tab_new() + +#class tabgo(Command): +# """ Go to the n-th tab. """ +# def execute(self): +# num = self.line.split()[1] +# self.fm.tab_open(int(num)) + +#class terminal(Command): +# """ +# :terminal +# +# Spawns an "x-terminal-emulator" starting in the current directory. +# """ +# def execute(self): +# self.fm.run('x-terminal-emulator', flags='d') + +#class edit(Command): +# def execute(self): +# if not self.arg(1): +# self.fm.edit_file(self.fm.env.cf.path) +# else: +# self.fm.edit_file(self.rest(1)) +# +# def tab(self): +# return self._tab_directory_content() + +#class incremental_search(Command): +# def quick(self): +# self.fm.search_file(self.rest(1), regexp=True, offset=0) diff --git a/ranger/data/config_examples/apps.py b/ranger/data/config_examples/apps.py deleted file mode 100644 index 2bb7e9cd..00000000 --- a/ranger/data/config_examples/apps.py +++ /dev/null @@ -1,102 +0,0 @@ -# =================================================================== -# This is the configuration file for file type detection and application -# handling. It's all in python; lines beginning with # are comments. -# -# Scroll down for a few examples. -# =================================================================== -# This system is based on things called MODES and FLAGS. You can read -# in the man page about them. To remind you, here's a list of all flags. -# An uppercase flag inverts previous flags of the same name. -# s Silent mode. Output will be discarded. -# d Detach the process. (Run in background) -# p Redirect output to the pager -# w Wait for an Enter-press when the process is done -# c Run the current file only, instead of the selection -# -# To implement flags in this file, you could do this: -# context.flags += "d" -# Another example: -# context.flags += "Dw" -# -# To implement modes in this file, you can do something like: -# if context.mode == 1: -# -# elif context.mode == 2: -# -# =================================================================== -# The methods are called with a "context" object which provides some -# attributes that transfer information. Relevant attributes are: -# -# mode -- a number, mainly used in determining the action in app_xyz() -# flags -- a string with flags which change the way programs are run -# files -- a list containing files, mainly used in app_xyz -# filepaths -- a list of the paths of each file -# file -- an arbitrary file from that list (or None) -# fm -- the filemanager instance -# popen_kws -- keyword arguments which are directly passed to Popen -# =================================================================== -# The return value of the functions should be either: -# 1. A reference to another app, like: -# return self.app_editor(context) -# -# 2. A call to the "either" method, which uses the first program that -# is installed on your system. If none are installed, None is returned. -# return self.either(context, "libreoffice", "soffice", "ooffice") -# -# 3. A tuple of arguments that should be run. -# return "mplayer", "-fs", context.file.path -# If you use lists instead of strings, they will be flattened: -# args = ["-fs", "-shuf"] -# return "mplayer", args, context.filepaths -# "context.filepaths" can, and will often be abbreviated with just "context": -# return "mplayer", context -# =================================================================== - -# Import the basics -from ranger.defaults.apps import CustomApplications as DefaultApps -from ranger.api.apps import * - -# -# Here, the class "CustomApplications" is defined as a subclass of the default -# application handler class. It is located at ranger/defaults/apps.py and -# contains a whole lot of definitions. The reason why we don't put them here -# is that when you update, this file doesn't change. -class CustomApplications(DefaultApps): - # By default, this just inherits all methods from DefaultApps - pass - -# def app_kaffeine(self, context): -# return 'kaffeine', context -# -# def app_feh_fullscreen_by_default(self, context): -# return 'feh', '-F', context -# -# # app_default is the function that is always called to determine which -# # application to run, unless you specify one manually with :open_with -# def app_default(self, context): -# f = context.file #shortcut -# if f.video or f.audio: -# return self.app_kaffeine(context) -# -# if f.image and context.mode == 0: -# return self.app_feh_fullscreen_by_default(context) -# -# return DefaultApps.app_default(self, context) -# -# # You could write this to use an entirely different program to open files: -# def app_default(self, context): -# return "mimeopen", context - - -## Often a programs invocation is trivial. For example: -## vim test.py readme.txt [...] -## This could be implemented like: -## @depends_on("vim") -## def app_vim(self, context): -## return "vim", context -## Instead of creating such a generic function for each program, just add -## its name here and it will be automatically done for you. -#CustomApplications.generic('zsnes', 'javac') - -## By setting flags='d', this programs will not block ranger's terminal: -#CustomApplications.generic('gimp', 'evince', flags='d') diff --git a/ranger/data/config_examples/commands.py b/ranger/data/config_examples/commands.py deleted file mode 100644 index 03178354..00000000 --- a/ranger/data/config_examples/commands.py +++ /dev/null @@ -1,103 +0,0 @@ -# =================================================================== -# This configuration file contains custom commands. It's all in python; -# lines beginning with # are comments. -# -# Scroll down for a few examples. -# -# Every class defined here which is a subclass of `Command' will be used as a -# command in ranger. Several methods are defined to interface with ranger: -# execute(): called when the command is executed. -# cancel(): called when closing the console. -# tab(): called when is pressed. -# quick(): called after each keypress. -# -# The return values for tab() can be either: -# None: There is no tab completion -# A string: Change the console to this string -# A list/tuple/generator: cycle through every item in it -# -# The return value for quick() can be: -# False: Nothing happens -# True: Execute the command afterwards -# -# The return value for execute() and cancel() doesn't matter. -# -# =================================================================== -# Commands have certain attributes and methods that facilitate parsing of -# the arguments: -# -# self.line: The whole line that was written in the console. -# self.args: A list of all (space-separated) arguments to the command. -# self.quantifier: If this command was mapped to the key "X" and -# the user pressed 6X, self.quantifier will be 6. -# self.arg(n): The n-th argument, or an empty string if it doesn't exist. -# self.rest(n): The n-th argument plus everything that followed. For example, -# If the command was "search foo bar a b c", rest(2) will be "bar a b c" -# self.start(n): The n-th argument and anything before it. For example, -# If the command was "search foo bar a b c", rest(2) will be "bar a b c" -# -# =================================================================== -# And this is a little reference for common ranger functions and objects: -# -# self.fm: A reference to the "fm" object which contains most information -# about ranger. -# self.fm.notify(string): Print the given string on the screen. -# self.fm.notify(string, bad=True): Print the given string in RED. -# self.fm.reload_cwd(): Reload the current working directory. -# self.fm.env.cwd: The current working directory. (A File object.) -# self.fm.env.cf: The current file. (A File object too.) -# self.fm.env.cwd.get_selection(): A list of all selected files. -# self.fm.execute_console(string): Execute the string as a ranger command. -# self.fm.open_console(string): Open the console with the given string -# already typed in for you. -# self.fm.move(direction): Moves the cursor in the given direction, which -# can be something like down=3, up=5, right=1, left=1, to=6, ... -# -# File objects (for example self.fm.env.cf) have these useful attributes and -# methods: -# -# cf.path: The path to the file. -# cf.basename: The base name only. -# cf.load_content(): Force a loading of the directories content (which -# obviously works with directories only) -# cf.is_directory: True/False depending on whether it's a directory. -# -# For advanced commands it is unavoidable to dive a bit into the source code -# of ranger. -# =================================================================== -# Here are some example commands: - -from ranger.api.commands import * - -#class tabnew(Command): -# def execute(self): -# self.fm.tab_new() - -#class tabgo(Command): -# """ Go to the n-th tab. """ -# def execute(self): -# num = self.line.split()[1] -# self.fm.tab_open(int(num)) - -#class terminal(Command): -# """ -# :terminal -# -# Spawns an "x-terminal-emulator" starting in the current directory. -# """ -# def execute(self): -# self.fm.run('x-terminal-emulator', flags='d') - -#class edit(Command): -# def execute(self): -# if not self.arg(1): -# self.fm.edit_file(self.fm.env.cf.path) -# else: -# self.fm.edit_file(self.rest(1)) -# -# def tab(self): -# return self._tab_directory_content() - -#class incremental_search(Command): -# def quick(self): -# self.fm.search_file(self.rest(1), regexp=True, offset=0) diff --git a/ranger/data/config_examples/options.py b/ranger/data/config_examples/options.py deleted file mode 100644 index 6a0a3bc4..00000000 --- a/ranger/data/config_examples/options.py +++ /dev/null @@ -1,103 +0,0 @@ -# =================================================================== -# This is the main configuration file of ranger. It consists of python -# code, but fear not, you don't need any python knowledge for changing -# the settings. -# -# Lines beginning with # are comments. To enable a line, remove the #. -# -# Here are the most important settings. Refer to the man page for -# a list and descriptions of all settings. -# =================================================================== - -# This line imports some basic variables -from ranger.api.options import * - -# ranger can use a customizable external script for previews. The included -# default script prints previews of archives, html/pdf documents and even -# images. This is, however, disabled by default for performance reasons. Turn -# it on by uncommenting this line: -#use_preview_script = True - -# This changes the location of the preview script -#preview_script = "~/.config/ranger/scope.sh" - -# Use a simple character-wise sort algorithm instead of the default natural -# sorting. This is faster, although the difference is hardly noticeable. -#sort = "basename" - -# Use a unicode "..." symbol when filenames are truncated. This is disabled -# by default since some systems don't support unicode+curses well. -#unicode_ellipsis = True - -# Uncomment these lines to disable previews by default? -#preview_files = False -#preview_directories = False - -# xterm handles the ALT key differently. If you use xterm, uncomment this line -#xterm_alt_key = True - -# Change what files ranger should hide with this setting. Its value is a -# "regular expression". If you don't know about them, there are lots of good -# tutorials on the web! Below is the default value. -#hidden_filter = regexp(r"^\.|\.(?:pyc|pyo|bak|swp)$|^lost\+found$|^__cache__$") - - -# =================================================================== -# Beware: from here on, you are on your own. This part requires python -# knowledge. -# -# Since python is a dynamic language, it gives you the power to replace any -# part of ranger without touching the code. This is commonly referred to as -# Monkey Patching and can be helpful if you, for some reason, don't want to -# modify rangers code directly. Just remember: the more you mess around, the -# more likely it is to break when you switch to another version. Here are some -# practical examples of monkey patching. -# -# Technical information: This file is imported as a python module. If a -# variable has the name of a setting, ranger will attempt to use it to change -# that setting. You can write "del " to avoid that. -# =================================================================== -# Add a new sorting algorithm: Random sort. -# Enable this with :set sort=random - -#from ranger.fsobject.directory import Directory -#from random import random -#Directory.sort_dict['random'] = lambda path: random() - -# =================================================================== -# A function that changes which files are displayed. This is more powerful -# than the hidden_filter setting since this function has more information. - -## Save the original filter function -#import ranger.fsobject.directory -#old_accept_file = ranger.fsobject.directory.accept_file - -## Define a new one -#def accept_file_MOD(fname, mypath, hidden_filter, name_filter): -# if mypath == '/' and fname in ('boot', 'sbin', 'proc', 'sys'): -# return False -# else: -# return old_accept_file(fname, mypath, hidden_filter, name_filter) - -## Overwrite the old function -#import ranger.fsobject.directory -#ranger.fsobject.directory.accept_file = accept_file_MOD - -# =================================================================== -# A function that adds an additional macro. Test this with :shell -p echo %date - -## Save the original macro function -#import ranger.core.actions -#old_get_macros = ranger.core.actions.Actions._get_macros -# -## Define a new macro function -#import time -#def get_macros_MOD(self): -# macros = old_get_macros(self) -# macros['date'] = time.strftime('%m/%d/%Y') -# return macros -# -## Overwrite the old one -#ranger.core.actions.Actions._get_macros = get_macros_MOD - -# =================================================================== diff --git a/ranger/data/config_examples/rc.conf b/ranger/data/config_examples/rc.conf deleted file mode 100644 index 5598d9f1..00000000 --- a/ranger/data/config_examples/rc.conf +++ /dev/null @@ -1,60 +0,0 @@ -# =================================================================== -# This file contains startup commands for ranger. -# -# The purpose of this file is mainly to define keybindings. For -# changing settings or running more complex python code, use the -# configuration file "options.py" or define commands in "commands.py". -# -# Each line is a command that will be run before the user interface -# is initialized. As a result, you can not use commands which rely on -# the UI such as "delete" or "mark". Lines starting with # are comments. -# -# Note: Press 1? in ranger for a list of key bindings and 2? for a list -# of commands. -# =================================================================== -# The "map" command maps a key sequence to a command. "map gt cd /tmp" -# maps the keys "gt" to the command "cd /tmp". "copymap" copies a key -# binding to another key sequence and "unmap" deletes the given key binding. -# -# Here are some examples: - -## go to common directories (this overrides some default keybindings) -#map gt cd /tmp -#map gc cd ~/.config -#map gp cd /usr/portage -#map gb cd /boot - -## Unbind "q" so you don't accidentally close ranger -#unmap q - -## Edit files with the lowercase "e". By default, uppercase "E" is used. -#copymap E e - -## Add a key for searching files with a given string in their name -#map F console shell -p find . | grep -Iir --color - -## Find all files in this directory, shuffle them and view in mplayer -#map M shell find . | shuf | xargs -d \\n mplayer -fs - -## Add some keys to edit configuration files -#map ,r chain shell vim ~/.config/ranger/rc.conf; source_cmdlist ~/.config/ranger/rc.conf -#map ,a shell vim ~/.config/ranger/apps.py -#map ,c shell vim ~/.config/ranger/commands.py -#map ,o shell vim ~/.config/ranger/options.py - -## And some keys to view defaults -#map ,R shell vim %rangerdir/defaults/rc.conf -#map ,A shell vim %rangerdir/defaults/apps.py -#map ,C shell vim %rangerdir/defaults/commands.py -#map ,O shell vim %rangerdir/defaults/options.py -#map ,n shell vim %rangerdir/core/actions.py - -## You might want to scroll up/down with u/d like in a pager -#copymap d D -#copymap u U -#map d move down=0.8 pages=True -#map u move up=0.8 pages=True - -## Or scroll up/down with ^P/^N: -#copymap -#copymap diff --git a/ranger/data/options.py b/ranger/data/options.py new file mode 100644 index 00000000..6a0a3bc4 --- /dev/null +++ b/ranger/data/options.py @@ -0,0 +1,103 @@ +# =================================================================== +# This is the main configuration file of ranger. It consists of python +# code, but fear not, you don't need any python knowledge for changing +# the settings. +# +# Lines beginning with # are comments. To enable a line, remove the #. +# +# Here are the most important settings. Refer to the man page for +# a list and descriptions of all settings. +# =================================================================== + +# This line imports some basic variables +from ranger.api.options import * + +# ranger can use a customizable external script for previews. The included +# default script prints previews of archives, html/pdf documents and even +# images. This is, however, disabled by default for performance reasons. Turn +# it on by uncommenting this line: +#use_preview_script = True + +# This changes the location of the preview script +#preview_script = "~/.config/ranger/scope.sh" + +# Use a simple character-wise sort algorithm instead of the default natural +# sorting. This is faster, although the difference is hardly noticeable. +#sort = "basename" + +# Use a unicode "..." symbol when filenames are truncated. This is disabled +# by default since some systems don't support unicode+curses well. +#unicode_ellipsis = True + +# Uncomment these lines to disable previews by default? +#preview_files = False +#preview_directories = False + +# xterm handles the ALT key differently. If you use xterm, uncomment this line +#xterm_alt_key = True + +# Change what files ranger should hide with this setting. Its value is a +# "regular expression". If you don't know about them, there are lots of good +# tutorials on the web! Below is the default value. +#hidden_filter = regexp(r"^\.|\.(?:pyc|pyo|bak|swp)$|^lost\+found$|^__cache__$") + + +# =================================================================== +# Beware: from here on, you are on your own. This part requires python +# knowledge. +# +# Since python is a dynamic language, it gives you the power to replace any +# part of ranger without touching the code. This is commonly referred to as +# Monkey Patching and can be helpful if you, for some reason, don't want to +# modify rangers code directly. Just remember: the more you mess around, the +# more likely it is to break when you switch to another version. Here are some +# practical examples of monkey patching. +# +# Technical information: This file is imported as a python module. If a +# variable has the name of a setting, ranger will attempt to use it to change +# that setting. You can write "del " to avoid that. +# =================================================================== +# Add a new sorting algorithm: Random sort. +# Enable this with :set sort=random + +#from ranger.fsobject.directory import Directory +#from random import random +#Directory.sort_dict['random'] = lambda path: random() + +# =================================================================== +# A function that changes which files are displayed. This is more powerful +# than the hidden_filter setting since this function has more information. + +## Save the original filter function +#import ranger.fsobject.directory +#old_accept_file = ranger.fsobject.directory.accept_file + +## Define a new one +#def accept_file_MOD(fname, mypath, hidden_filter, name_filter): +# if mypath == '/' and fname in ('boot', 'sbin', 'proc', 'sys'): +# return False +# else: +# return old_accept_file(fname, mypath, hidden_filter, name_filter) + +## Overwrite the old function +#import ranger.fsobject.directory +#ranger.fsobject.directory.accept_file = accept_file_MOD + +# =================================================================== +# A function that adds an additional macro. Test this with :shell -p echo %date + +## Save the original macro function +#import ranger.core.actions +#old_get_macros = ranger.core.actions.Actions._get_macros +# +## Define a new macro function +#import time +#def get_macros_MOD(self): +# macros = old_get_macros(self) +# macros['date'] = time.strftime('%m/%d/%Y') +# return macros +# +## Overwrite the old one +#ranger.core.actions.Actions._get_macros = get_macros_MOD + +# =================================================================== diff --git a/ranger/data/rc.conf b/ranger/data/rc.conf new file mode 100644 index 00000000..5598d9f1 --- /dev/null +++ b/ranger/data/rc.conf @@ -0,0 +1,60 @@ +# =================================================================== +# This file contains startup commands for ranger. +# +# The purpose of this file is mainly to define keybindings. For +# changing settings or running more complex python code, use the +# configuration file "options.py" or define commands in "commands.py". +# +# Each line is a command that will be run before the user interface +# is initialized. As a result, you can not use commands which rely on +# the UI such as "delete" or "mark". Lines starting with # are comments. +# +# Note: Press 1? in ranger for a list of key bindings and 2? for a list +# of commands. +# =================================================================== +# The "map" command maps a key sequence to a command. "map gt cd /tmp" +# maps the keys "gt" to the command "cd /tmp". "copymap" copies a key +# binding to another key sequence and "unmap" deletes the given key binding. +# +# Here are some examples: + +## go to common directories (this overrides some default keybindings) +#map gt cd /tmp +#map gc cd ~/.config +#map gp cd /usr/portage +#map gb cd /boot + +## Unbind "q" so you don't accidentally close ranger +#unmap q + +## Edit files with the lowercase "e". By default, uppercase "E" is used. +#copymap E e + +## Add a key for searching files with a given string in their name +#map F console shell -p find . | grep -Iir --color + +## Find all files in this directory, shuffle them and view in mplayer +#map M shell find . | shuf | xargs -d \\n mplayer -fs + +## Add some keys to edit configuration files +#map ,r chain shell vim ~/.config/ranger/rc.conf; source_cmdlist ~/.config/ranger/rc.conf +#map ,a shell vim ~/.config/ranger/apps.py +#map ,c shell vim ~/.config/ranger/commands.py +#map ,o shell vim ~/.config/ranger/options.py + +## And some keys to view defaults +#map ,R shell vim %rangerdir/defaults/rc.conf +#map ,A shell vim %rangerdir/defaults/apps.py +#map ,C shell vim %rangerdir/defaults/commands.py +#map ,O shell vim %rangerdir/defaults/options.py +#map ,n shell vim %rangerdir/core/actions.py + +## You might want to scroll up/down with u/d like in a pager +#copymap d D +#copymap u U +#map d move down=0.8 pages=True +#map u move up=0.8 pages=True + +## Or scroll up/down with ^P/^N: +#copymap +#copymap -- cgit 1.4.1-2-gfad0