diff options
| author | Shubham Saini <shubham6405@gmail.com> | 2019-12-02 12:21:04 +0000 |
|---|---|---|
| committer | Shubham Saini <shubham6405@gmail.com> | 2019-12-02 12:21:04 +0000 |
| commit | a42df546ce34429759a20bc2c4c240de045dbd0a (patch) | |
| tree | 4e7153d41d6a1b710f8002f2eb7b64231889b6cf /ranger | |
using stow
Diffstat (limited to 'ranger')
| -rw-r--r-- | ranger/.config/ranger/commands.py | 62 | ||||
| -rw-r--r-- | ranger/.config/ranger/commands_full.py | 1836 | ||||
| -rw-r--r-- | ranger/.config/ranger/rc.conf | 726 | ||||
| -rw-r--r-- | ranger/.config/ranger/rifle.conf | 256 | ||||
| -rwxr-xr-x | ranger/.config/ranger/scope.sh | 216 |
5 files changed, 3096 insertions, 0 deletions
diff --git a/ranger/.config/ranger/commands.py b/ranger/.config/ranger/commands.py new file mode 100644 index 0000000..97b7909 --- /dev/null +++ b/ranger/.config/ranger/commands.py | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | # This is a sample commands.py. You can add your own commands here. | ||
| 2 | # | ||
| 3 | # Please refer to commands_full.py for all the default commands and a complete | ||
| 4 | # documentation. Do NOT add them all here, or you may end up with defunct | ||
| 5 | # commands when upgrading ranger. | ||
| 6 | |||
| 7 | # A simple command for demonstration purposes follows. | ||
| 8 | # ----------------------------------------------------------------------------- | ||
| 9 | |||
| 10 | from __future__ import (absolute_import, division, print_function) | ||
| 11 | |||
| 12 | # You can import any python module as needed. | ||
| 13 | import os | ||
| 14 | |||
| 15 | # You always need to import ranger.api.commands here to get the Command class: | ||
| 16 | from ranger.api.commands import Command | ||
| 17 | |||
| 18 | |||
| 19 | # Any class that is a subclass of "Command" will be integrated into ranger as a | ||
| 20 | # command. Try typing ":my_edit<ENTER>" in ranger! | ||
| 21 | class my_edit(Command): | ||
| 22 | # The so-called doc-string of the class will be visible in the built-in | ||
| 23 | # help that is accessible by typing "?c" inside ranger. | ||
| 24 | """:my_edit <filename> | ||
| 25 | |||
| 26 | A sample command for demonstration purposes that opens a file in an editor. | ||
| 27 | """ | ||
| 28 | |||
| 29 | # The execute method is called when you run this command in ranger. | ||
| 30 | def execute(self): | ||
| 31 | # self.arg(1) is the first (space-separated) argument to the function. | ||
| 32 | # This way you can write ":my_edit somefilename<ENTER>". | ||
| 33 | if self.arg(1): | ||
| 34 | # self.rest(1) contains self.arg(1) and everything that follows | ||
| 35 | target_filename = self.rest(1) | ||
| 36 | else: | ||
| 37 | # self.fm is a ranger.core.filemanager.FileManager object and gives | ||
| 38 | # you access to internals of ranger. | ||
| 39 | # self.fm.thisfile is a ranger.container.file.File object and is a | ||
| 40 | # reference to the currently selected file. | ||
| 41 | target_filename = self.fm.thisfile.path | ||
| 42 | |||
| 43 | # This is a generic function to print text in ranger. | ||
| 44 | self.fm.notify("Let's edit the file " + target_filename + "!") | ||
| 45 | |||
| 46 | # Using bad=True in fm.notify allows you to print error messages: | ||
| 47 | if not os.path.exists(target_filename): | ||
| 48 | self.fm.notify("The given file does not exist!", bad=True) | ||
| 49 | return | ||
| 50 | |||
| 51 | # This executes a function from ranger.core.acitons, a module with a | ||
| 52 | # variety of subroutines that can help you construct commands. | ||
| 53 | # Check out the source, or run "pydoc ranger.core.actions" for a list. | ||
| 54 | self.fm.edit_file(target_filename) | ||
| 55 | |||
| 56 | # The tab method is called when you press tab, and should return a list of | ||
| 57 | # suggestions that the user will tab through. | ||
| 58 | # tabnum is 1 for <TAB> and -1 for <S-TAB> by default | ||
| 59 | def tab(self, tabnum): | ||
| 60 | # This is a generic tab-completion function that iterates through the | ||
| 61 | # content of the current directory. | ||
| 62 | return self._tab_directory_content() | ||
diff --git a/ranger/.config/ranger/commands_full.py b/ranger/.config/ranger/commands_full.py new file mode 100644 index 0000000..d177203 --- /dev/null +++ b/ranger/.config/ranger/commands_full.py | |||
| @@ -0,0 +1,1836 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # This file is part of ranger, the console file manager. | ||
| 3 | # This configuration file is licensed under the same terms as ranger. | ||
| 4 | # =================================================================== | ||
| 5 | # | ||
| 6 | # NOTE: If you copied this file to /etc/ranger/commands_full.py or | ||
| 7 | # ~/.config/ranger/commands_full.py, then it will NOT be loaded by ranger, | ||
| 8 | # and only serve as a reference. | ||
| 9 | # | ||
| 10 | # =================================================================== | ||
| 11 | # This file contains ranger's commands. | ||
| 12 | # It's all in python; lines beginning with # are comments. | ||
| 13 | # | ||
| 14 | # Note that additional commands are automatically generated from the methods | ||
| 15 | # of the class ranger.core.actions.Actions. | ||
| 16 | # | ||
| 17 | # You can customize commands in the files /etc/ranger/commands.py (system-wide) | ||
| 18 | # and ~/.config/ranger/commands.py (per user). | ||
| 19 | # They have the same syntax as this file. In fact, you can just copy this | ||
| 20 | # file to ~/.config/ranger/commands_full.py with | ||
| 21 | # `ranger --copy-config=commands_full' and make your modifications, don't | ||
| 22 | # forget to rename it to commands.py. You can also use | ||
| 23 | # `ranger --copy-config=commands' to copy a short sample commands.py that | ||
| 24 | # has everything you need to get started. | ||
| 25 | # But make sure you update your configs when you update ranger. | ||
| 26 | # | ||
| 27 | # =================================================================== | ||
| 28 | # Every class defined here which is a subclass of `Command' will be used as a | ||
| 29 | # command in ranger. Several methods are defined to interface with ranger: | ||
| 30 | # execute(): called when the command is executed. | ||
| 31 | # cancel(): called when closing the console. | ||
| 32 | # tab(tabnum): called when <TAB> is pressed. | ||
| 33 | # quick(): called after each keypress. | ||
| 34 | # | ||
| 35 | # tab() argument tabnum is 1 for <TAB> and -1 for <S-TAB> by default | ||
| 36 | # | ||
| 37 | # The return values for tab() can be either: | ||
| 38 | # None: There is no tab completion | ||
| 39 | # A string: Change the console to this string | ||
| 40 | # A list/tuple/generator: cycle through every item in it | ||
| 41 | # | ||
| 42 | # The return value for quick() can be: | ||
| 43 | # False: Nothing happens | ||
| 44 | # True: Execute the command afterwards | ||
| 45 | # | ||
| 46 | # The return value for execute() and cancel() doesn't matter. | ||
| 47 | # | ||
| 48 | # =================================================================== | ||
| 49 | # Commands have certain attributes and methods that facilitate parsing of | ||
| 50 | # the arguments: | ||
| 51 | # | ||
| 52 | # self.line: The whole line that was written in the console. | ||
| 53 | # self.args: A list of all (space-separated) arguments to the command. | ||
| 54 | # self.quantifier: If this command was mapped to the key "X" and | ||
| 55 | # the user pressed 6X, self.quantifier will be 6. | ||
| 56 | # self.arg(n): The n-th argument, or an empty string if it doesn't exist. | ||
| 57 | # self.rest(n): The n-th argument plus everything that followed. For example, | ||
| 58 | # if the command was "search foo bar a b c", rest(2) will be "bar a b c" | ||
| 59 | # self.start(n): Anything before the n-th argument. For example, if the | ||
| 60 | # command was "search foo bar a b c", start(2) will be "search foo" | ||
| 61 | # | ||
| 62 | # =================================================================== | ||
| 63 | # And this is a little reference for common ranger functions and objects: | ||
| 64 | # | ||
| 65 | # self.fm: A reference to the "fm" object which contains most information | ||
| 66 | # about ranger. | ||
| 67 | # self.fm.notify(string): Print the given string on the screen. | ||
| 68 | # self.fm.notify(string, bad=True): Print the given string in RED. | ||
| 69 | # self.fm.reload_cwd(): Reload the current working directory. | ||
| 70 | # self.fm.thisdir: The current working directory. (A File object.) | ||
| 71 | # self.fm.thisfile: The current file. (A File object too.) | ||
| 72 | # self.fm.thistab.get_selection(): A list of all selected files. | ||
| 73 | # self.fm.execute_console(string): Execute the string as a ranger command. | ||
| 74 | # self.fm.open_console(string): Open the console with the given string | ||
| 75 | # already typed in for you. | ||
| 76 | # self.fm.move(direction): Moves the cursor in the given direction, which | ||
| 77 | # can be something like down=3, up=5, right=1, left=1, to=6, ... | ||
| 78 | # | ||
| 79 | # File objects (for example self.fm.thisfile) have these useful attributes and | ||
| 80 | # methods: | ||
| 81 | # | ||
| 82 | # tfile.path: The path to the file. | ||
| 83 | # tfile.basename: The base name only. | ||
| 84 | # tfile.load_content(): Force a loading of the directories content (which | ||
| 85 | # obviously works with directories only) | ||
| 86 | # tfile.is_directory: True/False depending on whether it's a directory. | ||
| 87 | # | ||
| 88 | # For advanced commands it is unavoidable to dive a bit into the source code | ||
| 89 | # of ranger. | ||
| 90 | # =================================================================== | ||
| 91 | |||
| 92 | from __future__ import (absolute_import, division, print_function) | ||
| 93 | |||
| 94 | from collections import deque | ||
| 95 | import os | ||
| 96 | import re | ||
| 97 | |||
| 98 | from ranger.api.commands import Command | ||
| 99 | |||
| 100 | |||
| 101 | class alias(Command): | ||
| 102 | """:alias <newcommand> <oldcommand> | ||
| 103 | |||
| 104 | Copies the oldcommand as newcommand. | ||
| 105 | """ | ||
| 106 | |||
| 107 | context = 'browser' | ||
| 108 | resolve_macros = False | ||
| 109 | |||
| 110 | def execute(self): | ||
| 111 | if not self.arg(1) or not self.arg(2): | ||
| 112 | self.fm.notify('Syntax: alias <newcommand> <oldcommand>', bad=True) | ||
| 113 | return | ||
| 114 | |||
| 115 | self.fm.commands.alias(self.arg(1), self.rest(2)) | ||
| 116 | |||
| 117 | |||
| 118 | class echo(Command): | ||
| 119 | """:echo <text> | ||
| 120 | |||
| 121 | Display the text in the statusbar. | ||
| 122 | """ | ||
| 123 | |||
| 124 | def execute(self): | ||
| 125 | self.fm.notify(self.rest(1)) | ||
| 126 | |||
| 127 | |||
| 128 | class cd(Command): | ||
| 129 | """:cd [-r] <path> | ||
| 130 | |||
| 131 | The cd command changes the directory. | ||
| 132 | If the path is a file, selects that file. | ||
| 133 | The command 'cd -' is equivalent to typing ``. | ||
| 134 | Using the option "-r" will get you to the real path. | ||
| 135 | """ | ||
| 136 | |||
| 137 | def execute(self): | ||
| 138 | if self.arg(1) == '-r': | ||
| 139 | self.shift() | ||
| 140 | destination = os.path.realpath(self.rest(1)) | ||
| 141 | if os.path.isfile(destination): | ||
| 142 | self.fm.select_file(destination) | ||
| 143 | return | ||
| 144 | else: | ||
| 145 | destination = self.rest(1) | ||
| 146 | |||
| 147 | if not destination: | ||
| 148 | destination = '~' | ||
| 149 | |||
| 150 | if destination == '-': | ||
| 151 | self.fm.enter_bookmark('`') | ||
| 152 | else: | ||
| 153 | self.fm.cd(destination) | ||
| 154 | |||
| 155 | def _tab_args(self): | ||
| 156 | # dest must be rest because path could contain spaces | ||
| 157 | if self.arg(1) == '-r': | ||
| 158 | start = self.start(2) | ||
| 159 | dest = self.rest(2) | ||
| 160 | else: | ||
| 161 | start = self.start(1) | ||
| 162 | dest = self.rest(1) | ||
| 163 | |||
| 164 | if dest: | ||
| 165 | head, tail = os.path.split(os.path.expanduser(dest)) | ||
| 166 | if head: | ||
| 167 | dest_exp = os.path.join(os.path.normpath(head), tail) | ||
| 168 | else: | ||
| 169 | dest_exp = tail | ||
| 170 | else: | ||
| 171 | dest_exp = '' | ||
| 172 | return (start, dest_exp, os.path.join(self.fm.thisdir.path, dest_exp), | ||
| 173 | dest.endswith(os.path.sep)) | ||
| 174 | |||
| 175 | @staticmethod | ||
| 176 | def _tab_paths(dest, dest_abs, ends_with_sep): | ||
| 177 | if not dest: | ||
| 178 | try: | ||
| 179 | return next(os.walk(dest_abs))[1], dest_abs | ||
| 180 | except (OSError, StopIteration): | ||
| 181 | return [], '' | ||
| 182 | |||
| 183 | if ends_with_sep: | ||
| 184 | try: | ||
| 185 | return [os.path.join(dest, path) for path in next(os.walk(dest_abs))[1]], '' | ||
| 186 | except (OSError, StopIteration): | ||
| 187 | return [], '' | ||
| 188 | |||
| 189 | return None, None | ||
| 190 | |||
| 191 | def _tab_match(self, path_user, path_file): | ||
| 192 | if self.fm.settings.cd_tab_case == 'insensitive': | ||
| 193 | path_user = path_user.lower() | ||
| 194 | path_file = path_file.lower() | ||
| 195 | elif self.fm.settings.cd_tab_case == 'smart' and path_user.islower(): | ||
| 196 | path_file = path_file.lower() | ||
| 197 | return path_file.startswith(path_user) | ||
| 198 | |||
| 199 | def _tab_normal(self, dest, dest_abs): | ||
| 200 | dest_dir = os.path.dirname(dest) | ||
| 201 | dest_base = os.path.basename(dest) | ||
| 202 | |||
| 203 | try: | ||
| 204 | dirnames = next(os.walk(os.path.dirname(dest_abs)))[1] | ||
| 205 | except (OSError, StopIteration): | ||
| 206 | return [], '' | ||
| 207 | |||
| 208 | return [os.path.join(dest_dir, d) for d in dirnames if self._tab_match(dest_base, d)], '' | ||
| 209 | |||
| 210 | def _tab_fuzzy_match(self, basepath, tokens): | ||
| 211 | """ Find directories matching tokens recursively """ | ||
| 212 | if not tokens: | ||
| 213 | tokens = [''] | ||
| 214 | paths = [basepath] | ||
| 215 | while True: | ||
| 216 | token = tokens.pop() | ||
| 217 | matches = [] | ||
| 218 | for path in paths: | ||
| 219 | try: | ||
| 220 | directories = next(os.walk(path))[1] | ||
| 221 | except (OSError, StopIteration): | ||
| 222 | continue | ||
| 223 | matches += [os.path.join(path, d) for d in directories | ||
| 224 | if self._tab_match(token, d)] | ||
| 225 | if not tokens or not matches: | ||
| 226 | return matches | ||
| 227 | paths = matches | ||
| 228 | |||
| 229 | return None | ||
| 230 | |||
| 231 | def _tab_fuzzy(self, dest, dest_abs): | ||
| 232 | tokens = [] | ||
| 233 | basepath = dest_abs | ||
| 234 | while True: | ||
| 235 | basepath_old = basepath | ||
| 236 | basepath, token = os.path.split(basepath) | ||
| 237 | if basepath == basepath_old: | ||
| 238 | break | ||
| 239 | if os.path.isdir(basepath_old) and not token.startswith('.'): | ||
| 240 | basepath = basepath_old | ||
| 241 | break | ||
| 242 | tokens.append(token) | ||
| 243 | |||
| 244 | paths = self._tab_fuzzy_match(basepath, tokens) | ||
| 245 | if not os.path.isabs(dest): | ||
| 246 | paths_rel = basepath | ||
| 247 | paths = [os.path.relpath(path, paths_rel) for path in paths] | ||
| 248 | else: | ||
| 249 | paths_rel = '' | ||
| 250 | return paths, paths_rel | ||
| 251 | |||
| 252 | def tab(self, tabnum): | ||
| 253 | from os.path import sep | ||
| 254 | |||
| 255 | start, dest, dest_abs, ends_with_sep = self._tab_args() | ||
| 256 | |||
| 257 | paths, paths_rel = self._tab_paths(dest, dest_abs, ends_with_sep) | ||
| 258 | if paths is None: | ||
| 259 | if self.fm.settings.cd_tab_fuzzy: | ||
| 260 | paths, paths_rel = self._tab_fuzzy(dest, dest_abs) | ||
| 261 | else: | ||
| 262 | paths, paths_rel = self._tab_normal(dest, dest_abs) | ||
| 263 | |||
| 264 | paths.sort() | ||
| 265 | |||
| 266 | if self.fm.settings.cd_bookmarks: | ||
| 267 | paths[0:0] = [ | ||
| 268 | os.path.relpath(v.path, paths_rel) if paths_rel else v.path | ||
| 269 | for v in self.fm.bookmarks.dct.values() for path in paths | ||
| 270 | if v.path.startswith(os.path.join(paths_rel, path) + sep) | ||
| 271 | ] | ||
| 272 | |||
| 273 | if not paths: | ||
| 274 | return None | ||
| 275 | if len(paths) == 1: | ||
| 276 | return start + paths[0] + sep | ||
| 277 | return [start + dirname for dirname in paths] | ||
| 278 | |||
| 279 | |||
| 280 | class chain(Command): | ||
| 281 | """:chain <command1>; <command2>; ... | ||
| 282 | |||
| 283 | Calls multiple commands at once, separated by semicolons. | ||
| 284 | """ | ||
| 285 | |||
| 286 | def execute(self): | ||
| 287 | if not self.rest(1).strip(): | ||
| 288 | self.fm.notify('Syntax: chain <command1>; <command2>; ...', bad=True) | ||
| 289 | return | ||
| 290 | for command in [s.strip() for s in self.rest(1).split(";")]: | ||
| 291 | self.fm.execute_console(command) | ||
| 292 | |||
| 293 | |||
| 294 | class shell(Command): | ||
| 295 | escape_macros_for_shell = True | ||
| 296 | |||
| 297 | def execute(self): | ||
| 298 | if self.arg(1) and self.arg(1)[0] == '-': | ||
| 299 | flags = self.arg(1)[1:] | ||
| 300 | command = self.rest(2) | ||
| 301 | else: | ||
| 302 | flags = '' | ||
| 303 | command = self.rest(1) | ||
| 304 | |||
| 305 | if command: | ||
| 306 | self.fm.execute_command(command, flags=flags) | ||
| 307 | |||
| 308 | def tab(self, tabnum): | ||
| 309 | from ranger.ext.get_executables import get_executables | ||
| 310 | if self.arg(1) and self.arg(1)[0] == '-': | ||
| 311 | command = self.rest(2) | ||
| 312 | else: | ||
| 313 | command = self.rest(1) | ||
| 314 | start = self.line[0:len(self.line) - len(command)] | ||
| 315 | |||
| 316 | try: | ||
| 317 | position_of_last_space = command.rindex(" ") | ||
| 318 | except ValueError: | ||
| 319 | return (start + program + ' ' for program | ||
| 320 | in get_executables() if program.startswith(command)) | ||
| 321 | if position_of_last_space == len(command) - 1: | ||
| 322 | selection = self.fm.thistab.get_selection() | ||
| 323 | if len(selection) == 1: | ||
| 324 | return self.line + selection[0].shell_escaped_basename + ' ' | ||
| 325 | return self.line + '%s ' | ||
| 326 | |||
| 327 | before_word, start_of_word = self.line.rsplit(' ', 1) | ||
| 328 | return (before_word + ' ' + file.shell_escaped_basename | ||
| 329 | for file in self.fm.thisdir.files or [] | ||
| 330 | if file.shell_escaped_basename.startswith(start_of_word)) | ||
| 331 | |||
| 332 | |||
| 333 | class open_with(Command): | ||
| 334 | |||
| 335 | def execute(self): | ||
| 336 | app, flags, mode = self._get_app_flags_mode(self.rest(1)) | ||
| 337 | self.fm.execute_file( | ||
| 338 | files=[f for f in self.fm.thistab.get_selection()], | ||
| 339 | app=app, | ||
| 340 | flags=flags, | ||
| 341 | mode=mode) | ||
| 342 | |||
| 343 | def tab(self, tabnum): | ||
| 344 | return self._tab_through_executables() | ||
| 345 | |||
| 346 | def _get_app_flags_mode(self, string): # pylint: disable=too-many-branches,too-many-statements | ||
| 347 | """Extracts the application, flags and mode from a string. | ||
| 348 | |||
| 349 | examples: | ||
| 350 | "mplayer f 1" => ("mplayer", "f", 1) | ||
| 351 | "atool 4" => ("atool", "", 4) | ||
| 352 | "p" => ("", "p", 0) | ||
| 353 | "" => None | ||
| 354 | """ | ||
| 355 | |||
| 356 | app = '' | ||
| 357 | flags = '' | ||
| 358 | mode = 0 | ||
| 359 | split = string.split() | ||
| 360 | |||
| 361 | if len(split) == 1: | ||
| 362 | part = split[0] | ||
| 363 | if self._is_app(part): | ||
| 364 | app = part | ||
| 365 | elif self._is_flags(part): | ||
| 366 | flags = part | ||
| 367 | elif self._is_mode(part): | ||
| 368 | mode = part | ||
| 369 | |||
| 370 | elif len(split) == 2: | ||
| 371 | part0 = split[0] | ||
| 372 | part1 = split[1] | ||
| 373 | |||
| 374 | if self._is_app(part0): | ||
| 375 | app = part0 | ||
| 376 | if self._is_flags(part1): | ||
| 377 | flags = part1 | ||
| 378 | elif self._is_mode(part1): | ||
| 379 | mode = part1 | ||
| 380 | elif self._is_flags(part0): | ||
| 381 | flags = part0 | ||
| 382 | if self._is_mode(part1): | ||
| 383 | mode = part1 | ||
| 384 | elif self._is_mode(part0): | ||
| 385 | mode = part0 | ||
| 386 | if self._is_flags(part1): | ||
| 387 | flags = part1 | ||
| 388 | |||
| 389 | elif len(split) >= 3: | ||
| 390 | part0 = split[0] | ||
| 391 | part1 = split[1] | ||
| 392 | part2 = split[2] | ||
| 393 | |||
| 394 | if self._is_app(part0): | ||
| 395 | app = part0 | ||
| 396 | if self._is_flags(part1): | ||
| 397 | flags = part1 | ||
| 398 | if self._is_mode(part2): | ||
| 399 | mode = part2 | ||
| 400 | elif self._is_mode(part1): | ||
| 401 | mode = part1 | ||
| 402 | if self._is_flags(part2): | ||
| 403 | flags = part2 | ||
| 404 | elif self._is_flags(part0): | ||
| 405 | flags = part0 | ||
| 406 | if self._is_mode(part1): | ||
| 407 | mode = part1 | ||
| 408 | elif self._is_mode(part0): | ||
| 409 | mode = part0 | ||
| 410 | if self._is_flags(part1): | ||
| 411 | flags = part1 | ||
| 412 | |||
| 413 | return app, flags, int(mode) | ||
| 414 | |||
| 415 | def _is_app(self, arg): | ||
| 416 | return not self._is_flags(arg) and not arg.isdigit() | ||
| 417 | |||
| 418 | @staticmethod | ||
| 419 | def _is_flags(arg): | ||
| 420 | from ranger.core.runner import ALLOWED_FLAGS | ||
| 421 | return all(x in ALLOWED_FLAGS for x in arg) | ||
| 422 | |||
| 423 | @staticmethod | ||
| 424 | def _is_mode(arg): | ||
| 425 | return all(x in '0123456789' for x in arg) | ||
| 426 | |||
| 427 | |||
| 428 | class set_(Command): | ||
| 429 | """:set <option name>=<python expression> | ||
| 430 | |||
| 431 | Gives an option a new value. | ||
| 432 | |||
| 433 | Use `:set <option>!` to toggle or cycle it, e.g. `:set flush_input!` | ||
| 434 | """ | ||
| 435 | name = 'set' # don't override the builtin set class | ||
| 436 | |||
| 437 | def execute(self): | ||
| 438 | name = self.arg(1) | ||
| 439 | name, value, _, toggle = self.parse_setting_line_v2() | ||
| 440 | if toggle: | ||
| 441 | self.fm.toggle_option(name) | ||
| 442 | else: | ||
| 443 | self.fm.set_option_from_string(name, value) | ||
| 444 | |||
| 445 | def tab(self, tabnum): # pylint: disable=too-many-return-statements | ||
| 446 | from ranger.gui.colorscheme import get_all_colorschemes | ||
| 447 | name, value, name_done = self.parse_setting_line() | ||
| 448 | settings = self.fm.settings | ||
| 449 | if not name: | ||
| 450 | return sorted(self.firstpart + setting for setting in settings) | ||
| 451 | if not value and not name_done: | ||
| 452 | return sorted(self.firstpart + setting for setting in settings | ||
| 453 | if setting.startswith(name)) | ||
| 454 | if not value: | ||
| 455 | value_completers = { | ||
| 456 | "colorscheme": | ||
| 457 | # Cycle through colorschemes when name, but no value is specified | ||
| 458 | lambda: sorted(self.firstpart + colorscheme for colorscheme | ||
| 459 | in get_all_colorschemes(self.fm)), | ||
| 460 | |||
| 461 | "column_ratios": | ||
| 462 | lambda: self.firstpart + ",".join(map(str, settings[name])), | ||
| 463 | } | ||
| 464 | |||
| 465 | def default_value_completer(): | ||
| 466 | return self.firstpart + str(settings[name]) | ||
| 467 | |||
| 468 | return value_completers.get(name, default_value_completer)() | ||
| 469 | if bool in settings.types_of(name): | ||
| 470 | if 'true'.startswith(value.lower()): | ||
| 471 | return self.firstpart + 'True' | ||
| 472 | if 'false'.startswith(value.lower()): | ||
| 473 | return self.firstpart + 'False' | ||
| 474 | # Tab complete colorscheme values if incomplete value is present | ||
| 475 | if name == "colorscheme": | ||
| 476 | return sorted(self.firstpart + colorscheme for colorscheme | ||
| 477 | in get_all_colorschemes(self.fm) if colorscheme.startswith(value)) | ||
| 478 | return None | ||
| 479 | |||
| 480 | |||
| 481 | class setlocal(set_): | ||
| 482 | """:setlocal path=<regular expression> <option name>=<python expression> | ||
| 483 | |||
| 484 | Gives an option a new value. | ||
| 485 | """ | ||
| 486 | PATH_RE_DQUOTED = re.compile(r'^setlocal\s+path="(.*?)"') | ||
| 487 | PATH_RE_SQUOTED = re.compile(r"^setlocal\s+path='(.*?)'") | ||
| 488 | PATH_RE_UNQUOTED = re.compile(r'^path=(.*?)$') | ||
| 489 | |||
| 490 | def _re_shift(self, match): | ||
| 491 | if not match: | ||
| 492 | return None | ||
| 493 | path = os.path.expanduser(match.group(1)) | ||
| 494 | for _ in range(len(path.split())): | ||
| 495 | self.shift() | ||
| 496 | return path | ||
| 497 | |||
| 498 | def execute(self): | ||
| 499 | path = self._re_shift(self.PATH_RE_DQUOTED.match(self.line)) | ||
| 500 | if path is None: | ||
| 501 | path = self._re_shift(self.PATH_RE_SQUOTED.match(self.line)) | ||
| 502 | if path is None: | ||
| 503 | path = self._re_shift(self.PATH_RE_UNQUOTED.match(self.arg(1))) | ||
| 504 | if path is None and self.fm.thisdir: | ||
| 505 | path = self.fm.thisdir.path | ||
| 506 | if not path: | ||
| 507 | return | ||
| 508 | |||
| 509 | name, value, _ = self.parse_setting_line() | ||
| 510 | self.fm.set_option_from_string(name, value, localpath=path) | ||
| 511 | |||
| 512 | |||
| 513 | class setintag(set_): | ||
| 514 | """:setintag <tag or tags> <option name>=<option value> | ||
| 515 | |||
| 516 | Sets an option for directories that are tagged with a specific tag. | ||
| 517 | """ | ||
| 518 | |||
| 519 | def execute(self): | ||
| 520 | tags = self.arg(1) | ||
| 521 | self.shift() | ||
| 522 | name, value, _ = self.parse_setting_line() | ||
| 523 | self.fm.set_option_from_string(name, value, tags=tags) | ||
| 524 | |||
| 525 | |||
| 526 | class default_linemode(Command): | ||
| 527 | |||
| 528 | def execute(self): | ||
| 529 | from ranger.container.fsobject import FileSystemObject | ||
| 530 | |||
| 531 | if len(self.args) < 2: | ||
| 532 | self.fm.notify( | ||
| 533 | "Usage: default_linemode [path=<regexp> | tag=<tag(s)>] <linemode>", bad=True) | ||
| 534 | |||
| 535 | # Extract options like "path=..." or "tag=..." from the command line | ||
| 536 | arg1 = self.arg(1) | ||
| 537 | method = "always" | ||
| 538 | argument = None | ||
| 539 | if arg1.startswith("path="): | ||
| 540 | method = "path" | ||
| 541 | argument = re.compile(arg1[5:]) | ||
| 542 | self.shift() | ||
| 543 | elif arg1.startswith("tag="): | ||
| 544 | method = "tag" | ||
| 545 | argument = arg1[4:] | ||
| 546 | self.shift() | ||
| 547 | |||
| 548 | # Extract and validate the line mode from the command line | ||
| 549 | lmode = self.rest(1) | ||
| 550 | if lmode not in FileSystemObject.linemode_dict: | ||
| 551 | self.fm.notify( | ||
| 552 | "Invalid linemode: %s; should be %s" % ( | ||
| 553 | lmode, "/".join(FileSystemObject.linemode_dict)), | ||
| 554 | bad=True, | ||
| 555 | ) | ||
| 556 | |||
| 557 | # Add the prepared entry to the fm.default_linemodes | ||
| 558 | entry = [method, argument, lmode] | ||
| 559 | self.fm.default_linemodes.appendleft(entry) | ||
| 560 | |||
| 561 | # Redraw the columns | ||
| 562 | if self.fm.ui.browser: | ||
| 563 | for col in self.fm.ui.browser.columns: | ||
| 564 | col.need_redraw = True | ||
| 565 | |||
| 566 | def tab(self, tabnum): | ||
| 567 | return (self.arg(0) + " " + lmode | ||
| 568 | for lmode in self.fm.thisfile.linemode_dict.keys() | ||
| 569 | if lmode.startswith(self.arg(1))) | ||
| 570 | |||
| 571 | |||
| 572 | class quit(Command): # pylint: disable=redefined-builtin | ||
| 573 | """:quit | ||
| 574 | |||
| 575 | Closes the current tab, if there's only one tab. | ||
| 576 | Otherwise quits if there are no tasks in progress. | ||
| 577 | """ | ||
| 578 | def _exit_no_work(self): | ||
| 579 | if self.fm.loader.has_work(): | ||
| 580 | self.fm.notify('Not quitting: Tasks in progress: Use `quit!` to force quit') | ||
| 581 | else: | ||
| 582 | self.fm.exit() | ||
| 583 | |||
| 584 | def execute(self): | ||
| 585 | if len(self.fm.tabs) >= 2: | ||
| 586 | self.fm.tab_close() | ||
| 587 | else: | ||
| 588 | self._exit_no_work() | ||
| 589 | |||
| 590 | |||
| 591 | class quit_bang(Command): | ||
| 592 | """:quit! | ||
| 593 | |||
| 594 | Closes the current tab, if there's only one tab. | ||
| 595 | Otherwise force quits immediately. | ||
| 596 | """ | ||
| 597 | name = 'quit!' | ||
| 598 | allow_abbrev = False | ||
| 599 | |||
| 600 | def execute(self): | ||
| 601 | if len(self.fm.tabs) >= 2: | ||
| 602 | self.fm.tab_close() | ||
| 603 | else: | ||
| 604 | self.fm.exit() | ||
| 605 | |||
| 606 | |||
| 607 | class quitall(Command): | ||
| 608 | """:quitall | ||
| 609 | |||
| 610 | Quits if there are no tasks in progress. | ||
| 611 | """ | ||
| 612 | def _exit_no_work(self): | ||
| 613 | if self.fm.loader.has_work(): | ||
| 614 | self.fm.notify('Not quitting: Tasks in progress: Use `quitall!` to force quit') | ||
| 615 | else: | ||
| 616 | self.fm.exit() | ||
| 617 | |||
| 618 | def execute(self): | ||
| 619 | self._exit_no_work() | ||
| 620 | |||
| 621 | |||
| 622 | class quitall_bang(Command): | ||
| 623 | """:quitall! | ||
| 624 | |||
| 625 | Force quits immediately. | ||
| 626 | """ | ||
| 627 | name = 'quitall!' | ||
| 628 | allow_abbrev = False | ||
| 629 | |||
| 630 | def execute(self): | ||
| 631 | self.fm.exit() | ||
| 632 | |||
| 633 | |||
| 634 | class terminal(Command): | ||
| 635 | """:terminal | ||
| 636 | |||
| 637 | Spawns an "x-terminal-emulator" starting in the current directory. | ||
| 638 | """ | ||
| 639 | |||
| 640 | def execute(self): | ||
| 641 | from ranger.ext.get_executables import get_term | ||
| 642 | self.fm.run(get_term(), flags='f') | ||
| 643 | |||
| 644 | |||
| 645 | class delete(Command): | ||
| 646 | """:delete | ||
| 647 | |||
| 648 | Tries to delete the selection or the files passed in arguments (if any). | ||
| 649 | The arguments use a shell-like escaping. | ||
| 650 | |||
| 651 | "Selection" is defined as all the "marked files" (by default, you | ||
| 652 | can mark files with space or v). If there are no marked files, | ||
| 653 | use the "current file" (where the cursor is) | ||
| 654 | |||
| 655 | When attempting to delete non-empty directories or multiple | ||
| 656 | marked files, it will require a confirmation. | ||
| 657 | """ | ||
| 658 | |||
| 659 | allow_abbrev = False | ||
| 660 | escape_macros_for_shell = True | ||
| 661 | |||
| 662 | def execute(self): | ||
| 663 | import shlex | ||
| 664 | from functools import partial | ||
| 665 | |||
| 666 | def is_directory_with_files(path): | ||
| 667 | return os.path.isdir(path) and not os.path.islink(path) and len(os.listdir(path)) > 0 | ||
| 668 | |||
| 669 | if self.rest(1): | ||
| 670 | files = shlex.split(self.rest(1)) | ||
| 671 | many_files = (len(files) > 1 or is_directory_with_files(files[0])) | ||
| 672 | else: | ||
| 673 | cwd = self.fm.thisdir | ||
| 674 | tfile = self.fm.thisfile | ||
| 675 | if not cwd or not tfile: | ||
| 676 | self.fm.notify("Error: no file selected for deletion!", bad=True) | ||
| 677 | return | ||
| 678 | |||
| 679 | # relative_path used for a user-friendly output in the confirmation. | ||
| 680 | files = [f.relative_path for f in self.fm.thistab.get_selection()] | ||
| 681 | many_files = (cwd.marked_items or is_directory_with_files(tfile.path)) | ||
| 682 | |||
| 683 | confirm = self.fm.settings.confirm_on_delete | ||
| 684 | if confirm != 'never' and (confirm != 'multiple' or many_files): | ||
| 685 | self.fm.ui.console.ask( | ||
| 686 | "Confirm deletion of: %s (y/N)" % ', '.join(files), | ||
| 687 | partial(self._question_callback, files), | ||
| 688 | ('n', 'N', 'y', 'Y'), | ||
| 689 | ) | ||
| 690 | else: | ||
| 691 | # no need for a confirmation, just delete | ||
| 692 | self.fm.delete(files) | ||
| 693 | |||
| 694 | def tab(self, tabnum): | ||
| 695 | return self._tab_directory_content() | ||
| 696 | |||
| 697 | def _question_callback(self, files, answer): | ||
| 698 | if answer == 'y' or answer == 'Y': | ||
| 699 | self.fm.delete(files) | ||
| 700 | |||
| 701 | |||
| 702 | class jump_non(Command): | ||
| 703 | """:jump_non [-FLAGS...] | ||
| 704 | |||
| 705 | Jumps to first non-directory if highlighted file is a directory and vice versa. | ||
| 706 | |||
| 707 | Flags: | ||
| 708 | -r Jump in reverse order | ||
| 709 | -w Wrap around if reaching end of filelist | ||
| 710 | """ | ||
| 711 | def __init__(self, *args, **kwargs): | ||
| 712 | super(jump_non, self).__init__(*args, **kwargs) | ||
| 713 | |||
| 714 | flags, _ = self.parse_flags() | ||
| 715 | self._flag_reverse = 'r' in flags | ||
| 716 | self._flag_wrap = 'w' in flags | ||
| 717 | |||
| 718 | @staticmethod | ||
| 719 | def _non(fobj, is_directory): | ||
| 720 | return fobj.is_directory if not is_directory else not fobj.is_directory | ||
| 721 | |||
| 722 | def execute(self): | ||
| 723 | tfile = self.fm.thisfile | ||
| 724 | passed = False | ||
| 725 | found_before = None | ||
| 726 | found_after = None | ||
| 727 | for fobj in self.fm.thisdir.files[::-1] if self._flag_reverse else self.fm.thisdir.files: | ||
| 728 | if fobj.path == tfile.path: | ||
| 729 | passed = True | ||
| 730 | continue | ||
| 731 | |||
| 732 | if passed: | ||
| 733 | if self._non(fobj, tfile.is_directory): | ||
| 734 | found_after = fobj.path | ||
| 735 | break | ||
| 736 | elif not found_before and self._non(fobj, tfile.is_directory): | ||
| 737 | found_before = fobj.path | ||
| 738 | |||
| 739 | if found_after: | ||
| 740 | self.fm.select_file(found_after) | ||
| 741 | elif self._flag_wrap and found_before: | ||
| 742 | self.fm.select_file(found_before) | ||
| 743 | |||
| 744 | |||
| 745 | class mark_tag(Command): | ||
| 746 | """:mark_tag [<tags>] | ||
| 747 | |||
| 748 | Mark all tags that are tagged with either of the given tags. | ||
| 749 | When leaving out the tag argument, all tagged files are marked. | ||
| 750 | """ | ||
| 751 | do_mark = True | ||
| 752 | |||
| 753 | def execute(self): | ||
| 754 | cwd = self.fm.thisdir | ||
| 755 | tags = self.rest(1).replace(" ", "") | ||
| 756 | if not self.fm.tags or not cwd.files: | ||
| 757 | return | ||
| 758 | for fileobj in cwd.files: | ||
| 759 | try: | ||
| 760 | tag = self.fm.tags.tags[fileobj.realpath] | ||
| 761 | except KeyError: | ||
| 762 | continue | ||
| 763 | if not tags or tag in tags: | ||
| 764 | cwd.mark_item(fileobj, val=self.do_mark) | ||
| 765 | self.fm.ui.status.need_redraw = True | ||
| 766 | self.fm.ui.need_redraw = True | ||
| 767 | |||
| 768 | |||
| 769 | class console(Command): | ||
| 770 | """:console <command> | ||
| 771 | |||
| 772 | Open the console with the given command. | ||
| 773 | """ | ||
| 774 | |||
| 775 | def execute(self): | ||
| 776 | position = None | ||
| 777 | if self.arg(1)[0:2] == '-p': | ||
| 778 | try: | ||
| 779 | position = int(self.arg(1)[2:]) | ||
| 780 | except ValueError: | ||
| 781 | pass | ||
| 782 | else: | ||
| 783 | self.shift() | ||
| 784 | self.fm.open_console(self.rest(1), position=position) | ||
| 785 | |||
| 786 | |||
| 787 | class load_copy_buffer(Command): | ||
| 788 | """:load_copy_buffer | ||
| 789 | |||
| 790 | Load the copy buffer from datadir/copy_buffer | ||
| 791 | """ | ||
| 792 | copy_buffer_filename = 'copy_buffer' | ||
| 793 | |||
| 794 | def execute(self): | ||
| 795 | import sys | ||
| 796 | from ranger.container.file import File | ||
| 797 | from os.path import exists | ||
| 798 | fname = self.fm.datapath(self.copy_buffer_filename) | ||
| 799 | unreadable = IOError if sys.version_info[0] < 3 else OSError | ||
| 800 | try: | ||
| 801 | fobj = open(fname, 'r') | ||
| 802 | except unreadable: | ||
| 803 | return self.fm.notify( | ||
| 804 | "Cannot open %s" % (fname or self.copy_buffer_filename), bad=True) | ||
| 805 | |||
| 806 | self.fm.copy_buffer = set(File(g) | ||
| 807 | for g in fobj.read().split("\n") if exists(g)) | ||
| 808 | fobj.close() | ||
| 809 | self.fm.ui.redraw_main_column() | ||
| 810 | return None | ||
| 811 | |||
| 812 | |||
| 813 | class save_copy_buffer(Command): | ||
| 814 | """:save_copy_buffer | ||
| 815 | |||
| 816 | Save the copy buffer to datadir/copy_buffer | ||
| 817 | """ | ||
| 818 | copy_buffer_filename = 'copy_buffer' | ||
| 819 | |||
| 820 | def execute(self): | ||
| 821 | import sys | ||
| 822 | fname = None | ||
| 823 | fname = self.fm.datapath(self.copy_buffer_filename) | ||
| 824 | unwritable = IOError if sys.version_info[0] < 3 else OSError | ||
| 825 | try: | ||
| 826 | fobj = open(fname, 'w') | ||
| 827 | except unwritable: | ||
| 828 | return self.fm.notify("Cannot open %s" % | ||
| 829 | (fname or self.copy_buffer_filename), bad=True) | ||
| 830 | fobj.write("\n".join(fobj.path for fobj in self.fm.copy_buffer)) | ||
| 831 | fobj.close() | ||
| 832 | return None | ||
| 833 | |||
| 834 | |||
| 835 | class unmark_tag(mark_tag): | ||
| 836 | """:unmark_tag [<tags>] | ||
| 837 | |||
| 838 | Unmark all tags that are tagged with either of the given tags. | ||
| 839 | When leaving out the tag argument, all tagged files are unmarked. | ||
| 840 | """ | ||
| 841 | do_mark = False | ||
| 842 | |||
| 843 | |||
| 844 | class mkdir(Command): | ||
| 845 | """:mkdir <dirname> | ||
| 846 | |||
| 847 | Creates a directory with the name <dirname>. | ||
| 848 | """ | ||
| 849 | |||
| 850 | def execute(self): | ||
| 851 | from os.path import join, expanduser, lexists | ||
| 852 | from os import makedirs | ||
| 853 | |||
| 854 | dirname = join(self.fm.thisdir.path, expanduser(self.rest(1))) | ||
| 855 | if not lexists(dirname): | ||
| 856 | makedirs(dirname) | ||
| 857 | else: | ||
| 858 | self.fm.notify("file/directory exists!", bad=True) | ||
| 859 | |||
| 860 | def tab(self, tabnum): | ||
| 861 | return self._tab_directory_content() | ||
| 862 | |||
| 863 | |||
| 864 | class touch(Command): | ||
| 865 | """:touch <fname> | ||
| 866 | |||
| 867 | Creates a file with the name <fname>. | ||
| 868 | """ | ||
| 869 | |||
| 870 | def execute(self): | ||
| 871 | from os.path import join, expanduser, lexists | ||
| 872 | |||
| 873 | fname = join(self.fm.thisdir.path, expanduser(self.rest(1))) | ||
| 874 | if not lexists(fname): | ||
| 875 | open(fname, 'a').close() | ||
| 876 | else: | ||
| 877 | self.fm.notify("file/directory exists!", bad=True) | ||
| 878 | |||
| 879 | def tab(self, tabnum): | ||
| 880 | return self._tab_directory_content() | ||
| 881 | |||
| 882 | |||
| 883 | class edit(Command): | ||
| 884 | """:edit <filename> | ||
| 885 | |||
| 886 | Opens the specified file in vim | ||
| 887 | """ | ||
| 888 | |||
| 889 | def execute(self): | ||
| 890 | if not self.arg(1): | ||
| 891 | self.fm.edit_file(self.fm.thisfile.path) | ||
| 892 | else: | ||
| 893 | self.fm.edit_file(self.rest(1)) | ||
| 894 | |||
| 895 | def tab(self, tabnum): | ||
| 896 | return self._tab_directory_content() | ||
| 897 | |||
| 898 | |||
| 899 | class eval_(Command): | ||
| 900 | """:eval [-q] <python code> | ||
| 901 | |||
| 902 | Evaluates the python code. | ||
| 903 | `fm' is a reference to the FM instance. | ||
| 904 | To display text, use the function `p'. | ||
| 905 | |||
| 906 | Examples: | ||
| 907 | :eval fm | ||
| 908 | :eval len(fm.directories) | ||
| 909 | :eval p("Hello World!") | ||
| 910 | """ | ||
| 911 | name = 'eval' | ||
| 912 | resolve_macros = False | ||
| 913 | |||
| 914 | def execute(self): | ||
| 915 | # The import is needed so eval() can access the ranger module | ||
| 916 | import ranger # NOQA pylint: disable=unused-import,unused-variable | ||
| 917 | if self.arg(1) == '-q': | ||
| 918 | code = self.rest(2) | ||
| 919 | quiet = True | ||
| 920 | else: | ||
| 921 | code = self.rest(1) | ||
| 922 | quiet = False | ||
| 923 | global cmd, fm, p, quantifier # pylint: disable=invalid-name,global-variable-undefined | ||
| 924 | fm = self.fm | ||
| 925 | cmd = self.fm.execute_console | ||
| 926 | p = fm.notify | ||
| 927 | quantifier = self.quantifier | ||
| 928 | try: | ||
| 929 | try: | ||
| 930 | result = eval(code) # pylint: disable=eval-used | ||
| 931 | except SyntaxError: | ||
| 932 | exec(code) # pylint: disable=exec-used | ||
| 933 | else: | ||
| 934 | if result and not quiet: | ||
| 935 | p(result) | ||
| 936 | except Exception as err: # pylint: disable=broad-except | ||
| 937 | fm.notify("The error `%s` was caused by evaluating the " | ||
| 938 | "following code: `%s`" % (err, code), bad=True) | ||
| 939 | |||
| 940 | |||
| 941 | class rename(Command): | ||
| 942 | """:rename <newname> | ||
| 943 | |||
| 944 | Changes the name of the currently highlighted file to <newname> | ||
| 945 | """ | ||
| 946 | |||
| 947 | def execute(self): | ||
| 948 | from ranger.container.file import File | ||
| 949 | from os import access | ||
| 950 | |||
| 951 | new_name = self.rest(1) | ||
| 952 | |||
| 953 | if not new_name: | ||
| 954 | return self.fm.notify('Syntax: rename <newname>', bad=True) | ||
| 955 | |||
| 956 | if new_name == self.fm.thisfile.relative_path: | ||
| 957 | return None | ||
| 958 | |||
| 959 | if access(new_name, os.F_OK): | ||
| 960 | return self.fm.notify("Can't rename: file already exists!", bad=True) | ||
| 961 | |||
| 962 | if self.fm.rename(self.fm.thisfile, new_name): | ||
| 963 | file_new = File(new_name) | ||
| 964 | self.fm.bookmarks.update_path(self.fm.thisfile.path, file_new) | ||
| 965 | self.fm.tags.update_path(self.fm.thisfile.path, file_new.path) | ||
| 966 | self.fm.thisdir.pointed_obj = file_new | ||
| 967 | self.fm.thisfile = file_new | ||
| 968 | |||
| 969 | return None | ||
| 970 | |||
| 971 | def tab(self, tabnum): | ||
| 972 | return self._tab_directory_content() | ||
| 973 | |||
| 974 | |||
| 975 | class rename_append(Command): | ||
| 976 | """:rename_append [-FLAGS...] | ||
| 977 | |||
| 978 | Opens the console with ":rename <current file>" with the cursor positioned | ||
| 979 | before the file extension. | ||
| 980 | |||
| 981 | Flags: | ||
| 982 | -a Position before all extensions | ||
| 983 | -r Remove everything before extensions | ||
| 984 | """ | ||
| 985 | def __init__(self, *args, **kwargs): | ||
| 986 | super(rename_append, self).__init__(*args, **kwargs) | ||
| 987 | |||
| 988 | flags, _ = self.parse_flags() | ||
| 989 | self._flag_ext_all = 'a' in flags | ||
| 990 | self._flag_remove = 'r' in flags | ||
| 991 | |||
| 992 | def execute(self): | ||
| 993 | from ranger import MACRO_DELIMITER, MACRO_DELIMITER_ESC | ||
| 994 | |||
| 995 | tfile = self.fm.thisfile | ||
| 996 | relpath = tfile.relative_path.replace(MACRO_DELIMITER, MACRO_DELIMITER_ESC) | ||
| 997 | basename = tfile.basename.replace(MACRO_DELIMITER, MACRO_DELIMITER_ESC) | ||
| 998 | |||
| 999 | if basename.find('.') <= 0: | ||
| 1000 | self.fm.open_console('rename ' + relpath) | ||
| 1001 | return | ||
| 1002 | |||
| 1003 | if self._flag_ext_all: | ||
| 1004 | pos_ext = re.search(r'[^.]+', basename).end(0) | ||
| 1005 | else: | ||
| 1006 | pos_ext = basename.rindex('.') | ||
| 1007 | pos = len(relpath) - len(basename) + pos_ext | ||
| 1008 | |||
| 1009 | if self._flag_remove: | ||
| 1010 | relpath = relpath[:-len(basename)] + basename[pos_ext:] | ||
| 1011 | pos -= pos_ext | ||
| 1012 | |||
| 1013 | self.fm.open_console('rename ' + relpath, position=(7 + pos)) | ||
| 1014 | |||
| 1015 | |||
| 1016 | class chmod(Command): | ||
| 1017 | """:chmod <octal number> | ||
| 1018 | |||
| 1019 | Sets the permissions of the selection to the octal number. | ||
| 1020 | |||
| 1021 | The octal number is between 0 and 777. The digits specify the | ||
| 1022 | permissions for the user, the group and others. | ||
| 1023 | |||
| 1024 | A 1 permits execution, a 2 permits writing, a 4 permits reading. | ||
| 1025 | Add those numbers to combine them. So a 7 permits everything. | ||
| 1026 | """ | ||
| 1027 | |||
| 1028 | def execute(self): | ||
| 1029 | mode_str = self.rest(1) | ||
| 1030 | if not mode_str: | ||
| 1031 | if not self.quantifier: | ||
| 1032 | self.fm.notify("Syntax: chmod <octal number>", bad=True) | ||
| 1033 | return | ||
| 1034 | mode_str = str(self.quantifier) | ||
| 1035 | |||
| 1036 | try: | ||
| 1037 | mode = int(mode_str, 8) | ||
| 1038 | if mode < 0 or mode > 0o777: | ||
| 1039 | raise ValueError | ||
| 1040 | except ValueError: | ||
| 1041 | self.fm.notify("Need an octal number between 0 and 777!", bad=True) | ||
| 1042 | return | ||
| 1043 | |||
| 1044 | for fobj in self.fm.thistab.get_selection(): | ||
| 1045 | try: | ||
| 1046 | os.chmod(fobj.path, mode) | ||
| 1047 | except OSError as ex: | ||
| 1048 | self.fm.notify(ex) | ||
| 1049 | |||
| 1050 | # reloading directory. maybe its better to reload the selected | ||
| 1051 | # files only. | ||
| 1052 | self.fm.thisdir.content_outdated = True | ||
| 1053 | |||
| 1054 | |||
| 1055 | class bulkrename(Command): | ||
| 1056 | """:bulkrename | ||
| 1057 | |||
| 1058 | This command opens a list of selected files in an external editor. | ||
| 1059 | After you edit and save the file, it will generate a shell script | ||
| 1060 | which does bulk renaming according to the changes you did in the file. | ||
| 1061 | |||
| 1062 | This shell script is opened in an editor for you to review. | ||
| 1063 | After you close it, it will be executed. | ||
| 1064 | """ | ||
| 1065 | |||
| 1066 | def execute(self): # pylint: disable=too-many-locals,too-many-statements | ||
| 1067 | import sys | ||
| 1068 | import tempfile | ||
| 1069 | from ranger.container.file import File | ||
| 1070 | from ranger.ext.shell_escape import shell_escape as esc | ||
| 1071 | py3 = sys.version_info[0] >= 3 | ||
| 1072 | |||
| 1073 | # Create and edit the file list | ||
| 1074 | filenames = [f.relative_path for f in self.fm.thistab.get_selection()] | ||
| 1075 | listfile = tempfile.NamedTemporaryFile(delete=False) | ||
| 1076 | listpath = listfile.name | ||
| 1077 | |||
| 1078 | if py3: | ||
| 1079 | listfile.write("\n".join(filenames).encode("utf-8")) | ||
| 1080 | else: | ||
| 1081 | listfile.write("\n".join(filenames)) | ||
| 1082 | listfile.close() | ||
| 1083 | self.fm.execute_file([File(listpath)], app='editor') | ||
| 1084 | listfile = open(listpath, 'r') | ||
| 1085 | new_filenames = listfile.read().split("\n") | ||
| 1086 | listfile.close() | ||
| 1087 | os.unlink(listpath) | ||
| 1088 | if all(a == b for a, b in zip(filenames, new_filenames)): | ||
| 1089 | self.fm.notify("No renaming to be done!") | ||
| 1090 | return | ||
| 1091 | |||
| 1092 | # Generate script | ||
| 1093 | cmdfile = tempfile.NamedTemporaryFile() | ||
| 1094 | script_lines = [] | ||
| 1095 | script_lines.append("# This file will be executed when you close the editor.\n") | ||
| 1096 | script_lines.append("# Please double-check everything, clear the file to abort.\n") | ||
| 1097 | script_lines.extend("mv -vi -- %s %s\n" % (esc(old), esc(new)) | ||
| 1098 | for old, new in zip(filenames, new_filenames) if old != new) | ||
| 1099 | script_content = "".join(script_lines) | ||
| 1100 | if py3: | ||
| 1101 | cmdfile.write(script_content.encode("utf-8")) | ||
| 1102 | else: | ||
| 1103 | cmdfile.write(script_content) | ||
| 1104 | cmdfile.flush() | ||
| 1105 | |||
| 1106 | # Open the script and let the user review it, then check if the script | ||
| 1107 | # was modified by the user | ||
| 1108 | self.fm.execute_file([File(cmdfile.name)], app='editor') | ||
| 1109 | cmdfile.seek(0) | ||
| 1110 | script_was_edited = (script_content != cmdfile.read()) | ||
| 1111 | |||
| 1112 | # Do the renaming | ||
| 1113 | self.fm.run(['/bin/sh', cmdfile.name], flags='w') | ||
| 1114 | cmdfile.close() | ||
| 1115 | |||
| 1116 | # Retag the files, but only if the script wasn't changed during review, | ||
| 1117 | # because only then we know which are the source and destination files. | ||
| 1118 | if not script_was_edited: | ||
| 1119 | tags_changed = False | ||
| 1120 | for old, new in zip(filenames, new_filenames): | ||
| 1121 | if old != new: | ||
| 1122 | oldpath = self.fm.thisdir.path + '/' + old | ||
| 1123 | newpath = self.fm.thisdir.path + '/' + new | ||
| 1124 | if oldpath in self.fm.tags: | ||
| 1125 | old_tag = self.fm.tags.tags[oldpath] | ||
| 1126 | self.fm.tags.remove(oldpath) | ||
| 1127 | self.fm.tags.tags[newpath] = old_tag | ||
| 1128 | tags_changed = True | ||
| 1129 | if tags_changed: | ||
| 1130 | self.fm.tags.dump() | ||
| 1131 | else: | ||
| 1132 | fm.notify("files have not been retagged") | ||
| 1133 | |||
| 1134 | |||
| 1135 | class relink(Command): | ||
| 1136 | """:relink <newpath> | ||
| 1137 | |||
| 1138 | Changes the linked path of the currently highlighted symlink to <newpath> | ||
| 1139 | """ | ||
| 1140 | |||
| 1141 | def execute(self): | ||
| 1142 | new_path = self.rest(1) | ||
| 1143 | tfile = self.fm.thisfile | ||
| 1144 | |||
| 1145 | if not new_path: | ||
| 1146 | return self.fm.notify('Syntax: relink <newpath>', bad=True) | ||
| 1147 | |||
| 1148 | if not tfile.is_link: | ||
| 1149 | return self.fm.notify('%s is not a symlink!' % tfile.relative_path, bad=True) | ||
| 1150 | |||
| 1151 | if new_path == os.readlink(tfile.path): | ||
| 1152 | return None | ||
| 1153 | |||
| 1154 | try: | ||
| 1155 | os.remove(tfile.path) | ||
| 1156 | os.symlink(new_path, tfile.path) | ||
| 1157 | except OSError as err: | ||
| 1158 | self.fm.notify(err) | ||
| 1159 | |||
| 1160 | self.fm.reset() | ||
| 1161 | self.fm.thisdir.pointed_obj = tfile | ||
| 1162 | self.fm.thisfile = tfile | ||
| 1163 | |||
| 1164 | return None | ||
| 1165 | |||
| 1166 | def tab(self, tabnum): | ||
| 1167 | if not self.rest(1): | ||
| 1168 | return self.line + os.readlink(self.fm.thisfile.path) | ||
| 1169 | return self._tab_directory_content() | ||
| 1170 | |||
| 1171 | |||
| 1172 | class help_(Command): | ||
| 1173 | """:help | ||
| 1174 | |||
| 1175 | Display ranger's manual page. | ||
| 1176 | """ | ||
| 1177 | name = 'help' | ||
| 1178 | |||
| 1179 | def execute(self): | ||
| 1180 | def callback(answer): | ||
| 1181 | if answer == "q": | ||
| 1182 | return | ||
| 1183 | elif answer == "m": | ||
| 1184 | self.fm.display_help() | ||
| 1185 | elif answer == "c": | ||
| 1186 | self.fm.dump_commands() | ||
| 1187 | elif answer == "k": | ||
| 1188 | self.fm.dump_keybindings() | ||
| 1189 | elif answer == "s": | ||
| 1190 | self.fm.dump_settings() | ||
| 1191 | |||
| 1192 | self.fm.ui.console.ask( | ||
| 1193 | "View [m]an page, [k]ey bindings, [c]ommands or [s]ettings? (press q to abort)", | ||
| 1194 | callback, | ||
| 1195 | list("mqkcs") | ||
| 1196 | ) | ||
| 1197 | |||
| 1198 | |||
| 1199 | class copymap(Command): | ||
| 1200 | """:copymap <keys> <newkeys1> [<newkeys2>...] | ||
| 1201 | |||
| 1202 | Copies a "browser" keybinding from <keys> to <newkeys> | ||
| 1203 | """ | ||
| 1204 | context = 'browser' | ||
| 1205 | |||
| 1206 | def execute(self): | ||
| 1207 | if not self.arg(1) or not self.arg(2): | ||
| 1208 | return self.fm.notify("Not enough arguments", bad=True) | ||
| 1209 | |||
| 1210 | for arg in self.args[2:]: | ||
| 1211 | self.fm.ui.keymaps.copy(self.context, self.arg(1), arg) | ||
| 1212 | |||
| 1213 | return None | ||
| 1214 | |||
| 1215 | |||
| 1216 | class copypmap(copymap): | ||
| 1217 | """:copypmap <keys> <newkeys1> [<newkeys2>...] | ||
| 1218 | |||
| 1219 | Copies a "pager" keybinding from <keys> to <newkeys> | ||
| 1220 | """ | ||
| 1221 | context = 'pager' | ||
| 1222 | |||
| 1223 | |||
| 1224 | class copycmap(copymap): | ||
| 1225 | """:copycmap <keys> <newkeys1> [<newkeys2>...] | ||
| 1226 | |||
| 1227 | Copies a "console" keybinding from <keys> to <newkeys> | ||
| 1228 | """ | ||
| 1229 | context = 'console' | ||
| 1230 | |||
| 1231 | |||
| 1232 | class copytmap(copymap): | ||
| 1233 | """:copycmap <keys> <newkeys1> [<newkeys2>...] | ||
| 1234 | |||
| 1235 | Copies a "taskview" keybinding from <keys> to <newkeys> | ||
| 1236 | """ | ||
| 1237 | context = 'taskview' | ||
| 1238 | |||
| 1239 | |||
| 1240 | class unmap(Command): | ||
| 1241 | """:unmap <keys> [<keys2>, ...] | ||
| 1242 | |||
| 1243 | Remove the given "browser" mappings | ||
| 1244 | """ | ||
| 1245 | context = 'browser' | ||
| 1246 | |||
| 1247 | def execute(self): | ||
| 1248 | for arg in self.args[1:]: | ||
| 1249 | self.fm.ui.keymaps.unbind(self.context, arg) | ||
| 1250 | |||
| 1251 | |||
| 1252 | class cunmap(unmap): | ||
| 1253 | """:cunmap <keys> [<keys2>, ...] | ||
| 1254 | |||
| 1255 | Remove the given "console" mappings | ||
| 1256 | """ | ||
| 1257 | context = 'browser' | ||
| 1258 | |||
| 1259 | |||
| 1260 | class punmap(unmap): | ||
| 1261 | """:punmap <keys> [<keys2>, ...] | ||
| 1262 | |||
| 1263 | Remove the given "pager" mappings | ||
| 1264 | """ | ||
| 1265 | context = 'pager' | ||
| 1266 | |||
| 1267 | |||
| 1268 | class tunmap(unmap): | ||
| 1269 | """:tunmap <keys> [<keys2>, ...] | ||
| 1270 | |||
| 1271 | Remove the given "taskview" mappings | ||
| 1272 | """ | ||
| 1273 | context = 'taskview' | ||
| 1274 | |||
| 1275 | |||
| 1276 | class map_(Command): | ||
| 1277 | """:map <keysequence> <command> | ||
| 1278 | |||
| 1279 | Maps a command to a keysequence in the "browser" context. | ||
| 1280 | |||
| 1281 | Example: | ||
| 1282 | map j move down | ||
| 1283 | map J move down 10 | ||
| 1284 | """ | ||
| 1285 | name = 'map' | ||
| 1286 | context = 'browser' | ||
| 1287 | resolve_macros = False | ||
| 1288 | |||
| 1289 | def execute(self): | ||
| 1290 | if not self.arg(1) or not self.arg(2): | ||
| 1291 | self.fm.notify("Syntax: {0} <keysequence> <command>".format(self.get_name()), bad=True) | ||
| 1292 | return | ||
| 1293 | |||
| 1294 | self.fm.ui.keymaps.bind(self.context, self.arg(1), self.rest(2)) | ||
| 1295 | |||
| 1296 | |||
| 1297 | class cmap(map_): | ||
| 1298 | """:cmap <keysequence> <command> | ||
| 1299 | |||
| 1300 | Maps a command to a keysequence in the "console" context. | ||
| 1301 | |||
| 1302 | Example: | ||
| 1303 | cmap <ESC> console_close | ||
| 1304 | cmap <C-x> console_type test | ||
| 1305 | """ | ||
| 1306 | context = 'console' | ||
| 1307 | |||
| 1308 | |||
| 1309 | class tmap(map_): | ||
| 1310 | """:tmap <keysequence> <command> | ||
| 1311 | |||
| 1312 | Maps a command to a keysequence in the "taskview" context. | ||
| 1313 | """ | ||
| 1314 | context = 'taskview' | ||
| 1315 | |||
| 1316 | |||
| 1317 | class pmap(map_): | ||
| 1318 | """:pmap <keysequence> <command> | ||
| 1319 | |||
| 1320 | Maps a command to a keysequence in the "pager" context. | ||
| 1321 | """ | ||
| 1322 | context = 'pager' | ||
| 1323 | |||
| 1324 | |||
| 1325 | class scout(Command): | ||
| 1326 | """:scout [-FLAGS...] <pattern> | ||
| 1327 | |||
| 1328 | Swiss army knife command for searching, traveling and filtering files. | ||
| 1329 | |||
| 1330 | Flags: | ||
| 1331 | -a Automatically open a file on unambiguous match | ||
| 1332 | -e Open the selected file when pressing enter | ||
| 1333 | -f Filter files that match the current search pattern | ||
| 1334 | -g Interpret pattern as a glob pattern | ||
| 1335 | -i Ignore the letter case of the files | ||
| 1336 | -k Keep the console open when changing a directory with the command | ||
| 1337 | -l Letter skipping; e.g. allow "rdme" to match the file "readme" | ||
| 1338 | -m Mark the matching files after pressing enter | ||
| 1339 | -M Unmark the matching files after pressing enter | ||
| 1340 | -p Permanent filter: hide non-matching files after pressing enter | ||
| 1341 | -r Interpret pattern as a regular expression pattern | ||
| 1342 | -s Smart case; like -i unless pattern contains upper case letters | ||
| 1343 | -t Apply filter and search pattern as you type | ||
| 1344 | -v Inverts the match | ||
| 1345 | |||
| 1346 | Multiple flags can be combined. For example, ":scout -gpt" would create | ||
| 1347 | a :filter-like command using globbing. | ||
| 1348 | """ | ||
| 1349 | # pylint: disable=bad-whitespace | ||
| 1350 | AUTO_OPEN = 'a' | ||
| 1351 | OPEN_ON_ENTER = 'e' | ||
| 1352 | FILTER = 'f' | ||
| 1353 | SM_GLOB = 'g' | ||
| 1354 | IGNORE_CASE = 'i' | ||
| 1355 | KEEP_OPEN = 'k' | ||
| 1356 | SM_LETTERSKIP = 'l' | ||
| 1357 | MARK = 'm' | ||
| 1358 | UNMARK = 'M' | ||
| 1359 | PERM_FILTER = 'p' | ||
| 1360 | SM_REGEX = 'r' | ||
| 1361 | SMART_CASE = 's' | ||
| 1362 | AS_YOU_TYPE = 't' | ||
| 1363 | INVERT = 'v' | ||
| 1364 | # pylint: enable=bad-whitespace | ||
| 1365 | |||
| 1366 | def __init__(self, *args, **kwargs): | ||
| 1367 | super(scout, self).__init__(*args, **kwargs) | ||
| 1368 | self._regex = None | ||
| 1369 | self.flags, self.pattern = self.parse_flags() | ||
| 1370 | |||
| 1371 | def execute(self): # pylint: disable=too-many-branches | ||
| 1372 | thisdir = self.fm.thisdir | ||
| 1373 | flags = self.flags | ||
| 1374 | pattern = self.pattern | ||
| 1375 | regex = self._build_regex() | ||
| 1376 | count = self._count(move=True) | ||
| 1377 | |||
| 1378 | self.fm.thistab.last_search = regex | ||
| 1379 | self.fm.set_search_method(order="search") | ||
| 1380 | |||
| 1381 | if (self.MARK in flags or self.UNMARK in flags) and thisdir.files: | ||
| 1382 | value = flags.find(self.MARK) > flags.find(self.UNMARK) | ||
| 1383 | if self.FILTER in flags: | ||
| 1384 | for fobj in thisdir.files: | ||
| 1385 | thisdir.mark_item(fobj, value) | ||
| 1386 | else: | ||
| 1387 | for fobj in thisdir.files: | ||
| 1388 | if regex.search(fobj.relative_path): | ||
| 1389 | thisdir.mark_item(fobj, value) | ||
| 1390 | |||
| 1391 | if self.PERM_FILTER in flags: | ||
| 1392 | thisdir.filter = regex if pattern else None | ||
| 1393 | |||
| 1394 | # clean up: | ||
| 1395 | self.cancel() | ||
| 1396 | |||
| 1397 | if self.OPEN_ON_ENTER in flags or \ | ||
| 1398 | (self.AUTO_OPEN in flags and count == 1): | ||
| 1399 | if pattern == '..': | ||
| 1400 | self.fm.cd(pattern) | ||
| 1401 | else: | ||
| 1402 | self.fm.move(right=1) | ||
| 1403 | if self.quickly_executed: | ||
| 1404 | self.fm.block_input(0.5) | ||
| 1405 | |||
| 1406 | if self.KEEP_OPEN in flags and thisdir != self.fm.thisdir: | ||
| 1407 | # reopen the console: | ||
| 1408 | if not pattern: | ||
| 1409 | self.fm.open_console(self.line) | ||
| 1410 | else: | ||
| 1411 | self.fm.open_console(self.line[0:-len(pattern)]) | ||
| 1412 | |||
| 1413 | if self.quickly_executed and thisdir != self.fm.thisdir and pattern != "..": | ||
| 1414 | self.fm.block_input(0.5) | ||
| 1415 | |||
| 1416 | def cancel(self): | ||
| 1417 | self.fm.thisdir.temporary_filter = None | ||
| 1418 | self.fm.thisdir.refilter() | ||
| 1419 | |||
| 1420 | def quick(self): | ||
| 1421 | asyoutype = self.AS_YOU_TYPE in self.flags | ||
| 1422 | if self.FILTER in self.flags: | ||
| 1423 | self.fm.thisdir.temporary_filter = self._build_regex() | ||
| 1424 | if self.PERM_FILTER in self.flags and asyoutype: | ||
| 1425 | self.fm.thisdir.filter = self._build_regex() | ||
| 1426 | if self.FILTER in self.flags or self.PERM_FILTER in self.flags: | ||
| 1427 | self.fm.thisdir.refilter() | ||
| 1428 | if self._count(move=asyoutype) == 1 and self.AUTO_OPEN in self.flags: | ||
| 1429 | return True | ||
| 1430 | return False | ||
| 1431 | |||
| 1432 | def tab(self, tabnum): | ||
| 1433 | self._count(move=True, offset=tabnum) | ||
| 1434 | |||
| 1435 | def _build_regex(self): | ||
| 1436 | if self._regex is not None: | ||
| 1437 | return self._regex | ||
| 1438 | |||
| 1439 | frmat = "%s" | ||
| 1440 | flags = self.flags | ||
| 1441 | pattern = self.pattern | ||
| 1442 | |||
| 1443 | if pattern == ".": | ||
| 1444 | return re.compile("") | ||
| 1445 | |||
| 1446 | # Handle carets at start and dollar signs at end separately | ||
| 1447 | if pattern.startswith('^'): | ||
| 1448 | pattern = pattern[1:] | ||
| 1449 | frmat = "^" + frmat | ||
| 1450 | if pattern.endswith('$'): | ||
| 1451 | pattern = pattern[:-1] | ||
| 1452 | frmat += "$" | ||
| 1453 | |||
| 1454 | # Apply one of the search methods | ||
| 1455 | if self.SM_REGEX in flags: | ||
| 1456 | regex = pattern | ||
| 1457 | elif self.SM_GLOB in flags: | ||
| 1458 | regex = re.escape(pattern).replace("\\*", ".*").replace("\\?", ".") | ||
| 1459 | elif self.SM_LETTERSKIP in flags: | ||
| 1460 | regex = ".*".join(re.escape(c) for c in pattern) | ||
| 1461 | else: | ||
| 1462 | regex = re.escape(pattern) | ||
| 1463 | |||
| 1464 | regex = frmat % regex | ||
| 1465 | |||
| 1466 | # Invert regular expression if necessary | ||
| 1467 | if self.INVERT in flags: | ||
| 1468 | regex = "^(?:(?!%s).)*$" % regex | ||
| 1469 | |||
| 1470 | # Compile Regular Expression | ||
| 1471 | # pylint: disable=no-member | ||
| 1472 | options = re.UNICODE | ||
| 1473 | if self.IGNORE_CASE in flags or self.SMART_CASE in flags and \ | ||
| 1474 | pattern.islower(): | ||
| 1475 | options |= re.IGNORECASE | ||
| 1476 | # pylint: enable=no-member | ||
| 1477 | try: | ||
| 1478 | self._regex = re.compile(regex, options) | ||
| 1479 | except re.error: | ||
| 1480 | self._regex = re.compile("") | ||
| 1481 | return self._regex | ||
| 1482 | |||
| 1483 | def _count(self, move=False, offset=0): | ||
| 1484 | count = 0 | ||
| 1485 | cwd = self.fm.thisdir | ||
| 1486 | pattern = self.pattern | ||
| 1487 | |||
| 1488 | if not pattern or not cwd.files: | ||
| 1489 | return 0 | ||
| 1490 | if pattern == '.': | ||
| 1491 | return 0 | ||
| 1492 | if pattern == '..': | ||
| 1493 | return 1 | ||
| 1494 | |||
| 1495 | deq = deque(cwd.files) | ||
| 1496 | deq.rotate(-cwd.pointer - offset) | ||
| 1497 | i = offset | ||
| 1498 | regex = self._build_regex() | ||
| 1499 | for fsobj in deq: | ||
| 1500 | if regex.search(fsobj.relative_path): | ||
| 1501 | count += 1 | ||
| 1502 | if move and count == 1: | ||
| 1503 | cwd.move(to=(cwd.pointer + i) % len(cwd.files)) | ||
| 1504 | self.fm.thisfile = cwd.pointed_obj | ||
| 1505 | if count > 1: | ||
| 1506 | return count | ||
| 1507 | i += 1 | ||
| 1508 | |||
| 1509 | return count == 1 | ||
| 1510 | |||
| 1511 | |||
| 1512 | class narrow(Command): | ||
| 1513 | """ | ||
| 1514 | :narrow | ||
| 1515 | |||
| 1516 | Show only the files selected right now. If no files are selected, | ||
| 1517 | disable narrowing. | ||
| 1518 | """ | ||
| 1519 | def execute(self): | ||
| 1520 | if self.fm.thisdir.marked_items: | ||
| 1521 | selection = [f.basename for f in self.fm.thistab.get_selection()] | ||
| 1522 | self.fm.thisdir.narrow_filter = selection | ||
| 1523 | else: | ||
| 1524 | self.fm.thisdir.narrow_filter = None | ||
| 1525 | self.fm.thisdir.refilter() | ||
| 1526 | |||
| 1527 | |||
| 1528 | class filter_inode_type(Command): | ||
| 1529 | """ | ||
| 1530 | :filter_inode_type [dfl] | ||
| 1531 | |||
| 1532 | Displays only the files of specified inode type. Parameters | ||
| 1533 | can be combined. | ||
| 1534 | |||
| 1535 | d display directories | ||
| 1536 | f display files | ||
| 1537 | l display links | ||
| 1538 | """ | ||
| 1539 | |||
| 1540 | def execute(self): | ||
| 1541 | if not self.arg(1): | ||
| 1542 | self.fm.thisdir.inode_type_filter = "" | ||
| 1543 | else: | ||
| 1544 | self.fm.thisdir.inode_type_filter = self.arg(1) | ||
| 1545 | self.fm.thisdir.refilter() | ||
| 1546 | |||
| 1547 | |||
| 1548 | class filter_stack(Command): | ||
| 1549 | """ | ||
| 1550 | :filter_stack ... | ||
| 1551 | |||
| 1552 | Manages the filter stack. | ||
| 1553 | |||
| 1554 | filter_stack add FILTER_TYPE ARGS... | ||
| 1555 | filter_stack pop | ||
| 1556 | filter_stack decompose | ||
| 1557 | filter_stack rotate [N=1] | ||
| 1558 | filter_stack clear | ||
| 1559 | filter_stack show | ||
| 1560 | """ | ||
| 1561 | def execute(self): | ||
| 1562 | from ranger.core.filter_stack import SIMPLE_FILTERS, FILTER_COMBINATORS | ||
| 1563 | |||
| 1564 | subcommand = self.arg(1) | ||
| 1565 | |||
| 1566 | if subcommand == "add": | ||
| 1567 | try: | ||
| 1568 | self.fm.thisdir.filter_stack.append( | ||
| 1569 | SIMPLE_FILTERS[self.arg(2)](self.rest(3)) | ||
| 1570 | ) | ||
| 1571 | except KeyError: | ||
| 1572 | FILTER_COMBINATORS[self.arg(2)](self.fm.thisdir.filter_stack) | ||
| 1573 | elif subcommand == "pop": | ||
| 1574 | self.fm.thisdir.filter_stack.pop() | ||
| 1575 | elif subcommand == "decompose": | ||
| 1576 | inner_filters = self.fm.thisdir.filter_stack.pop().decompose() | ||
| 1577 | if inner_filters: | ||
| 1578 | self.fm.thisdir.filter_stack.extend(inner_filters) | ||
| 1579 | elif subcommand == "clear": | ||
| 1580 | self.fm.thisdir.filter_stack = [] | ||
| 1581 | elif subcommand == "rotate": | ||
| 1582 | rotate_by = int(self.arg(2) or 1) | ||
| 1583 | self.fm.thisdir.filter_stack = ( | ||
| 1584 | self.fm.thisdir.filter_stack[-rotate_by:] | ||
| 1585 | + self.fm.thisdir.filter_stack[:-rotate_by] | ||
| 1586 | ) | ||
| 1587 | elif subcommand == "show": | ||
| 1588 | stack = list(map(str, self.fm.thisdir.filter_stack)) | ||
| 1589 | pager = self.fm.ui.open_pager() | ||
| 1590 | pager.set_source(["Filter stack: "] + stack) | ||
| 1591 | pager.move(to=100, percentage=True) | ||
| 1592 | return | ||
| 1593 | else: | ||
| 1594 | self.fm.notify( | ||
| 1595 | "Unknown subcommand: {}".format(subcommand), | ||
| 1596 | bad=True | ||
| 1597 | ) | ||
| 1598 | return | ||
| 1599 | |||
| 1600 | self.fm.thisdir.refilter() | ||
| 1601 | |||
| 1602 | |||
| 1603 | class grep(Command): | ||
| 1604 | """:grep <string> | ||
| 1605 | |||
| 1606 | Looks for a string in all marked files or directories | ||
| 1607 | """ | ||
| 1608 | |||
| 1609 | def execute(self): | ||
| 1610 | if self.rest(1): | ||
| 1611 | action = ['grep', '--line-number'] | ||
| 1612 | action.extend(['-e', self.rest(1), '-r']) | ||
| 1613 | action.extend(f.path for f in self.fm.thistab.get_selection()) | ||
| 1614 | self.fm.execute_command(action, flags='p') | ||
| 1615 | |||
| 1616 | |||
| 1617 | class flat(Command): | ||
| 1618 | """ | ||
| 1619 | :flat <level> | ||
| 1620 | |||
| 1621 | Flattens the directory view up to the specified level. | ||
| 1622 | |||
| 1623 | -1 fully flattened | ||
| 1624 | 0 remove flattened view | ||
| 1625 | """ | ||
| 1626 | |||
| 1627 | def execute(self): | ||
| 1628 | try: | ||
| 1629 | level_str = self.rest(1) | ||
| 1630 | level = int(level_str) | ||
| 1631 | except ValueError: | ||
| 1632 | level = self.quantifier | ||
| 1633 | if level is None: | ||
| 1634 | self.fm.notify("Syntax: flat <level>", bad=True) | ||
| 1635 | return | ||
| 1636 | if level < -1: | ||
| 1637 | self.fm.notify("Need an integer number (-1, 0, 1, ...)", bad=True) | ||
| 1638 | self.fm.thisdir.unload() | ||
| 1639 | self.fm.thisdir.flat = level | ||
| 1640 | self.fm.thisdir.load_content() | ||
| 1641 | |||
| 1642 | # Version control commands | ||
| 1643 | # -------------------------------- | ||
| 1644 | |||
| 1645 | |||
| 1646 | class stage(Command): | ||
| 1647 | """ | ||
| 1648 | :stage | ||
| 1649 | |||
| 1650 | Stage selected files for the corresponding version control system | ||
| 1651 | """ | ||
| 1652 | |||
| 1653 | def execute(self): | ||
| 1654 | from ranger.ext.vcs import VcsError | ||
| 1655 | |||
| 1656 | if self.fm.thisdir.vcs and self.fm.thisdir.vcs.track: | ||
| 1657 | filelist = [f.path for f in self.fm.thistab.get_selection()] | ||
| 1658 | try: | ||
| 1659 | self.fm.thisdir.vcs.action_add(filelist) | ||
| 1660 | except VcsError as ex: | ||
| 1661 | self.fm.notify('Unable to stage files: {0}'.format(ex)) | ||
| 1662 | self.fm.ui.vcsthread.process(self.fm.thisdir) | ||
| 1663 | else: | ||
| 1664 | self.fm.notify('Unable to stage files: Not in repository') | ||
| 1665 | |||
| 1666 | |||
| 1667 | class unstage(Command): | ||
| 1668 | """ | ||
| 1669 | :unstage | ||
| 1670 | |||
| 1671 | Unstage selected files for the corresponding version control system | ||
| 1672 | """ | ||
| 1673 | |||
| 1674 | def execute(self): | ||
| 1675 | from ranger.ext.vcs import VcsError | ||
| 1676 | |||
| 1677 | if self.fm.thisdir.vcs and self.fm.thisdir.vcs.track: | ||
| 1678 | filelist = [f.path for f in self.fm.thistab.get_selection()] | ||
| 1679 | try: | ||
| 1680 | self.fm.thisdir.vcs.action_reset(filelist) | ||
| 1681 | except VcsError as ex: | ||
| 1682 | self.fm.notify('Unable to unstage files: {0}'.format(ex)) | ||
| 1683 | self.fm.ui.vcsthread.process(self.fm.thisdir) | ||
| 1684 | else: | ||
| 1685 | self.fm.notify('Unable to unstage files: Not in repository') | ||
| 1686 | |||
| 1687 | # Metadata commands | ||
| 1688 | # -------------------------------- | ||
| 1689 | |||
| 1690 | |||
| 1691 | class prompt_metadata(Command): | ||
| 1692 | """ | ||
| 1693 | :prompt_metadata <key1> [<key2> [<key3> ...]] | ||
| 1694 | |||
| 1695 | Prompt the user to input metadata for multiple keys in a row. | ||
| 1696 | """ | ||
| 1697 | |||
| 1698 | _command_name = "meta" | ||
| 1699 | _console_chain = None | ||
| 1700 | |||
| 1701 | def execute(self): | ||
| 1702 | prompt_metadata._console_chain = self.args[1:] | ||
| 1703 | self._process_command_stack() | ||
| 1704 | |||
| 1705 | def _process_command_stack(self): | ||
| 1706 | if prompt_metadata._console_chain: | ||
| 1707 | key = prompt_metadata._console_chain.pop() | ||
| 1708 | self._fill_console(key) | ||
| 1709 | else: | ||
| 1710 | for col in self.fm.ui.browser.columns: | ||
| 1711 | col.need_redraw = True | ||
| 1712 | |||
| 1713 | def _fill_console(self, key): | ||
| 1714 | metadata = self.fm.metadata.get_metadata(self.fm.thisfile.path) | ||
| 1715 | if key in metadata and metadata[key]: | ||
| 1716 | existing_value = metadata[key] | ||
| 1717 | else: | ||
| 1718 | existing_value = "" | ||
| 1719 | text = "%s %s %s" % (self._command_name, key, existing_value) | ||
| 1720 | self.fm.open_console(text, position=len(text)) | ||
| 1721 | |||
| 1722 | |||
| 1723 | class meta(prompt_metadata): | ||
| 1724 | """ | ||
| 1725 | :meta <key> [<value>] | ||
| 1726 | |||
| 1727 | Change metadata of a file. Deletes the key if value is empty. | ||
| 1728 | """ | ||
| 1729 | |||
| 1730 | def execute(self): | ||
| 1731 | key = self.arg(1) | ||
| 1732 | update_dict = dict() | ||
| 1733 | update_dict[key] = self.rest(2) | ||
| 1734 | selection = self.fm.thistab.get_selection() | ||
| 1735 | for fobj in selection: | ||
| 1736 | self.fm.metadata.set_metadata(fobj.path, update_dict) | ||
| 1737 | self._process_command_stack() | ||
| 1738 | |||
| 1739 | def tab(self, tabnum): | ||
| 1740 | key = self.arg(1) | ||
| 1741 | metadata = self.fm.metadata.get_metadata(self.fm.thisfile.path) | ||
| 1742 | if key in metadata and metadata[key]: | ||
| 1743 | return [" ".join([self.arg(0), self.arg(1), metadata[key]])] | ||
| 1744 | return [self.arg(0) + " " + k for k in sorted(metadata) | ||
| 1745 | if k.startswith(self.arg(1))] | ||
| 1746 | |||
| 1747 | |||
| 1748 | class linemode(default_linemode): | ||
| 1749 | """ | ||
| 1750 | :linemode <mode> | ||
| 1751 | |||
| 1752 | Change what is displayed as a filename. | ||
| 1753 | |||
| 1754 | - "mode" may be any of the defined linemodes (see: ranger.core.linemode). | ||
| 1755 | "normal" is mapped to "filename". | ||
| 1756 | """ | ||
| 1757 | |||
| 1758 | def execute(self): | ||
| 1759 | mode = self.arg(1) | ||
| 1760 | |||
| 1761 | if mode == "normal": | ||
| 1762 | from ranger.core.linemode import DEFAULT_LINEMODE | ||
| 1763 | mode = DEFAULT_LINEMODE | ||
| 1764 | |||
| 1765 | if mode not in self.fm.thisfile.linemode_dict: | ||
| 1766 | self.fm.notify("Unhandled linemode: `%s'" % mode, bad=True) | ||
| 1767 | return | ||
| 1768 | |||
| 1769 | self.fm.thisdir.set_linemode_of_children(mode) | ||
| 1770 | |||
| 1771 | # Ask the browsercolumns to redraw | ||
| 1772 | for col in self.fm.ui.browser.columns: | ||
| 1773 | col.need_redraw = True | ||
| 1774 | |||
| 1775 | |||
| 1776 | class yank(Command): | ||
| 1777 | """:yank [name|dir|path] | ||
| 1778 | |||
| 1779 | Copies the file's name (default), directory or path into both the primary X | ||
| 1780 | selection and the clipboard. | ||
| 1781 | """ | ||
| 1782 | |||
| 1783 | modes = { | ||
| 1784 | '': 'basename', | ||
| 1785 | 'name_without_extension': 'basename_without_extension', | ||
| 1786 | 'name': 'basename', | ||
| 1787 | 'dir': 'dirname', | ||
| 1788 | 'path': 'path', | ||
| 1789 | } | ||
| 1790 | |||
| 1791 | def execute(self): | ||
| 1792 | import subprocess | ||
| 1793 | |||
| 1794 | def clipboards(): | ||
| 1795 | from ranger.ext.get_executables import get_executables | ||
| 1796 | clipboard_managers = { | ||
| 1797 | 'xclip': [ | ||
| 1798 | ['xclip'], | ||
| 1799 | ['xclip', '-selection', 'clipboard'], | ||
| 1800 | ], | ||
| 1801 | 'xsel': [ | ||
| 1802 | ['xsel'], | ||
| 1803 | ['xsel', '-b'], | ||
| 1804 | ], | ||
| 1805 | 'pbcopy': [ | ||
| 1806 | ['pbcopy'], | ||
| 1807 | ], | ||
| 1808 | } | ||
| 1809 | ordered_managers = ['pbcopy', 'xclip', 'xsel'] | ||
| 1810 | executables = get_executables() | ||
| 1811 | for manager in ordered_managers: | ||
| 1812 | if manager in executables: | ||
| 1813 | return clipboard_managers[manager] | ||
| 1814 | return [] | ||
| 1815 | |||
| 1816 | clipboard_commands = clipboards() | ||
| 1817 | |||
| 1818 | mode = self.modes[self.arg(1)] | ||
| 1819 | selection = self.get_selection_attr(mode) | ||
| 1820 | |||
| 1821 | new_clipboard_contents = "\n".join(selection) | ||
| 1822 | for command in clipboard_commands: | ||
| 1823 | process = subprocess.Popen(command, universal_newlines=True, | ||
| 1824 | stdin=subprocess.PIPE) | ||
| 1825 | process.communicate(input=new_clipboard_contents) | ||
| 1826 | |||
| 1827 | def get_selection_attr(self, attr): | ||
| 1828 | return [getattr(item, attr) for item in | ||
| 1829 | self.fm.thistab.get_selection()] | ||
| 1830 | |||
| 1831 | def tab(self, tabnum): | ||
| 1832 | return ( | ||
| 1833 | self.start(1) + mode for mode | ||
| 1834 | in sorted(self.modes.keys()) | ||
| 1835 | if mode | ||
| 1836 | ) | ||
diff --git a/ranger/.config/ranger/rc.conf b/ranger/.config/ranger/rc.conf new file mode 100644 index 0000000..2722f18 --- /dev/null +++ b/ranger/.config/ranger/rc.conf | |||
| @@ -0,0 +1,726 @@ | |||
| 1 | # =================================================================== | ||
| 2 | # This file contains the default startup commands for ranger. | ||
| 3 | # To change them, it is recommended to create either /etc/ranger/rc.conf | ||
| 4 | # (system-wide) or ~/.config/ranger/rc.conf (per user) and add your custom | ||
| 5 | # commands there. | ||
| 6 | # | ||
| 7 | # If you copy this whole file there, you may want to set the environment | ||
| 8 | # variable RANGER_LOAD_DEFAULT_RC to FALSE to avoid loading it twice. | ||
| 9 | # | ||
| 10 | # The purpose of this file is mainly to define keybindings and settings. | ||
| 11 | # For running more complex python code, please create a plugin in "plugins/" or | ||
| 12 | # a command in "commands.py". | ||
| 13 | # | ||
| 14 | # Each line is a command that will be run before the user interface | ||
| 15 | # is initialized. As a result, you can not use commands which rely | ||
| 16 | # on the UI such as :delete or :mark. | ||
| 17 | # =================================================================== | ||
| 18 | |||
| 19 | # =================================================================== | ||
| 20 | # == Options | ||
| 21 | # =================================================================== | ||
| 22 | |||
| 23 | # Which viewmode should be used? Possible values are: | ||
| 24 | # miller: Use miller columns which show multiple levels of the hierarchy | ||
| 25 | # multipane: Midnight-commander like multipane view showing all tabs next | ||
| 26 | # to each other | ||
| 27 | set viewmode miller | ||
| 28 | #set viewmode multipane | ||
| 29 | |||
| 30 | # How many columns are there, and what are their relative widths? | ||
| 31 | set column_ratios 1,3,4 | ||
| 32 | |||
| 33 | # Which files should be hidden? (regular expression) | ||
| 34 | set hidden_filter ^\.|\.(?:pyc|pyo|bak|swp)$|^lost\+found$|^__(py)?cache__$ | ||
| 35 | |||
| 36 | # Show hidden files? You can toggle this by typing 'zh' | ||
| 37 | set show_hidden false | ||
| 38 | |||
| 39 | # Ask for a confirmation when running the "delete" command? | ||
| 40 | # Valid values are "always", "never", "multiple" (default) | ||
| 41 | # With "multiple", ranger will ask only if you delete multiple files at once. | ||
| 42 | set confirm_on_delete multiple | ||
| 43 | |||
| 44 | # Use non-default path for file preview script? | ||
| 45 | # ranger ships with scope.sh, a script that calls external programs (see | ||
| 46 | # README.md for dependencies) to preview images, archives, etc. | ||
| 47 | #set preview_script ~/.config/ranger/scope.sh | ||
| 48 | |||
| 49 | # Use the external preview script or display simple plain text or image previews? | ||
| 50 | set use_preview_script true | ||
| 51 | |||
| 52 | # Automatically count files in the directory, even before entering them? | ||
| 53 | set automatically_count_files true | ||
| 54 | |||
| 55 | # Open all images in this directory when running certain image viewers | ||
| 56 | # like feh or sxiv? You can still open selected files by marking them. | ||
| 57 | set open_all_images true | ||
| 58 | |||
| 59 | # Be aware of version control systems and display information. | ||
| 60 | set vcs_aware false | ||
| 61 | |||
| 62 | # State of the four backends git, hg, bzr, svn. The possible states are | ||
| 63 | # disabled, local (only show local info), enabled (show local and remote | ||
| 64 | # information). | ||
| 65 | set vcs_backend_git enabled | ||
| 66 | set vcs_backend_hg disabled | ||
| 67 | set vcs_backend_bzr disabled | ||
| 68 | set vcs_backend_svn disabled | ||
| 69 | |||
| 70 | # Use one of the supported image preview protocols | ||
| 71 | set preview_images true | ||
| 72 | |||
| 73 | # Set the preview image method. Supported methods: | ||
| 74 | # | ||
| 75 | # * w3m (default): | ||
| 76 | # Preview images in full color with the external command "w3mimgpreview"? | ||
| 77 | # This requires the console web browser "w3m" and a supported terminal. | ||
| 78 | # It has been successfully tested with "xterm" and "urxvt" without tmux. | ||
| 79 | # | ||
| 80 | # * iterm2: | ||
| 81 | # Preview images in full color using iTerm2 image previews | ||
| 82 | # (http://iterm2.com/images.html). This requires using iTerm2 compiled | ||
| 83 | # with image preview support. | ||
| 84 | # | ||
| 85 | # This feature relies on the dimensions of the terminal's font. By default, a | ||
| 86 | # width of 8 and height of 11 are used. To use other values, set the options | ||
| 87 | # iterm2_font_width and iterm2_font_height to the desired values. | ||
| 88 | # | ||
| 89 | # * terminology: | ||
| 90 | # Previews images in full color in the terminology terminal emulator. | ||
| 91 | # Supports a wide variety of formats, even vector graphics like svg. | ||
| 92 | # | ||
| 93 | # * urxvt: | ||
| 94 | # Preview images in full color using urxvt image backgrounds. This | ||
| 95 | # requires using urxvt compiled with pixbuf support. | ||
| 96 | # | ||
| 97 | # * urxvt-full: | ||
| 98 | # The same as urxvt but utilizing not only the preview pane but the | ||
| 99 | # whole terminal window. | ||
| 100 | # | ||
| 101 | # * kitty: | ||
| 102 | # Preview images in full color using kitty image protocol. | ||
| 103 | # Requires python PIL or pillow library. | ||
| 104 | # If ranger does not share the local filesystem with kitty | ||
| 105 | # the transfer method is changed to encode the whole image; | ||
| 106 | # while slower, this allows remote previews, | ||
| 107 | # for example during an ssh session. | ||
| 108 | # Tmux is unsupported. | ||
| 109 | set preview_images_method w3m | ||
| 110 | |||
| 111 | # Delay in seconds before displaying an image with the w3m method. | ||
| 112 | # Increase it in case of experiencing display corruption. | ||
| 113 | set w3m_delay 0.02 | ||
| 114 | |||
| 115 | # Default iTerm2 font size (see: preview_images_method: iterm2) | ||
| 116 | set iterm2_font_width 8 | ||
| 117 | set iterm2_font_height 11 | ||
| 118 | |||
| 119 | # Use a unicode "..." character to mark cut-off filenames? | ||
| 120 | set unicode_ellipsis false | ||
| 121 | |||
| 122 | # BIDI support - try to properly display file names in RTL languages (Hebrew, Arabic). | ||
| 123 | # Requires the python-bidi pip package | ||
| 124 | set bidi_support false | ||
| 125 | |||
| 126 | # Show dotfiles in the bookmark preview box? | ||
| 127 | set show_hidden_bookmarks true | ||
| 128 | |||
| 129 | # Which colorscheme to use? These colorschemes are available by default: | ||
| 130 | # default, jungle, snow, solarized | ||
| 131 | set colorscheme default | ||
| 132 | |||
| 133 | # Preview files on the rightmost column? | ||
| 134 | # And collapse (shrink) the last column if there is nothing to preview? | ||
| 135 | set preview_files true | ||
| 136 | set preview_directories true | ||
| 137 | set collapse_preview true | ||
| 138 | |||
| 139 | # Save the console history on exit? | ||
| 140 | set save_console_history true | ||
| 141 | |||
| 142 | # Draw the status bar on top of the browser window (default: bottom) | ||
| 143 | set status_bar_on_top false | ||
| 144 | |||
| 145 | # Draw a progress bar in the status bar which displays the average state of all | ||
| 146 | # currently running tasks which support progress bars? | ||
| 147 | set draw_progress_bar_in_status_bar true | ||
| 148 | |||
| 149 | # Draw borders around columns? (separators, outline, both, or none) | ||
| 150 | # Separators are vertical lines between columns. | ||
| 151 | # Outline draws a box around all the columns. | ||
| 152 | # Both combines the two. | ||
| 153 | set draw_borders none | ||
| 154 | |||
| 155 | # Display the directory name in tabs? | ||
| 156 | set dirname_in_tabs false | ||
| 157 | |||
| 158 | # Enable the mouse support? | ||
| 159 | set mouse_enabled true | ||
| 160 | |||
| 161 | # Display the file size in the main column or status bar? | ||
| 162 | set display_size_in_main_column true | ||
| 163 | set display_size_in_status_bar true | ||
| 164 | |||
| 165 | # Display the free disk space in the status bar? | ||
| 166 | set display_free_space_in_status_bar true | ||
| 167 | |||
| 168 | # Display files tags in all columns or only in main column? | ||
| 169 | set display_tags_in_all_columns true | ||
| 170 | |||
| 171 | # Set a title for the window? | ||
| 172 | set update_title false | ||
| 173 | |||
| 174 | # Set the title to "ranger" in the tmux program? | ||
| 175 | set update_tmux_title true | ||
| 176 | |||
| 177 | # Shorten the title if it gets long? The number defines how many | ||
| 178 | # directories are displayed at once, 0 turns off this feature. | ||
| 179 | set shorten_title 3 | ||
| 180 | |||
| 181 | # Show hostname in titlebar? | ||
| 182 | set hostname_in_titlebar true | ||
| 183 | |||
| 184 | # Abbreviate $HOME with ~ in the titlebar (first line) of ranger? | ||
| 185 | set tilde_in_titlebar false | ||
| 186 | |||
| 187 | # How many directory-changes or console-commands should be kept in history? | ||
| 188 | set max_history_size 20 | ||
| 189 | set max_console_history_size 50 | ||
| 190 | |||
| 191 | # Try to keep so much space between the top/bottom border when scrolling: | ||
| 192 | set scroll_offset 8 | ||
| 193 | |||
| 194 | # Flush the input after each key hit? (Noticeable when ranger lags) | ||
| 195 | set flushinput true | ||
| 196 | |||
| 197 | # Padding on the right when there's no preview? | ||
| 198 | # This allows you to click into the space to run the file. | ||
| 199 | set padding_right true | ||
| 200 | |||
| 201 | # Save bookmarks (used with mX and `X) instantly? | ||
| 202 | # This helps to synchronize bookmarks between multiple ranger | ||
| 203 | # instances but leads to *slight* performance loss. | ||
| 204 | # When false, bookmarks are saved when ranger is exited. | ||
| 205 | set autosave_bookmarks true | ||
| 206 | |||
| 207 | # Save the "`" bookmark to disk. This can be used to switch to the last | ||
| 208 | # directory by typing "``". | ||
| 209 | set save_backtick_bookmark true | ||
| 210 | |||
| 211 | # You can display the "real" cumulative size of directories by using the | ||
| 212 | # command :get_cumulative_size or typing "dc". The size is expensive to | ||
| 213 | # calculate and will not be updated automatically. You can choose | ||
| 214 | # to update it automatically though by turning on this option: | ||
| 215 | set autoupdate_cumulative_size false | ||
| 216 | |||
| 217 | # Turning this on makes sense for screen readers: | ||
| 218 | set show_cursor false | ||
| 219 | |||
| 220 | # One of: size, natural, basename, atime, ctime, mtime, type, random | ||
| 221 | set sort natural | ||
| 222 | |||
| 223 | # Additional sorting options | ||
| 224 | set sort_reverse false | ||
| 225 | set sort_case_insensitive true | ||
| 226 | set sort_directories_first true | ||
| 227 | set sort_unicode false | ||
| 228 | |||
| 229 | # Enable this if key combinations with the Alt Key don't work for you. | ||
| 230 | # (Especially on xterm) | ||
| 231 | set xterm_alt_key false | ||
| 232 | |||
| 233 | # Whether to include bookmarks in cd command | ||
| 234 | set cd_bookmarks true | ||
| 235 | |||
| 236 | # Changes case sensitivity for the cd command tab completion | ||
| 237 | set cd_tab_case sensitive | ||
| 238 | |||
| 239 | # Use fuzzy tab completion with the "cd" command. For example, | ||
| 240 | # ":cd /u/lo/b<tab>" expands to ":cd /usr/local/bin". | ||
| 241 | set cd_tab_fuzzy false | ||
| 242 | |||
| 243 | # Avoid previewing files larger than this size, in bytes. Use a value of 0 to | ||
| 244 | # disable this feature. | ||
| 245 | set preview_max_size 0 | ||
| 246 | |||
| 247 | # The key hint lists up to this size have their sublists expanded. | ||
| 248 | # Otherwise the submaps are replaced with "...". | ||
| 249 | set hint_collapse_threshold 10 | ||
| 250 | |||
| 251 | # Add the highlighted file to the path in the titlebar | ||
| 252 | set show_selection_in_titlebar true | ||
| 253 | |||
| 254 | # The delay that ranger idly waits for user input, in milliseconds, with a | ||
| 255 | # resolution of 100ms. Lower delay reduces lag between directory updates but | ||
| 256 | # increases CPU load. | ||
| 257 | set idle_delay 2000 | ||
| 258 | |||
| 259 | # When the metadata manager module looks for metadata, should it only look for | ||
| 260 | # a ".metadata.json" file in the current directory, or do a deep search and | ||
| 261 | # check all directories above the current one as well? | ||
| 262 | set metadata_deep_search false | ||
| 263 | |||
| 264 | # Clear all existing filters when leaving a directory | ||
| 265 | set clear_filters_on_dir_change false | ||
| 266 | |||
| 267 | # Disable displaying line numbers in main column. | ||
| 268 | # Possible values: false, absolute, relative. | ||
| 269 | set line_numbers false | ||
| 270 | |||
| 271 | # When line_numbers=relative show the absolute line number in the | ||
| 272 | # current line. | ||
| 273 | set relative_current_zero false | ||
| 274 | |||
| 275 | # Start line numbers from 1 instead of 0 | ||
| 276 | set one_indexed false | ||
| 277 | |||
| 278 | # Save tabs on exit | ||
| 279 | set save_tabs_on_exit false | ||
| 280 | |||
| 281 | # Enable scroll wrapping - moving down while on the last item will wrap around to | ||
| 282 | # the top and vice versa. | ||
| 283 | set wrap_scroll false | ||
| 284 | |||
| 285 | # Set the global_inode_type_filter to nothing. Possible options: d, f and l for | ||
| 286 | # directories, files and symlinks respectively. | ||
| 287 | set global_inode_type_filter | ||
| 288 | |||
| 289 | # This setting allows to freeze the list of files to save I/O bandwidth. It | ||
| 290 | # should be 'false' during start-up, but you can toggle it by pressing F. | ||
| 291 | set freeze_files false | ||
| 292 | |||
| 293 | # =================================================================== | ||
| 294 | # == Local Options | ||
| 295 | # =================================================================== | ||
| 296 | # You can set local options that only affect a single directory. | ||
| 297 | |||
| 298 | # Examples: | ||
| 299 | # setlocal path=~/downloads sort mtime | ||
| 300 | |||
| 301 | # =================================================================== | ||
| 302 | # == Command Aliases in the Console | ||
| 303 | # =================================================================== | ||
| 304 | |||
| 305 | alias e edit | ||
| 306 | alias q quit | ||
| 307 | alias q! quit! | ||
| 308 | alias qa quitall | ||
| 309 | alias qa! quitall! | ||
| 310 | alias qall quitall | ||
| 311 | alias qall! quitall! | ||
| 312 | alias setl setlocal | ||
| 313 | |||
| 314 | alias filter scout -prts | ||
| 315 | alias find scout -aets | ||
| 316 | alias mark scout -mr | ||
| 317 | alias unmark scout -Mr | ||
| 318 | alias search scout -rs | ||
| 319 | alias search_inc scout -rts | ||
| 320 | alias travel scout -aefklst | ||
| 321 | |||
| 322 | # =================================================================== | ||
| 323 | # == Define keys for the browser | ||
| 324 | # =================================================================== | ||
| 325 | |||
| 326 | # Basic | ||
| 327 | map Q quitall | ||
| 328 | map q quit | ||
| 329 | copymap q ZZ ZQ | ||
| 330 | |||
| 331 | map R reload_cwd | ||
| 332 | map F set freeze_files! | ||
| 333 | map <C-r> reset | ||
| 334 | map <C-l> redraw_window | ||
| 335 | map <C-c> abort | ||
| 336 | map <esc> change_mode normal | ||
| 337 | map ~ set viewmode! | ||
| 338 | |||
| 339 | map i display_file | ||
| 340 | map ? help | ||
| 341 | map W display_log | ||
| 342 | map w taskview_open | ||
| 343 | map S shell $SHELL | ||
| 344 | |||
| 345 | map : console | ||
| 346 | map ; console | ||
| 347 | map ! console shell%space | ||
| 348 | map @ console -p6 shell %%s | ||
| 349 | map # console shell -p%space | ||
| 350 | map s console shell%space | ||
| 351 | map r chain draw_possible_programs; console open_with%%space | ||
| 352 | map f console find%space | ||
| 353 | map cd console cd%space | ||
| 354 | |||
| 355 | map <C-p> chain console; eval fm.ui.console.history_move(-1) | ||
| 356 | |||
| 357 | # Change the line mode | ||
| 358 | map Mf linemode filename | ||
| 359 | map Mi linemode fileinfo | ||
| 360 | map Mm linemode mtime | ||
| 361 | map Mp linemode permissions | ||
| 362 | map Ms linemode sizemtime | ||
| 363 | map Mt linemode metatitle | ||
| 364 | |||
| 365 | # Tagging / Marking | ||
| 366 | map t tag_toggle | ||
| 367 | map ut tag_remove | ||
| 368 | map "<any> tag_toggle tag=%any | ||
| 369 | map <Space> mark_files toggle=True | ||
| 370 | map v mark_files all=True toggle=True | ||
| 371 | map uv mark_files all=True val=False | ||
| 372 | map V toggle_visual_mode | ||
| 373 | map uV toggle_visual_mode reverse=True | ||
| 374 | |||
| 375 | # For the nostalgics: Midnight Commander bindings | ||
| 376 | map <F1> help | ||
| 377 | map <F2> rename_append | ||
| 378 | map <F3> display_file | ||
| 379 | map <F4> edit | ||
| 380 | map <F5> copy | ||
| 381 | map <F6> cut | ||
| 382 | map <F7> console mkdir%space | ||
| 383 | map <F8> console delete | ||
| 384 | map <F10> exit | ||
| 385 | |||
| 386 | # In case you work on a keyboard with dvorak layout | ||
| 387 | map <UP> move up=1 | ||
| 388 | map <DOWN> move down=1 | ||
| 389 | map <LEFT> move left=1 | ||
| 390 | map <RIGHT> move right=1 | ||
| 391 | map <HOME> move to=0 | ||
| 392 | map <END> move to=-1 | ||
| 393 | map <PAGEDOWN> move down=1 pages=True | ||
| 394 | map <PAGEUP> move up=1 pages=True | ||
| 395 | map <CR> move right=1 | ||
| 396 | #map <DELETE> console delete | ||
| 397 | map <INSERT> console touch%space | ||
| 398 | |||
| 399 | # VIM-like | ||
| 400 | copymap <UP> k | ||
| 401 | copymap <DOWN> j | ||
| 402 | copymap <LEFT> h | ||
| 403 | copymap <RIGHT> l | ||
| 404 | copymap <HOME> gg | ||
| 405 | copymap <END> G | ||
| 406 | copymap <PAGEDOWN> <C-F> | ||
| 407 | copymap <PAGEUP> <C-B> | ||
| 408 | |||
| 409 | map J move down=0.5 pages=True | ||
| 410 | map K move up=0.5 pages=True | ||
| 411 | copymap J <C-D> | ||
| 412 | copymap K <C-U> | ||
| 413 | |||
| 414 | # Jumping around | ||
| 415 | map H history_go -1 | ||
| 416 | map L history_go 1 | ||
| 417 | map ] move_parent 1 | ||
| 418 | map [ move_parent -1 | ||
| 419 | map } traverse | ||
| 420 | map { traverse_backwards | ||
| 421 | map ) jump_non | ||
| 422 | |||
| 423 | map gh cd ~ | ||
| 424 | map ge cd /etc | ||
| 425 | map gw cd /home/ssaini/Pictures/Walls | ||
| 426 | map gu cd /usr | ||
| 427 | map gd cd /dev | ||
| 428 | map gl cd -r . | ||
| 429 | map gL cd -r %f | ||
| 430 | map go cd /opt | ||
| 431 | map gv cd /var | ||
| 432 | map gm cd /run/media | ||
| 433 | map gi eval fm.cd('/run/media/' + os.getenv('USER')) | ||
| 434 | map gM cd /mnt | ||
| 435 | map gs cd /srv | ||
| 436 | map gp cd /tmp | ||
| 437 | map gr cd / | ||
| 438 | map gR eval fm.cd(ranger.RANGERDIR) | ||
| 439 | map g/ cd / | ||
| 440 | map g? cd /usr/share/doc/ranger | ||
| 441 | |||
| 442 | # External Programs | ||
| 443 | map E edit | ||
| 444 | map du shell -p du --max-depth=1 -h --apparent-size | ||
| 445 | map dU shell -p du --max-depth=1 -h --apparent-size | sort -rh | ||
| 446 | map yp yank path | ||
| 447 | map yd yank dir | ||
| 448 | map yn yank name | ||
| 449 | map y. yank name_without_extension | ||
| 450 | |||
| 451 | # Filesystem Operations | ||
| 452 | map = chmod | ||
| 453 | |||
| 454 | map cw console rename%space | ||
| 455 | map a rename_append | ||
| 456 | map A eval fm.open_console('rename ' + fm.thisfile.relative_path.replace("%", "%%")) | ||
| 457 | map I eval fm.open_console('rename ' + fm.thisfile.relative_path.replace("%", "%%"), position=7) | ||
| 458 | |||
| 459 | map pp paste | ||
| 460 | map po paste overwrite=True | ||
| 461 | map pP paste append=True | ||
| 462 | map pO paste overwrite=True append=True | ||
| 463 | map pl paste_symlink relative=False | ||
| 464 | map pL paste_symlink relative=True | ||
| 465 | map phl paste_hardlink | ||
| 466 | map pht paste_hardlinked_subtree | ||
| 467 | |||
| 468 | map dD console delete | ||
| 469 | |||
| 470 | map dd cut | ||
| 471 | map ud uncut | ||
| 472 | map da cut mode=add | ||
| 473 | map dr cut mode=remove | ||
| 474 | map dt cut mode=toggle | ||
| 475 | |||
| 476 | map yy copy | ||
| 477 | map uy uncut | ||
| 478 | map ya copy mode=add | ||
| 479 | map yr copy mode=remove | ||
| 480 | map yt copy mode=toggle | ||
| 481 | |||
| 482 | # Temporary workarounds | ||
| 483 | map dgg eval fm.cut(dirarg=dict(to=0), narg=quantifier) | ||
| 484 | map dG eval fm.cut(dirarg=dict(to=-1), narg=quantifier) | ||
| 485 | map dj eval fm.cut(dirarg=dict(down=1), narg=quantifier) | ||
| 486 | map dk eval fm.cut(dirarg=dict(up=1), narg=quantifier) | ||
| 487 | map ygg eval fm.copy(dirarg=dict(to=0), narg=quantifier) | ||
| 488 | map yG eval fm.copy(dirarg=dict(to=-1), narg=quantifier) | ||
| 489 | map yj eval fm.copy(dirarg=dict(down=1), narg=quantifier) | ||
| 490 | map yk eval fm.copy(dirarg=dict(up=1), narg=quantifier) | ||
| 491 | |||
| 492 | # Searching | ||
| 493 | map / console search%space | ||
| 494 | map n search_next | ||
| 495 | map N search_next forward=False | ||
| 496 | map ct search_next order=tag | ||
| 497 | map cs search_next order=size | ||
| 498 | map ci search_next order=mimetype | ||
| 499 | map cc search_next order=ctime | ||
| 500 | map cm search_next order=mtime | ||
| 501 | map ca search_next order=atime | ||
| 502 | |||
| 503 | # Tabs | ||
| 504 | map <C-n> tab_new | ||
| 505 | map <C-w> tab_close | ||
| 506 | map <TAB> tab_move 1 | ||
| 507 | map <S-TAB> tab_move -1 | ||
| 508 | map <A-Right> tab_move 1 | ||
| 509 | map <A-Left> tab_move -1 | ||
| 510 | map gt tab_move 1 | ||
| 511 | map gT tab_move -1 | ||
| 512 | map gn tab_new | ||
| 513 | map gc tab_close | ||
| 514 | map uq tab_restore | ||
| 515 | map <a-1> tab_open 1 | ||
| 516 | map <a-2> tab_open 2 | ||
| 517 | map <a-3> tab_open 3 | ||
| 518 | map <a-4> tab_open 4 | ||
| 519 | map <a-5> tab_open 5 | ||
| 520 | map <a-6> tab_open 6 | ||
| 521 | map <a-7> tab_open 7 | ||
| 522 | map <a-8> tab_open 8 | ||
| 523 | map <a-9> tab_open 9 | ||
| 524 | map <a-r> tab_shift 1 | ||
| 525 | map <a-l> tab_shift -1 | ||
| 526 | |||
| 527 | # Sorting | ||
| 528 | map or set sort_reverse! | ||
| 529 | map oz set sort=random | ||
| 530 | map os chain set sort=size; set sort_reverse=False | ||
| 531 | map ob chain set sort=basename; set sort_reverse=False | ||
| 532 | map on chain set sort=natural; set sort_reverse=False | ||
| 533 | map om chain set sort=mtime; set sort_reverse=False | ||
| 534 | map oc chain set sort=ctime; set sort_reverse=False | ||
| 535 | map oa chain set sort=atime; set sort_reverse=False | ||
| 536 | map ot chain set sort=type; set sort_reverse=False | ||
| 537 | map oe chain set sort=extension; set sort_reverse=False | ||
| 538 | |||
| 539 | map oS chain set sort=size; set sort_reverse=True | ||
| 540 | map oB chain set sort=basename; set sort_reverse=True | ||
| 541 | map oN chain set sort=natural; set sort_reverse=True | ||
| 542 | map oM chain set sort=mtime; set sort_reverse=True | ||
| 543 | map oC chain set sort=ctime; set sort_reverse=True | ||
| 544 | map oA chain set sort=atime; set sort_reverse=True | ||
| 545 | map oT chain set sort=type; set sort_reverse=True | ||
| 546 | map oE chain set sort=extension; set sort_reverse=True | ||
| 547 | |||
| 548 | map dc get_cumulative_size | ||
| 549 | |||
| 550 | # Settings | ||
| 551 | map zc set collapse_preview! | ||
| 552 | map zd set sort_directories_first! | ||
| 553 | map zh set show_hidden! | ||
| 554 | map <C-h> set show_hidden! | ||
| 555 | copymap <C-h> <backspace> | ||
| 556 | copymap <backspace> <backspace2> | ||
| 557 | map zI set flushinput! | ||
| 558 | map zi set preview_images! | ||
| 559 | map zm set mouse_enabled! | ||
| 560 | map zp set preview_files! | ||
| 561 | map zP set preview_directories! | ||
| 562 | map zs set sort_case_insensitive! | ||
| 563 | map zu set autoupdate_cumulative_size! | ||
| 564 | map zv set use_preview_script! | ||
| 565 | map zf console filter%space | ||
| 566 | copymap zf zz | ||
| 567 | |||
| 568 | # Filter stack | ||
| 569 | map .n console filter_stack add name%space | ||
| 570 | map .m console filter_stack add mime%space | ||
| 571 | map .d filter_stack add type d | ||
| 572 | map .f filter_stack add type f | ||
| 573 | map .l filter_stack add type l | ||
| 574 | map .| filter_stack add or | ||
| 575 | map .& filter_stack add and | ||
| 576 | map .! filter_stack add not | ||
| 577 | map .r console filter_stack rotate | ||
| 578 | map .c filter_stack clear | ||
| 579 | map .* filter_stack decompose | ||
| 580 | map .p filter_stack pop | ||
| 581 | map .. filter_stack show | ||
| 582 | |||
| 583 | # Bookmarks | ||
| 584 | map `<any> enter_bookmark %any | ||
| 585 | map '<any> enter_bookmark %any | ||
| 586 | map m<any> set_bookmark %any | ||
| 587 | map um<any> unset_bookmark %any | ||
| 588 | |||
| 589 | map m<bg> draw_bookmarks | ||
| 590 | copymap m<bg> um<bg> `<bg> '<bg> | ||
| 591 | |||
| 592 | # Generate all the chmod bindings with some python help: | ||
| 593 | eval for arg in "rwxXst": cmd("map +u{0} shell -f chmod u+{0} %s".format(arg)) | ||
| 594 | eval for arg in "rwxXst": cmd("map +g{0} shell -f chmod g+{0} %s".format(arg)) | ||
| 595 | eval for arg in "rwxXst": cmd("map +o{0} shell -f chmod o+{0} %s".format(arg)) | ||
| 596 | eval for arg in "rwxXst": cmd("map +a{0} shell -f chmod a+{0} %s".format(arg)) | ||
| 597 | eval for arg in "rwxXst": cmd("map +{0} shell -f chmod u+{0} %s".format(arg)) | ||
| 598 | |||
| 599 | eval for arg in "rwxXst": cmd("map -u{0} shell -f chmod u-{0} %s".format(arg)) | ||
| 600 | eval for arg in "rwxXst": cmd("map -g{0} shell -f chmod g-{0} %s".format(arg)) | ||
| 601 | eval for arg in "rwxXst": cmd("map -o{0} shell -f chmod o-{0} %s".format(arg)) | ||
| 602 | eval for arg in "rwxXst": cmd("map -a{0} shell -f chmod a-{0} %s".format(arg)) | ||
| 603 | eval for arg in "rwxXst": cmd("map -{0} shell -f chmod u-{0} %s".format(arg)) | ||
| 604 | |||
| 605 | # =================================================================== | ||
| 606 | # == Define keys for the console | ||
| 607 | # =================================================================== | ||
| 608 | # Note: Unmapped keys are passed directly to the console. | ||
| 609 | |||
| 610 | # Basic | ||
| 611 | cmap <tab> eval fm.ui.console.tab() | ||
| 612 | cmap <s-tab> eval fm.ui.console.tab(-1) | ||
| 613 | cmap <ESC> eval fm.ui.console.close() | ||
| 614 | cmap <CR> eval fm.ui.console.execute() | ||
| 615 | cmap <C-l> redraw_window | ||
| 616 | |||
| 617 | copycmap <ESC> <C-c> | ||
| 618 | copycmap <CR> <C-j> | ||
| 619 | |||
| 620 | # Move around | ||
| 621 | cmap <up> eval fm.ui.console.history_move(-1) | ||
| 622 | cmap <down> eval fm.ui.console.history_move(1) | ||
| 623 | cmap <left> eval fm.ui.console.move(left=1) | ||
| 624 | cmap <right> eval fm.ui.console.move(right=1) | ||
| 625 | cmap <home> eval fm.ui.console.move(right=0, absolute=True) | ||
| 626 | cmap <end> eval fm.ui.console.move(right=-1, absolute=True) | ||
| 627 | cmap <a-b> eval fm.ui.console.move_word(left=1) | ||
| 628 | cmap <a-f> eval fm.ui.console.move_word(right=1) | ||
| 629 | |||
| 630 | copycmap <a-b> <a-left> | ||
| 631 | copycmap <a-f> <a-right> | ||
| 632 | |||
| 633 | # Line Editing | ||
| 634 | cmap <backspace> eval fm.ui.console.delete(-1) | ||
| 635 | cmap <delete> eval fm.ui.console.delete(0) | ||
| 636 | cmap <C-w> eval fm.ui.console.delete_word() | ||
| 637 | cmap <A-d> eval fm.ui.console.delete_word(backward=False) | ||
| 638 | cmap <C-k> eval fm.ui.console.delete_rest(1) | ||
| 639 | cmap <C-u> eval fm.ui.console.delete_rest(-1) | ||
| 640 | cmap <C-y> eval fm.ui.console.paste() | ||
| 641 | |||
| 642 | # And of course the emacs way | ||
| 643 | copycmap <ESC> <C-g> | ||
| 644 | copycmap <up> <C-p> | ||
| 645 | copycmap <down> <C-n> | ||
| 646 | copycmap <left> <C-b> | ||
| 647 | copycmap <right> <C-f> | ||
| 648 | copycmap <home> <C-a> | ||
| 649 | copycmap <end> <C-e> | ||
| 650 | copycmap <delete> <C-d> | ||
| 651 | copycmap <backspace> <C-h> | ||
| 652 | |||
| 653 | # Note: There are multiple ways to express backspaces. <backspace> (code 263) | ||
| 654 | # and <backspace2> (code 127). To be sure, use both. | ||
| 655 | copycmap <backspace> <backspace2> | ||
| 656 | |||
| 657 | # This special expression allows typing in numerals: | ||
| 658 | cmap <allow_quantifiers> false | ||
| 659 | |||
| 660 | # =================================================================== | ||
| 661 | # == Pager Keybindings | ||
| 662 | # =================================================================== | ||
| 663 | |||
| 664 | # Movement | ||
| 665 | pmap <down> pager_move down=1 | ||
| 666 | pmap <up> pager_move up=1 | ||
| 667 | pmap <left> pager_move left=4 | ||
| 668 | pmap <right> pager_move right=4 | ||
| 669 | pmap <home> pager_move to=0 | ||
| 670 | pmap <end> pager_move to=-1 | ||
| 671 | pmap <pagedown> pager_move down=1.0 pages=True | ||
| 672 | pmap <pageup> pager_move up=1.0 pages=True | ||
| 673 | pmap <C-d> pager_move down=0.5 pages=True | ||
| 674 | pmap <C-u> pager_move up=0.5 pages=True | ||
| 675 | |||
| 676 | copypmap <UP> k <C-p> | ||
| 677 | copypmap <DOWN> j <C-n> <CR> | ||
| 678 | copypmap <LEFT> h | ||
| 679 | copypmap <RIGHT> l | ||
| 680 | copypmap <HOME> g | ||
| 681 | copypmap <END> G | ||
| 682 | copypmap <C-d> d | ||
| 683 | copypmap <C-u> u | ||
| 684 | copypmap <PAGEDOWN> n f <C-F> <Space> | ||
| 685 | copypmap <PAGEUP> p b <C-B> | ||
| 686 | |||
| 687 | # Basic | ||
| 688 | pmap <C-l> redraw_window | ||
| 689 | pmap <ESC> pager_close | ||
| 690 | copypmap <ESC> q Q i <F3> | ||
| 691 | pmap E edit_file | ||
| 692 | |||
| 693 | # =================================================================== | ||
| 694 | # == Taskview Keybindings | ||
| 695 | # =================================================================== | ||
| 696 | |||
| 697 | # Movement | ||
| 698 | tmap <up> taskview_move up=1 | ||
| 699 | tmap <down> taskview_move down=1 | ||
| 700 | tmap <home> taskview_move to=0 | ||
| 701 | tmap <end> taskview_move to=-1 | ||
| 702 | tmap <pagedown> taskview_move down=1.0 pages=True | ||
| 703 | tmap <pageup> taskview_move up=1.0 pages=True | ||
| 704 | tmap <C-d> taskview_move down=0.5 pages=True | ||
| 705 | tmap <C-u> taskview_move up=0.5 pages=True | ||
| 706 | |||
| 707 | copytmap <UP> k <C-p> | ||
| 708 | copytmap <DOWN> j <C-n> <CR> | ||
| 709 | copytmap <HOME> g | ||
| 710 | copytmap <END> G | ||
| 711 | copytmap <C-u> u | ||
| 712 | copytmap <PAGEDOWN> n f <C-F> <Space> | ||
| 713 | copytmap <PAGEUP> p b <C-B> | ||
| 714 | |||
| 715 | # Changing priority and deleting tasks | ||
| 716 | tmap J eval -q fm.ui.taskview.task_move(-1) | ||
| 717 | tmap K eval -q fm.ui.taskview.task_move(0) | ||
| 718 | tmap dd eval -q fm.ui.taskview.task_remove() | ||
| 719 | tmap <pagedown> eval -q fm.ui.taskview.task_move(-1) | ||
| 720 | tmap <pageup> eval -q fm.ui.taskview.task_move(0) | ||
| 721 | tmap <delete> eval -q fm.ui.taskview.task_remove() | ||
| 722 | |||
| 723 | # Basic | ||
| 724 | tmap <C-l> redraw_window | ||
| 725 | tmap <ESC> taskview_close | ||
| 726 | copytmap <ESC> q Q w <C-c> | ||
diff --git a/ranger/.config/ranger/rifle.conf b/ranger/.config/ranger/rifle.conf new file mode 100644 index 0000000..babdcda --- /dev/null +++ b/ranger/.config/ranger/rifle.conf | |||
| @@ -0,0 +1,256 @@ | |||
| 1 | # vim: ft=cfg | ||
| 2 | # | ||
| 3 | # This is the configuration file of "rifle", ranger's file executor/opener. | ||
| 4 | # Each line consists of conditions and a command. For each line the conditions | ||
| 5 | # are checked and if they are met, the respective command is run. | ||
| 6 | # | ||
| 7 | # Syntax: | ||
| 8 | # <condition1> , <condition2> , ... = command | ||
| 9 | # | ||
| 10 | # The command can contain these environment variables: | ||
| 11 | # $1-$9 | The n-th selected file | ||
| 12 | # $@ | All selected files | ||
| 13 | # | ||
| 14 | # If you use the special command "ask", rifle will ask you what program to run. | ||
| 15 | # | ||
| 16 | # Prefixing a condition with "!" will negate its result. | ||
| 17 | # These conditions are currently supported: | ||
| 18 | # match <regexp> | The regexp matches $1 | ||
| 19 | # ext <regexp> | The regexp matches the extension of $1 | ||
| 20 | # mime <regexp> | The regexp matches the mime type of $1 | ||
| 21 | # name <regexp> | The regexp matches the basename of $1 | ||
| 22 | # path <regexp> | The regexp matches the absolute path of $1 | ||
| 23 | # has <program> | The program is installed (i.e. located in $PATH) | ||
| 24 | # env <variable> | The environment variable "variable" is non-empty | ||
| 25 | # file | $1 is a file | ||
| 26 | # directory | $1 is a directory | ||
| 27 | # number <n> | change the number of this command to n | ||
| 28 | # terminal | stdin, stderr and stdout are connected to a terminal | ||
| 29 | # X | $DISPLAY is not empty (i.e. Xorg runs) | ||
| 30 | # | ||
| 31 | # There are also pseudo-conditions which have a "side effect": | ||
| 32 | # flag <flags> | Change how the program is run. See below. | ||
| 33 | # label <label> | Assign a label or name to the command so it can | ||
| 34 | # | be started with :open_with <label> in ranger | ||
| 35 | # | or `rifle -p <label>` in the standalone executable. | ||
| 36 | # else | Always true. | ||
| 37 | # | ||
| 38 | # Flags are single characters which slightly transform the command: | ||
| 39 | # f | Fork the program, make it run in the background. | ||
| 40 | # | New command = setsid $command >& /dev/null & | ||
| 41 | # r | Execute the command with root permissions | ||
| 42 | # | New command = sudo $command | ||
| 43 | # t | Run the program in a new terminal. If $TERMCMD is not defined, | ||
| 44 | # | rifle will attempt to extract it from $TERM. | ||
| 45 | # | New command = $TERMCMD -e $command | ||
| 46 | # Note: The "New command" serves only as an illustration, the exact | ||
| 47 | # implementation may differ. | ||
| 48 | # Note: When using rifle in ranger, there is an additional flag "c" for | ||
| 49 | # only running the current file even if you have marked multiple files. | ||
| 50 | |||
| 51 | #------------------------------------------- | ||
| 52 | # Websites | ||
| 53 | #------------------------------------------- | ||
| 54 | # Rarely installed browsers get higher priority; It is assumed that if you | ||
| 55 | # install a rare browser, you probably use it. Firefox/konqueror/w3m on the | ||
| 56 | # other hand are often only installed as fallback browsers. | ||
| 57 | ext x?html?, has surf, X, flag f = surf -- file://"$1" | ||
| 58 | ext x?html?, has vimprobable, X, flag f = vimprobable -- "$@" | ||
| 59 | ext x?html?, has vimprobable2, X, flag f = vimprobable2 -- "$@" | ||
| 60 | ext x?html?, has qutebrowser, X, flag f = qutebrowser -- "$@" | ||
| 61 | ext x?html?, has dwb, X, flag f = dwb -- "$@" | ||
| 62 | ext x?html?, has jumanji, X, flag f = jumanji -- "$@" | ||
| 63 | ext x?html?, has luakit, X, flag f = luakit -- "$@" | ||
| 64 | ext x?html?, has uzbl, X, flag f = uzbl -- "$@" | ||
| 65 | ext x?html?, has uzbl-tabbed, X, flag f = uzbl-tabbed -- "$@" | ||
| 66 | ext x?html?, has uzbl-browser, X, flag f = uzbl-browser -- "$@" | ||
| 67 | ext x?html?, has uzbl-core, X, flag f = uzbl-core -- "$@" | ||
| 68 | ext x?html?, has midori, X, flag f = midori -- "$@" | ||
| 69 | ext x?html?, has chromium-browser, X, flag f = chromium-browser -- "$@" | ||
| 70 | ext x?html?, has chromium, X, flag f = chromium -- "$@" | ||
| 71 | ext x?html?, has google-chrome, X, flag f = google-chrome -- "$@" | ||
| 72 | ext x?html?, has opera, X, flag f = opera -- "$@" | ||
| 73 | ext x?html?, has firefox, X, flag f = firefox -- "$@" | ||
| 74 | ext x?html?, has seamonkey, X, flag f = seamonkey -- "$@" | ||
| 75 | ext x?html?, has iceweasel, X, flag f = iceweasel -- "$@" | ||
| 76 | ext x?html?, has epiphany, X, flag f = epiphany -- "$@" | ||
| 77 | ext x?html?, has konqueror, X, flag f = konqueror -- "$@" | ||
| 78 | ext x?html?, has elinks, terminal = elinks "$@" | ||
| 79 | ext x?html?, has links2, terminal = links2 "$@" | ||
| 80 | ext x?html?, has links, terminal = links "$@" | ||
| 81 | ext x?html?, has lynx, terminal = lynx -- "$@" | ||
| 82 | ext x?html?, has w3m, terminal = w3m "$@" | ||
| 83 | |||
| 84 | #------------------------------------------- | ||
| 85 | # Misc | ||
| 86 | #------------------------------------------- | ||
| 87 | # Define the "editor" for text files as first action | ||
| 88 | mime ^text, label editor = ${VISUAL:-$EDITOR} -- "$@" | ||
| 89 | mime ^text, label pager = "$PAGER" -- "$@" | ||
| 90 | !mime ^text, label editor, ext xml|json|csv|tex|py|pl|rb|js|sh|php = ${VISUAL:-$EDITOR} -- "$@" | ||
| 91 | !mime ^text, label pager, ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@" | ||
| 92 | |||
| 93 | ext 1 = man "$1" | ||
| 94 | ext s[wmf]c, has zsnes, X = zsnes "$1" | ||
| 95 | ext s[wmf]c, has snes9x-gtk,X = snes9x-gtk "$1" | ||
| 96 | ext nes, has fceux, X = fceux "$1" | ||
| 97 | ext exe = wine "$1" | ||
| 98 | name ^[mM]akefile$ = make | ||
| 99 | |||
| 100 | #-------------------------------------------- | ||
| 101 | # Code | ||
| 102 | #------------------------------------------- | ||
| 103 | ext py = python -- "$1" | ||
| 104 | ext pl = perl -- "$1" | ||
| 105 | ext rb = ruby -- "$1" | ||
| 106 | ext js = node -- "$1" | ||
| 107 | ext sh = sh -- "$1" | ||
| 108 | ext php = php -- "$1" | ||
| 109 | |||
| 110 | #-------------------------------------------- | ||
| 111 | # Audio without X | ||
| 112 | #------------------------------------------- | ||
| 113 | mime ^audio|ogg$, terminal, has mpv = mpv -- "$@" | ||
| 114 | mime ^audio|ogg$, terminal, has mplayer2 = mplayer2 -- "$@" | ||
| 115 | mime ^audio|ogg$, terminal, has mplayer = mplayer -- "$@" | ||
| 116 | ext midi?, terminal, has wildmidi = wildmidi -- "$@" | ||
| 117 | |||
| 118 | #-------------------------------------------- | ||
| 119 | # Video/Audio with a GUI | ||
| 120 | #------------------------------------------- | ||
| 121 | mime ^video|audio, has gmplayer, X, flag f = gmplayer -- "$@" | ||
| 122 | mime ^video|audio, has smplayer, X, flag f = smplayer "$@" | ||
| 123 | mime ^video, has mpv, X, flag f = mpv -- "$@" | ||
| 124 | mime ^video, has mpv, X, flag f = mpv --fs -- "$@" | ||
| 125 | mime ^video, has mplayer2, X, flag f = mplayer2 -- "$@" | ||
| 126 | mime ^video, has mplayer2, X, flag f = mplayer2 -fs -- "$@" | ||
| 127 | mime ^video, has mplayer, X, flag f = mplayer -- "$@" | ||
| 128 | mime ^video, has mplayer, X, flag f = mplayer -fs -- "$@" | ||
| 129 | mime ^video|audio, has vlc, X, flag f = vlc -- "$@" | ||
| 130 | mime ^video|audio, has totem, X, flag f = totem -- "$@" | ||
| 131 | mime ^video|audio, has totem, X, flag f = totem --fullscreen -- "$@" | ||
| 132 | |||
| 133 | #-------------------------------------------- | ||
| 134 | # Video without X: | ||
| 135 | #------------------------------------------- | ||
| 136 | mime ^video, terminal, !X, has mpv = mpv -- "$@" | ||
| 137 | mime ^video, terminal, !X, has mplayer2 = mplayer2 -- "$@" | ||
| 138 | mime ^video, terminal, !X, has mplayer = mplayer -- "$@" | ||
| 139 | |||
| 140 | #------------------------------------------- | ||
| 141 | # Documents | ||
| 142 | #------------------------------------------- | ||
| 143 | ext pdf, has llpp, X, flag f = llpp "$@" | ||
| 144 | ext pdf, has zathura, X, flag f = zathura -- "$@" | ||
| 145 | ext pdf, has mupdf, X, flag f = mupdf "$@" | ||
| 146 | ext pdf, has mupdf-x11,X, flag f = mupdf-x11 "$@" | ||
| 147 | ext pdf, has apvlv, X, flag f = apvlv -- "$@" | ||
| 148 | ext pdf, has xpdf, X, flag f = xpdf -- "$@" | ||
| 149 | ext pdf, has evince, X, flag f = evince -- "$@" | ||
| 150 | ext pdf, has atril, X, flag f = atril -- "$@" | ||
| 151 | ext pdf, has okular, X, flag f = okular -- "$@" | ||
| 152 | ext pdf, has epdfview, X, flag f = epdfview -- "$@" | ||
| 153 | ext pdf, has qpdfview, X, flag f = qpdfview "$@" | ||
| 154 | ext pdf, has open, X, flag f = open "$@" | ||
| 155 | |||
| 156 | ext docx?, has catdoc, terminal = catdoc -- "$@" | "$PAGER" | ||
| 157 | |||
| 158 | ext sxc|xlsx?|xlt|xlw|gnm|gnumeric, has gnumeric, X, flag f = gnumeric -- "$@" | ||
| 159 | ext sxc|xlsx?|xlt|xlw|gnm|gnumeric, has kspread, X, flag f = kspread -- "$@" | ||
| 160 | ext pptx?|od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has libreoffice, X, flag f = libreoffice "$@" | ||
| 161 | ext pptx?|od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has soffice, X, flag f = soffice "$@" | ||
| 162 | ext pptx?|od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has ooffice, X, flag f = ooffice "$@" | ||
| 163 | |||
| 164 | ext djvu, has zathura,X, flag f = zathura -- "$@" | ||
| 165 | ext djvu, has evince, X, flag f = evince -- "$@" | ||
| 166 | ext djvu, has atril, X, flag f = atril -- "$@" | ||
| 167 | ext djvu, has djview, X, flag f = djview -- "$@" | ||
| 168 | |||
| 169 | ext epub, has ebook-viewer, X, flag f = ebook-viewer -- "$@" | ||
| 170 | ext mobi, has ebook-viewer, X, flag f = ebook-viewer -- "$@" | ||
| 171 | |||
| 172 | #------------------------------------------- | ||
| 173 | # Image Viewing: | ||
| 174 | #------------------------------------------- | ||
| 175 | mime ^image/svg, has inkscape, X, flag f = inkscape -- "$@" | ||
| 176 | mime ^image/svg, has display, X, flag f = display -- "$@" | ||
| 177 | |||
| 178 | mime ^image, has pqiv, X, flag f = pqiv -- "$@" | ||
| 179 | mime ^image, has sxiv, X, flag f = sxiv -- "$@" | ||
| 180 | mime ^image, has feh, X, flag f = feh -- "$@" | ||
| 181 | mime ^image, has mirage, X, flag f = mirage -- "$@" | ||
| 182 | mime ^image, has ristretto, X, flag f = ristretto "$@" | ||
| 183 | mime ^image, has eog, X, flag f = eog -- "$@" | ||
| 184 | mime ^image, has eom, X, flag f = eom -- "$@" | ||
| 185 | mime ^image, has nomacs, X, flag f = nomacs -- "$@" | ||
| 186 | mime ^image, has geeqie, X, flag f = geeqie -- "$@" | ||
| 187 | mime ^image, has gwenview, X, flag f = gwenview -- "$@" | ||
| 188 | mime ^image, has gimp, X, flag f = gimp -- "$@" | ||
| 189 | ext xcf, X, flag f = gimp -- "$@" | ||
| 190 | |||
| 191 | #------------------------------------------- | ||
| 192 | # Archives | ||
| 193 | #------------------------------------------- | ||
| 194 | |||
| 195 | # avoid password prompt by providing empty password | ||
| 196 | ext 7z, has 7z = 7z -p l "$@" | "$PAGER" | ||
| 197 | # This requires atool | ||
| 198 | ext ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has atool = atool --list --each -- "$@" | "$PAGER" | ||
| 199 | ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has atool = atool --list --each -- "$@" | "$PAGER" | ||
| 200 | ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has atool = atool --extract --each -- "$@" | ||
| 201 | ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has atool = atool --extract --each -- "$@" | ||
| 202 | |||
| 203 | # Listing and extracting archives without atool: | ||
| 204 | ext tar|gz|bz2|xz, has tar = tar vvtf "$1" | "$PAGER" | ||
| 205 | ext tar|gz|bz2|xz, has tar = for file in "$@"; do tar vvxf "$file"; done | ||
| 206 | ext bz2, has bzip2 = for file in "$@"; do bzip2 -dk "$file"; done | ||
| 207 | ext zip, has unzip = unzip -l "$1" | less | ||
| 208 | ext zip, has unzip = for file in "$@"; do unzip -d "${file%.*}" "$file"; done | ||
| 209 | ext ace, has unace = unace l "$1" | less | ||
| 210 | ext ace, has unace = for file in "$@"; do unace e "$file"; done | ||
| 211 | ext rar, has unrar = unrar l "$1" | less | ||
| 212 | ext rar, has unrar = for file in "$@"; do unrar x "$file"; done | ||
| 213 | |||
| 214 | #------------------------------------------- | ||
| 215 | # Flag t fallback terminals | ||
| 216 | #------------------------------------------- | ||
| 217 | # Rarely installed terminal emulators get higher priority; It is assumed that | ||
| 218 | # if you install a rare terminal emulator, you probably use it. | ||
| 219 | # gnome-terminal/konsole/xterm on the other hand are often installed as part of | ||
| 220 | # a desktop environment or as fallback terminal emulators. | ||
| 221 | mime ^ranger/x-terminal-emulator, has terminology = terminology -e "$@" | ||
| 222 | mime ^ranger/x-terminal-emulator, has kitty = kitty -- "$@" | ||
| 223 | mime ^ranger/x-terminal-emulator, has alacritty = alacritty -e "$@" | ||
| 224 | mime ^ranger/x-terminal-emulator, has sakura = sakura -e "$@" | ||
| 225 | mime ^ranger/x-terminal-emulator, has lilyterm = lilyterm -e "$@" | ||
| 226 | #mime ^ranger/x-terminal-emulator, has cool-retro-term = cool-retro-term -e "$@" | ||
| 227 | mime ^ranger/x-terminal-emulator, has termite = termite -x '"$@"' | ||
| 228 | #mime ^ranger/x-terminal-emulator, has yakuake = yakuake -e "$@" | ||
| 229 | mime ^ranger/x-terminal-emulator, has guake = guake -ne "$@" | ||
| 230 | mime ^ranger/x-terminal-emulator, has tilda = tilda -c "$@" | ||
| 231 | mime ^ranger/x-terminal-emulator, has st = st -e "$@" | ||
| 232 | mime ^ranger/x-terminal-emulator, has terminator = terminator -x "$@" | ||
| 233 | mime ^ranger/x-terminal-emulator, has urxvt = urxvt -e "$@" | ||
| 234 | mime ^ranger/x-terminal-emulator, has pantheon-terminal = pantheon-terminal -e "$@" | ||
| 235 | mime ^ranger/x-terminal-emulator, has lxterminal = lxterminal -e "$@" | ||
| 236 | mime ^ranger/x-terminal-emulator, has mate-terminal = mate-terminal -x "$@" | ||
| 237 | mime ^ranger/x-terminal-emulator, has xfce4-terminal = xfce4-terminal -x "$@" | ||
| 238 | mime ^ranger/x-terminal-emulator, has konsole = konsole -e "$@" | ||
| 239 | mime ^ranger/x-terminal-emulator, has gnome-terminal = gnome-terminal -- "$@" | ||
| 240 | mime ^ranger/x-terminal-emulator, has xterm = xterm -e "$@" | ||
| 241 | |||
| 242 | #------------------------------------------- | ||
| 243 | # Misc | ||
| 244 | #------------------------------------------- | ||
| 245 | label wallpaper, number 11, mime ^image, has feh, X = feh --bg-scale "$1" | ||
| 246 | label wallpaper, number 12, mime ^image, has feh, X = feh --bg-tile "$1" | ||
| 247 | label wallpaper, number 13, mime ^image, has feh, X = feh --bg-center "$1" | ||
| 248 | label wallpaper, number 14, mime ^image, has feh, X = feh --bg-fill "$1" | ||
| 249 | |||
| 250 | # Define the editor for non-text files + pager as last action | ||
| 251 | !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = ask | ||
| 252 | label editor, !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = ${VISUAL:-$EDITOR} -- "$@" | ||
| 253 | label pager, !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@" | ||
| 254 | |||
| 255 | # The very last action, so that it's never triggered accidentally, is to execute a program: | ||
| 256 | mime application/x-executable = "$1" | ||
diff --git a/ranger/.config/ranger/scope.sh b/ranger/.config/ranger/scope.sh new file mode 100755 index 0000000..13a25b4 --- /dev/null +++ b/ranger/.config/ranger/scope.sh | |||
| @@ -0,0 +1,216 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | |||
| 3 | set -o noclobber -o noglob -o nounset -o pipefail | ||
| 4 | IFS=$'\n' | ||
| 5 | |||
| 6 | # If the option `use_preview_script` is set to `true`, | ||
| 7 | # then this script will be called and its output will be displayed in ranger. | ||
| 8 | # ANSI color codes are supported. | ||
| 9 | # STDIN is disabled, so interactive scripts won't work properly | ||
| 10 | |||
| 11 | # This script is considered a configuration file and must be updated manually. | ||
| 12 | # It will be left untouched if you upgrade ranger. | ||
| 13 | |||
| 14 | # Meanings of exit codes: | ||
| 15 | # code | meaning | action of ranger | ||
| 16 | # -----+------------+------------------------------------------- | ||
| 17 | # 0 | success | Display stdout as preview | ||
| 18 | # 1 | no preview | Display no preview at all | ||
| 19 | # 2 | plain text | Display the plain content of the file | ||
| 20 | # 3 | fix width | Don't reload when width changes | ||
| 21 | # 4 | fix height | Don't reload when height changes | ||
| 22 | # 5 | fix both | Don't ever reload | ||
| 23 | # 6 | image | Display the image `$IMAGE_CACHE_PATH` points to as an image preview | ||
| 24 | # 7 | image | Display the file directly as an image | ||
| 25 | |||
| 26 | # Script arguments | ||
| 27 | FILE_PATH="${1}" # Full path of the highlighted file | ||
| 28 | PV_WIDTH="${2}" # Width of the preview pane (number of fitting characters) | ||
| 29 | PV_HEIGHT="${3}" # Height of the preview pane (number of fitting characters) | ||
| 30 | IMAGE_CACHE_PATH="${4}" # Full path that should be used to cache image preview | ||
| 31 | PV_IMAGE_ENABLED="${5}" # 'True' if image previews are enabled, 'False' otherwise. | ||
| 32 | |||
| 33 | FILE_EXTENSION="${FILE_PATH##*.}" | ||
| 34 | FILE_EXTENSION_LOWER=$(echo ${FILE_EXTENSION} | tr '[:upper:]' '[:lower:]') | ||
| 35 | |||
| 36 | # Settings | ||
| 37 | HIGHLIGHT_SIZE_MAX=262143 # 256KiB | ||
| 38 | HIGHLIGHT_TABWIDTH=8 | ||
| 39 | HIGHLIGHT_STYLE='pablo' | ||
| 40 | PYGMENTIZE_STYLE='autumn' | ||
| 41 | |||
| 42 | |||
| 43 | handle_extension() { | ||
| 44 | case "${FILE_EXTENSION_LOWER}" in | ||
| 45 | # Archive | ||
| 46 | a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\ | ||
| 47 | rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip) | ||
| 48 | atool --list -- "${FILE_PATH}" && exit 5 | ||
| 49 | bsdtar --list --file "${FILE_PATH}" && exit 5 | ||
| 50 | exit 1;; | ||
| 51 | rar) | ||
| 52 | # Avoid password prompt by providing empty password | ||
| 53 | unrar lt -p- -- "${FILE_PATH}" && exit 5 | ||
| 54 | exit 1;; | ||
| 55 | 7z) | ||
| 56 | # Avoid password prompt by providing empty password | ||
| 57 | 7z l -p -- "${FILE_PATH}" && exit 5 | ||
| 58 | exit 1;; | ||
| 59 | |||
| 60 | |||
| 61 | pdf) | ||
| 62 | # Preview as text conversion | ||
| 63 | pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | fmt -w ${PV_WIDTH} && exit 5 | ||
| 64 | mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | fmt -w ${PV_WIDTH} && exit 5 | ||
| 65 | exiftool "${FILE_PATH}" && exit 5 | ||
| 66 | exit 1;; | ||
| 67 | |||
| 68 | # BitTorrent | ||
| 69 | torrent) | ||
| 70 | transmission-show -- "${FILE_PATH}" && exit 5 | ||
| 71 | exit 1;; | ||
| 72 | |||
| 73 | # OpenDocument | ||
| 74 | odt|ods|odp|sxw) | ||
| 75 | # Preview as text conversion | ||
| 76 | odt2txt "${FILE_PATH}" && exit 5 | ||
| 77 | exit 1;; | ||
| 78 | |||
| 79 | # HTML | ||
| 80 | htm|html|xhtml) | ||
| 81 | # Preview as text conversion | ||
| 82 | w3m -dump "${FILE_PATH}" && exit 5 | ||
| 83 | lynx -dump -- "${FILE_PATH}" && exit 5 | ||
| 84 | elinks -dump "${FILE_PATH}" && exit 5 | ||
| 85 | ;; # Continue with next handler on failure | ||
| 86 | esac | ||
| 87 | } | ||
| 88 | |||
| 89 | handle_image() { | ||
| 90 | local mimetype="${1}" | ||
| 91 | case "${mimetype}" in | ||
| 92 | # SVG | ||
| 93 | # image/svg+xml) | ||
| 94 | # convert "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6 | ||
| 95 | # exit 1;; | ||
| 96 | |||
| 97 | # Image | ||
| 98 | image/*) | ||
| 99 | local orientation | ||
| 100 | orientation="$( identify -format '%[EXIF:Orientation]\n' -- "${FILE_PATH}" )" | ||
| 101 | # If orientation data is present and the image actually | ||
| 102 | # needs rotating ("1" means no rotation)... | ||
| 103 | if [[ -n "$orientation" && "$orientation" != 1 ]]; then | ||
| 104 | # ...auto-rotate the image according to the EXIF data. | ||
| 105 | convert -- "${FILE_PATH}" -auto-orient "${IMAGE_CACHE_PATH}" && exit 6 | ||
| 106 | fi | ||
| 107 | |||
| 108 | # `w3mimgdisplay` will be called for all images (unless overriden as above), | ||
| 109 | # but might fail for unsupported types. | ||
| 110 | exit 7;; | ||
| 111 | |||
| 112 | # Video | ||
| 113 | # video/*) | ||
| 114 | # # Thumbnail | ||
| 115 | # ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6 | ||
| 116 | # exit 1;; | ||
| 117 | |||
| 118 | # application/pdf) | ||
| 119 | # pdftoppm -f 1 -l 1 \ | ||
| 120 | # -scale-to-x 1920 \ | ||
| 121 | # -scale-to-y -1 \ | ||
| 122 | # -singlefile \ | ||
| 123 | # -jpeg -tiffcompression jpeg \ | ||
| 124 | # -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \ | ||
| 125 | # && exit 6 || exit 1;; | ||
| 126 | |||
| 127 | # Preview archives using the first image inside. | ||
| 128 | # (Very useful for comic book collections for example.) | ||
| 129 | # application/zip|application/x-rar|application/x-7z-compressed|\ | ||
| 130 | # application/x-xz|application/x-bzip2|application/x-gzip|application/x-tar) | ||
| 131 | # local fn=""; local fe="" | ||
| 132 | # local zip=""; local rar=""; local tar=""; local bsd="" | ||
| 133 | # case "${mimetype}" in | ||
| 134 | # application/zip) zip=1 ;; | ||
| 135 | # application/x-rar) rar=1 ;; | ||
| 136 | # application/x-7z-compressed) ;; | ||
| 137 | # *) tar=1 ;; | ||
| 138 | # esac | ||
| 139 | # { [ "$tar" ] && fn=$(tar --list --file "${FILE_PATH}"); } || \ | ||
| 140 | # { fn=$(bsdtar --list --file "${FILE_PATH}") && bsd=1 && tar=""; } || \ | ||
| 141 | # { [ "$rar" ] && fn=$(unrar lb -p- -- "${FILE_PATH}"); } || \ | ||
| 142 | # { [ "$zip" ] && fn=$(zipinfo -1 -- "${FILE_PATH}"); } || return | ||
| 143 | # | ||
| 144 | # fn=$(echo "$fn" | python -c "import sys; import mimetypes as m; \ | ||
| 145 | # [ print(l, end='') for l in sys.stdin if \ | ||
| 146 | # (m.guess_type(l[:-1])[0] or '').startswith('image/') ]" |\ | ||
| 147 | # sort -V | head -n 1) | ||
| 148 | # [ "$fn" = "" ] && return | ||
| 149 | # [ "$bsd" ] && fn=$(printf '%b' "$fn") | ||
| 150 | # | ||
| 151 | # [ "$tar" ] && tar --extract --to-stdout \ | ||
| 152 | # --file "${FILE_PATH}" -- "$fn" > "${IMAGE_CACHE_PATH}" && exit 6 | ||
| 153 | # fe=$(echo -n "$fn" | sed 's/[][*?\]/\\\0/g') | ||
| 154 | # [ "$bsd" ] && bsdtar --extract --to-stdout \ | ||
| 155 | # --file "${FILE_PATH}" -- "$fe" > "${IMAGE_CACHE_PATH}" && exit 6 | ||
| 156 | # [ "$bsd" ] || [ "$tar" ] && rm -- "${IMAGE_CACHE_PATH}" | ||
| 157 | # [ "$rar" ] && unrar p -p- -inul -- "${FILE_PATH}" "$fn" > \ | ||
| 158 | # "${IMAGE_CACHE_PATH}" && exit 6 | ||
| 159 | # [ "$zip" ] && unzip -pP "" -- "${FILE_PATH}" "$fe" > \ | ||
| 160 | # "${IMAGE_CACHE_PATH}" && exit 6 | ||
| 161 | # [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}" | ||
| 162 | # ;; | ||
| 163 | esac | ||
| 164 | } | ||
| 165 | |||
| 166 | handle_mime() { | ||
| 167 | local mimetype="${1}" | ||
| 168 | case "${mimetype}" in | ||
| 169 | # Text | ||
| 170 | text/* | */xml) | ||
| 171 | # Syntax highlight | ||
| 172 | if [[ "$( stat --printf='%s' -- "${FILE_PATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then | ||
| 173 | exit 2 | ||
| 174 | fi | ||
| 175 | if [[ "$( tput colors )" -ge 256 ]]; then | ||
| 176 | local pygmentize_format='terminal256' | ||
| 177 | local highlight_format='xterm256' | ||
| 178 | else | ||
| 179 | local pygmentize_format='terminal' | ||
| 180 | local highlight_format='ansi' | ||
| 181 | fi | ||
| 182 | highlight --replace-tabs="${HIGHLIGHT_TABWIDTH}" --out-format="${highlight_format}" \ | ||
| 183 | --style="${HIGHLIGHT_STYLE}" --force -- "${FILE_PATH}" && exit 5 | ||
| 184 | # pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "${FILE_PATH}" && exit 5 | ||
| 185 | exit 2;; | ||
| 186 | |||
| 187 | # Image | ||
| 188 | image/*) | ||
| 189 | # Preview as text conversion | ||
| 190 | # img2txt --gamma=0.6 --width="${PV_WIDTH}" -- "${FILE_PATH}" && exit 4 | ||
| 191 | exiftool "${FILE_PATH}" && exit 5 | ||
| 192 | exit 1;; | ||
| 193 | |||
| 194 | # Video and audio | ||
| 195 | video/* | audio/*) | ||
| 196 | mediainfo "${FILE_PATH}" && exit 5 | ||
| 197 | exiftool "${FILE_PATH}" && exit 5 | ||
| 198 | exit 1;; | ||
| 199 | esac | ||
| 200 | } | ||
| 201 | |||
| 202 | handle_fallback() { | ||
| 203 | echo '----- File Type Classification -----' && file --dereference --brief -- "${FILE_PATH}" && exit 5 | ||
| 204 | exit 1 | ||
| 205 | } | ||
| 206 | |||
| 207 | |||
| 208 | MIMETYPE="$( file --dereference --brief --mime-type -- "${FILE_PATH}" )" | ||
| 209 | if [[ "${PV_IMAGE_ENABLED}" == 'True' ]]; then | ||
| 210 | handle_image "${MIMETYPE}" | ||
| 211 | fi | ||
| 212 | handle_extension | ||
| 213 | handle_mime "${MIMETYPE}" | ||
| 214 | handle_fallback | ||
| 215 | |||
| 216 | exit 1 | ||
