diff options
author | hut <hut@lavabit.com> | 2010-04-07 15:50:08 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-04-07 15:50:08 +0200 |
commit | 8d89c6f3a7cf6b0c8abc2ff68ecc7201ac08e872 (patch) | |
tree | 610dd3acfdac10ebe1d766a779897207ea6dfb33 /ranger/defaults | |
parent | 55435343b142c424619e3072475ca8b3366d109c (diff) | |
parent | f45f9734d2ff9fd6b68ff6c879d5b07b0e5c7d02 (diff) | |
download | ranger-8d89c6f3a7cf6b0c8abc2ff68ecc7201ac08e872.tar.gz |
Merge branch 'devel' into newkey
Conflicts: ranger/core/actions.py ranger/defaults/keys.py ranger/ext/direction.py ranger/gui/ui.py ranger/gui/widgets/browserview.py ranger/gui/widgets/pager.py
Diffstat (limited to 'ranger/defaults')
-rw-r--r-- | ranger/defaults/apps.py | 26 | ||||
-rw-r--r-- | ranger/defaults/commands.py | 30 | ||||
-rw-r--r-- | ranger/defaults/keys.py | 141 | ||||
-rw-r--r-- | ranger/defaults/options.py | 38 |
4 files changed, 154 insertions, 81 deletions
diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py index 347b9ce2..9543badb 100644 --- a/ranger/defaults/apps.py +++ b/ranger/defaults/apps.py @@ -59,6 +59,7 @@ class CustomApplications(Applications): if f.extension is not None: if f.extension in ('pdf'): + c.flags += 'd' return self.either(c, 'evince', 'zathura', 'apvlv') if f.extension in ('html', 'htm', 'xhtml', 'swf'): return self.either(c, 'firefox', 'opera', 'elinks') @@ -114,7 +115,7 @@ class CustomApplications(Applications): @depends_on('mplayer') def app_mplayer(self, c): if c.mode is 1: - return tup('mplayer', *c) + return tup('mplayer', '-fs', *c) elif c.mode is 2: args = "mplayer -fs -sid 0 -vfm ffmpeg -lavdopts " \ @@ -126,7 +127,7 @@ class CustomApplications(Applications): return tup('mplayer', '-mixer', 'software', *c) else: - return tup('mplayer', '-fs', *c) + return tup('mplayer', *c) @depends_on("eog") def app_eye_of_gnome(self, c): @@ -151,15 +152,18 @@ class CustomApplications(Applications): if len(c.files) > 1: return tup('feh', *c) - from collections import deque + try: + from collections import deque - directory = self.fm.env.get_directory(c.file.dirname) - images = [f.path for f in directory.files if f.image] - position = images.index(c.file.path) - deq = deque(images) - deq.rotate(-position) + directory = self.fm.env.get_directory(c.file.dirname) + images = [f.path for f in directory.files if f.image] + position = images.index(c.file.path) + deq = deque(images) + deq.rotate(-position) - return tup('feh', *deq) + return tup('feh', *deq) + except: + return tup('feh', *c) @depends_on("gimp") def app_gimp(self, c): @@ -231,6 +235,6 @@ class CustomApplications(Applications): @depends_on('totem') def app_totem(self, c): if c.mode is 0: - return tup("totem", "--fullscreen", *c) - if c.mode is 1: return tup("totem", *c) + if c.mode is 1: + return tup("totem", "--fullscreen", *c) diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index b1518013..f653168f 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -199,9 +199,10 @@ class find(Command): search = parse(self.line).rest(1) search = re.escape(search) self.fm.env.last_search = re.compile(search, re.IGNORECASE) + self.fm.search_method = 'search' if self.count == 1: - self.fm.move_right() + self.fm.move(right=1) self.fm.block_input(0.5) def quick_open(self): @@ -239,11 +240,25 @@ class quit(Command): """ :quit + Closes the current tab. If there is only one tab, quit the program. + """ + + def execute(self): + if len(self.fm.tabs) <= 1: + self.fm.exit() + self.fm.tab_close() + + +class quit_now(Command): + """ + :quit! + Quits the program immediately. """ + name = 'quit!' def execute(self): - raise SystemExit + self.fm.exit() class delete(Command): @@ -277,8 +292,11 @@ class delete(Command): # user did not confirm deletion return - if self.fm.env.cwd.marked_items \ - or (self.fm.env.cf.is_directory and not self.fm.env.cf.empty()): + cwd = self.fm.env.cwd + cf = self.fm.env.cf + + if cwd.marked_items or (cf.is_directory and not cf.islink \ + and len(os.listdir(cf.path)) > 0): # better ask for a confirmation, when attempting to # delete multiple files or a non-empty directory. return self.fm.open_console(self.mode, delete.WARNING) @@ -495,5 +513,7 @@ def get_command(name, abbrev=True): def command_generator(start): return (cmd + ' ' for cmd in by_name if cmd.startswith(start)) -alias(e=edit) # to make :e unambiguous. +alias(e=edit, q=quit) # for unambiguity +alias(**{'q!':quit_now}) +alias(qall=quit_now) diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index f48c7012..a236ad9f 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -53,28 +53,32 @@ def _vimlike_aliases(map): alias(KEY_HOME, 'gg') alias(KEY_END, 'G') + +def _emacs_aliases(map): + alias = map.alias + alias(KEY_LEFT, ctrl('b')) + alias(KEY_RIGHT, ctrl('f')) + alias(KEY_HOME, ctrl('a')) + alias(KEY_END, ctrl('e')) + alias(KEY_DC, ctrl('d')) + alias(DEL, ctrl('h')) + + def initialize_commands(map): """Initialize the commands for the main user interface""" # -------------------------------------------------------- movement _vimlike_aliases(map) - map.alias(KEY_LEFT, KEY_BACKSPACE, DEL) - - map(KEY_DOWN, fm.move_pointer(relative=1)) - map(KEY_UP, fm.move_pointer(relative=-1)) - map(KEY_RIGHT, KEY_ENTER, ctrl('j'), fm.move_right()) - map(KEY_LEFT, KEY_BACKSPACE, DEL, fm.move_left(1)) - map(KEY_HOME, fm.move_pointer(absolute=0)) - map(KEY_END, fm.move_pointer(absolute=-1)) + _basic_movement(map) - map(KEY_HOME, fm.move_pointer(absolute=0)) - map(KEY_END, fm.move_pointer(absolute=-1)) + map.alias(KEY_LEFT, KEY_BACKSPACE, DEL) + map.alias(KEY_RIGHT, KEY_ENTER, ctrl('j')) - map('%', fm.move_pointer_by_percentage(absolute=50)) - map(KEY_NPAGE, fm.move_pointer_by_pages(1)) - map(KEY_PPAGE, fm.move_pointer_by_pages(-1)) - map(ctrl('d'), 'J', fm.move_pointer_by_pages(0.5)) - map(ctrl('u'), 'K', fm.move_pointer_by_pages(-0.5)) + map('%', fm.move(to=50, percentage=True)) + map(KEY_NPAGE, ctrl('f'), fm.move(down=1, pages=True)) + map(KEY_PPAGE, ctrl('b'), fm.move(up=1, pages=True)) + map(ctrl('d'), 'J', fm.move(down=0.5, pages=True)) + map(ctrl('u'), 'K', fm.move(up=0.5, pages=True)) map(']', fm.traverse()) map('[', fm.history_go(-1)) @@ -107,14 +111,16 @@ def initialize_commands(map): map('du', fm.execute_command('du --max-depth=1 -h | less')) # -------------------------------------------------- toggle options - map('b', hint="show_//h//idden //p//review_files //d//irectories_first " \ - "//c//ollapse_preview flush//i//nput") - map('bh', fm.toggle_boolean_option('show_hidden')) - map('bp', fm.toggle_boolean_option('preview_files')) - map('bP', fm.toggle_boolean_option('preview_directories')) - map('bi', fm.toggle_boolean_option('flushinput')) - map('bd', fm.toggle_boolean_option('directories_first')) - map('bc', fm.toggle_boolean_option('collapse_preview')) + map('b', fm.notify('Warning: settings are now changed with z!', bad=True)) + map('z', hint="show_//h//idden //p//review_files //d//irectories_first " \ + "//c//ollapse_preview flush//i//nput ca//s//e_insensitive") + map('zh', fm.toggle_boolean_option('show_hidden')) + map('zp', fm.toggle_boolean_option('preview_files')) + map('zP', fm.toggle_boolean_option('preview_directories')) + map('zi', fm.toggle_boolean_option('flushinput')) + map('zd', fm.toggle_boolean_option('sort_directories_first')) + map('zc', fm.toggle_boolean_option('collapse_preview')) + map('zs', fm.toggle_boolean_option('sort_case_insensitive')) # ------------------------------------------------------------ sort map('o', 'O', hint="//s//ize //b//ase//n//ame //m//time //t//ype //r//everse") @@ -133,7 +139,7 @@ def initialize_commands(map): map('O' + key, fm.sort(func=val, reverse=True)) map('or', 'Or', 'oR', 'OR', lambda arg: \ - arg.fm.sort(reverse=not arg.fm.settings.reverse)) + arg.fm.sort(reverse=not arg.fm.settings.sort_reverse)) # ----------------------------------------------- console shortcuts @map("A") @@ -146,6 +152,8 @@ def initialize_commands(map): map('f', fm.open_console(cmode.COMMAND_QUICK, 'find ')) map('tf', fm.open_console(cmode.COMMAND, 'filter ')) map('d', hint='d//u// (disk usage) d//d// (cut)') + map('@', fm.open_console(cmode.OPEN, '@')) + map('#', fm.open_console(cmode.OPEN, 'p!')) # --------------------------------------------- jump to directories map('gh', fm.cd('~')) @@ -162,24 +170,32 @@ def initialize_commands(map): map('gs', fm.cd('/srv')) map('gR', fm.cd(RANGERDIR)) + # ------------------------------------------------------------ tabs + map('gc', ctrl('W'), fm.tab_close()) + map('gt', TAB, fm.tab_move(1)) + map('gT', KEY_BTAB, fm.tab_move(-1)) + map('gn', ctrl('N'), fm.tab_new()) + for n in range(10): + map('g' + str(n), fm.tab_open(n)) + # ------------------------------------------------------- searching map('/', fm.open_console(cmode.SEARCH)) map('n', fm.search()) map('N', fm.search(forward=False)) - map(TAB, fm.search(order='tag')) + map('ct', fm.search(order='tag')) map('cc', fm.search(order='ctime')) map('cm', fm.search(order='mimetype')) map('cs', fm.search(order='size')) - map('c', hint='//c//time //m//imetype //s//ize') + map('c', hint='//c//time //m//imetype //s//ize //t//agged') # ------------------------------------------------------- bookmarks for key in ALLOWED_BOOKMARK_KEYS: map("`" + key, "'" + key, fm.enter_bookmark(key)) map("m" + key, fm.set_bookmark(key)) map("um" + key, fm.unset_bookmark(key)) - map("`", "'", "m", draw_bookmarks=True) + map("`", "'", "m", "um", draw_bookmarks=True) # ---------------------------------------------------- change views map('i', fm.display_file()) @@ -204,10 +220,18 @@ def initialize_commands(map): # ------------------------------------------------ system functions _system_functions(map) - map('ZZ', fm.exit()) + map('ZZ', 'ZQ', fm.exit()) map(ctrl('R'), fm.reset()) map('R', fm.reload_cwd()) - map(ctrl('C'), fm.exit()) + @map(ctrl('C')) + def ctrl_c(arg): + try: + item = arg.fm.loader.queue[0] + except: + arg.fm.notify("Type Q or :quit<Enter> to exit Ranger") + else: + arg.fm.notify("Aborting: " + item.get_description()) + arg.fm.loader.remove(index=0) map(':', ';', fm.open_console(cmode.COMMAND)) map('>', fm.open_console(cmode.COMMAND_QUICK)) @@ -220,33 +244,24 @@ def initialize_commands(map): def initialize_console_commands(map): """Initialize the commands for the console widget only""" + _basic_movement(map) + _emacs_aliases(map) + # -------------------------------------------------------- movement map(KEY_UP, wdg.history_move(-1)) map(KEY_DOWN, wdg.history_move(1)) - - map(ctrl('b'), KEY_LEFT, wdg.move(relative = -1)) - map(ctrl('f'), KEY_RIGHT, wdg.move(relative = 1)) - map(ctrl('a'), KEY_HOME, wdg.move(absolute = 0)) - map(ctrl('e'), KEY_END, wdg.move(absolute = -1)) + map(KEY_HOME, wdg.move(right=0, absolute=True)) + map(KEY_END, wdg.move(right=-1, absolute=True)) # ----------------------------------------- deleting / pasting text - map(ctrl('d'), KEY_DC, wdg.delete(0)) - map(ctrl('h'), KEY_BACKSPACE, DEL, wdg.delete(-1)) + map(KEY_DC, wdg.delete(0)) + map(KEY_BACKSPACE, DEL, wdg.delete(-1)) map(ctrl('w'), wdg.delete_word()) map(ctrl('k'), wdg.delete_rest(1)) map(ctrl('u'), wdg.delete_rest(-1)) map(ctrl('y'), wdg.paste()) - # ----------------------------------------------------- typing keys - def type_key(arg): - arg.wdg.type_key(arg.keys) - - for i in range(ord(' '), ord('~')+1): - map(i, type_key) - # ------------------------------------------------ system functions - _system_functions(map) - map(KEY_F1, lambda arg: arg.fm.display_command_help(arg.wdg)) map(ctrl('c'), ESC, wdg.close()) map(ctrl('j'), KEY_ENTER, wdg.execute()) @@ -286,42 +301,44 @@ def initialize_embedded_pager_commands(map): map('q', 'i', ESC, lambda arg: arg.fm.ui.close_embedded_pager()) map.rebuild_paths() + def _base_pager_commands(map): _basic_movement(map) _vimlike_aliases(map) _system_functions(map) # -------------------------------------------------------- movement - map(KEY_LEFT, wdg.move_horizontal(relative=-4)) - map(KEY_RIGHT, wdg.move_horizontal(relative=4)) - map(KEY_NPAGE, wdg.move(relative=1, pages=True)) - map(KEY_PPAGE, wdg.move(relative=-1, pages=True)) - map(ctrl('d'), wdg.move(relative=0.5, pages=True)) - map(ctrl('u'), wdg.move(relative=-0.5, pages=True)) - map(' ', wdg.move(relative=0.8, pages=True)) + map(KEY_LEFT, wdg.move(left=4)) + map(KEY_RIGHT, wdg.move(right=4)) + map(KEY_NPAGE, ctrl('f'), wdg.move(down=1, pages=True)) + map(KEY_PPAGE, ctrl('b'), wdg.move(up=1, pages=True)) + map(ctrl('d'), wdg.move(down=0.5, pages=True)) + map(ctrl('u'), wdg.move(up=0.5, pages=True)) + map(' ', wdg.move(down=0.8, pages=True)) # ---------------------------------------------------------- others map('E', fm.edit_file()) map('?', fm.display_help()) # --------------------------------------------- less-like shortcuts - map.alias(KEY_NPAGE, 'd') - map.alias(KEY_PPAGE, 'u') + map.alias(KEY_NPAGE, 'f') + map.alias(KEY_PPAGE, 'b') + map.alias(ctrl('d'), 'd') + map.alias(ctrl('u'), 'u') def _system_functions(map): - # Each commandlist should have this bindings - map(KEY_RESIZE, fm.resize()) - map(KEY_MOUSE, fm.handle_mouse()) map('Q', fm.exit()) map(ctrl('L'), fm.redraw_window()) def _basic_movement(map): - map(KEY_DOWN, wdg.move(relative=1)) - map(KEY_UP, wdg.move(relative=-1)) - map(KEY_HOME, wdg.move(absolute=0)) - map(KEY_END, wdg.move(absolute=-1)) + map(KEY_DOWN, wdg.move(down=1)) + map(KEY_UP, wdg.move(up=1)) + map(KEY_RIGHT, wdg.move(right=1)) + map(KEY_LEFT, wdg.move(left=1)) + map(KEY_HOME, wdg.move(to=0)) + map(KEY_END, wdg.move(to=-1)) @@ -339,7 +356,7 @@ def base_directions(): map('<end>', dir=Direction(down=-1, absolute=True)) map('<pagedown>', dir=Direction(down=1, pages=True)) map('<pageup>', dir=Direction(down=-1, pages=True)) - map('%<any>', dir=Direction(down=1, percent=True, absolute=True)) + map('%<any>', dir=Direction(down=1, percentage=True, absolute=True)) map('<space>', dir=Direction(down=1, pages=True)) map('<CR>', dir=Direction(down=1)) diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py index a7090285..6b2a0dc9 100644 --- a/ranger/defaults/options.py +++ b/ranger/defaults/options.py @@ -33,7 +33,8 @@ of the values stay the same. from ranger.api.options import * -# Which files are hidden if show_hidden is False? +# Which files should be hidden? Toggle this by typing `zh' or +# changing the setting `show_hidden' hidden_filter = regexp( r'lost\+found|^\.|~$|\.(:?pyc|pyo|bak|swp)$') show_hidden = False @@ -50,8 +51,19 @@ preview_directories = True max_filesize_for_preview = 300 * 1024 # 300kb collapse_preview = True +# Save the console history on exit? +save_console_history = True + # Draw borders around columns? draw_borders = False +draw_bookmark_borders = True + +# How many columns are there, and what are their relative widths? +column_ratios = (1, 1, 4, 3) + +# Display the file size in the main column or status bar? +display_size_in_main_column = True +display_size_in_status_bar = False # Set a title for the window? update_title = True @@ -80,6 +92,26 @@ show_cursor = False # One of: size, basename, mtime, type sort = 'basename' -reverse = False -directories_first = True +sort_reverse = False +sort_case_insensitive = False +sort_directories_first = True + + +# Apply an overlay function to the colorscheme. It will be called with +# 4 arguments: the context and the 3 values (fg, bg, attr) returned by +# the original use() function of your colorscheme. The return value +# must be a 3-tuple of (fg, bg, attr). +# Note: Here, the colors/attributes aren't directly imported into +# the namespace but have to be accessed with color.xyz. +def colorscheme_overlay(context, fg, bg, attr): + if context.directory and attr & color.bold and \ + not any((context.marked, context.selected)): + attr ^= color.bold # I don't like bold directories! + + if context.main_column and context.selected: + fg, bg = color.red, color.default # To highlight the main column! + + return fg, bg, attr +# The above function was just an example, let's set it back to None +colorscheme_overlay = None |