about summary refs log tree commit diff stats
path: root/doc/rifle.1
blob: 4d501df06197ba7ed042366daabdce8e354f3bf5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.if !\nF .nr F 0
.if \nF>0 \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    if !\nF==2 \{\
.        nr % 0
.        nr F 2
.    \}
.\}
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "RIFLE 1"
.TH RIFLE 1 "rifle-1.9.0b5" "10/01/2017" "rifle manual"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
rifle \- ranger's file opener
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
\&\fBrifle\fR [\fB\-\-help\fR] [\fB\-f\fR \fI\s-1FLAGS\s0\fR] [\fB\-l\fR] [\fB\-p\fR \fI\s-1KEYWORD\s0\fR]
[\fB\-w\fR \fI\s-1PROGRAM\s0\fR] [\fB\-c\fR \fI\s-1CONFIG_FILE\s0\fR] \fIfiles\fR
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
rifle is a powerful file executor that allows for complex file type checking,
written to meet the needs of the file manager \fIranger\fR.  rifle's strength lies
in automatically determining file types, depending on which programs are
installed on the system, even without any user interaction.
.SH "OPTIONS"
.IX Header "OPTIONS"
.IP "\fB\-f\fR \fI\s-1FLAGS\s0\fR" 14
.IX Item "-f FLAGS"
Specify flags for opening the files.  Flags are letters that changes how the
program is executed.  Any combination of flags will work.  Writing uppercase
flags will negate the effect of all previously used lowercase flags of the same
letter.
.Sp
Table of all flags:
 f   fork program to background
 r   run program as root, using sudo
 t   run program in a separate terminal, as specified by \f(CW$TERMCMD\fR
.IP "\fB\-l\fR" 14
.IX Item "-l"
List all possible ways to open the specified files.  Each line will contain information in the format of \fIid:label:flags:command\fR. \fIid\fR is the identification number. \fIlabel\fR is an arbitrary string that was specified for this command, \fIflags\fR are the flags that are used by default, and \fIcommand\fR is the command that is going to be executed.
.IP "\fB\-p\fR \fI\s-1KEYWORD\s0\fR" 14
.IX Item "-p KEYWORD"
Pick a method to open the files.
.Sp
\&\fI\s-1KEYWORD\s0\fR is either the \s-1ID\s0 number listed by \f(CW\*(C`rifle \-l\*(C'\fR or a string that matches a label in the configuration file.
.IP "\fB\-w\fR \fI\s-1PROGRAM\s0\fR" 14
.IX Item "-w PROGRAM"
Open the files with the program \fI\s-1PROGRAM\s0\fR
.IP "\fB\-c\fR \fI\s-1CONFIG_FILE\s0\fR" 14
.IX Item "-c CONFIG_FILE"
Read configuration from \fI\s-1CONFIG_FILE\s0\fR, instead of the default.
.IP "\fB\-h\fR, \fB\-\-help\fR" 14
.IX Item "-h, --help"
Print a list of options and exit.
.SH "FILES"
.IX Header "FILES"
rifle shares configuration files with ranger, though ranger is not required in
order to use rifle. The default configuration file \fIrifle.conf\fR is expected
to be at \fI~/.config/ranger/rifle.conf\fR. However, this can be overridden with
the \fB\-c\fR option.
.PP
This file specifies patterns for determining the commands to open files with.
The syntax is described in the comments of the default \fIrifle.conf\fR that ships
with ranger.  To obtain it, you need to run: \f(CW\*(C`ranger \-\-copy\-config=rifle\*(C'\fR
.SH "ENVIRONMENT"
.IX Header "ENVIRONMENT"
.IP "\s-1EDITOR\s0" 8
.IX Item "EDITOR"
Determines which editor to use for editing files (in the default \fIrifle.conf\fR).
.IP "\s-1PAGER\s0" 8
.IX Item "PAGER"
Determines which pager to use for displaying files (in the default \fIrifle.conf\fR).
.IP "\s-1TERMCMD\s0" 8
.IX Item "TERMCMD"
Determines the terminal emulator command for use with the \fIt\fR flag.  It is required that the value is the path to an executable file which accepts the \*(L"\-e \s-1COMMAND\*(R"\s0 argument.
.IP "\s-1XDG_CONFIG_HOME\s0" 8
.IX Item "XDG_CONFIG_HOME"
Specifies the directory for configuration files. Defaults to \fI\f(CI$HOME\fI/.config\fR.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
List all the different methods:
.PP
.Vb 4
\& $ rifle \-l helloworld.py
\& 0:editor::"$EDITOR" \-\- "$@"
\& 1:pager::"$PAGER" \-\- "$@"
\& 2:::python \-\- "$1"
.Ve
.PP
Display its content by opening it with \*(L"cat\*(R":
.PP
.Vb 2
\& $ rifle \-w cat helloworld.py
\& print("Hello World!")
.Ve
.PP
Run it by picking the method 2, which calls 'python \*(-- \*(L"$1\*(R"':
.PP
.Vb 2
\& $ rifle \-p 2 helloworld.py
\& Hello World!
.Ve
.PP
Display the file in a pager inside a new terminal, run as root:
.PP
.Vb 1
\& $ rifle \-p 1 \-f tr helloworld.py
.Ve
class="k">lambda x: x.realpath, sel))) if movedown is None: movedown = len(sel) == 1 if movedown: self.move_pointer(relative=1) if hasattr(self.ui, 'redraw_main_column'): self.ui.redraw_main_column() def tag_remove(self, movedown=None): try: remove = self.tags.remove except AttributeError: return sel = self.env.get_selection() remove(*tuple(map(lambda x: x.realpath, sel))) if movedown is None: movedown = len(sel) == 1 if movedown: self.move_pointer(relative=1) if hasattr(self.ui, 'redraw_main_column'): self.ui.redraw_main_column() def enter_bookmark(self, key): """Enter the bookmark with the name <key>""" try: destination = self.bookmarks[key] pwd = self.env.pwd if destination.path != pwd.path: self.bookmarks.enter(key) self.bookmarks.remember(pwd) except KeyError: pass def set_bookmark(self, key): """Set the bookmark with the name <key> to the current directory""" self.bookmarks[key] = self.env.pwd def unset_bookmark(self, key): """Delete the bookmark with the name <key>""" self.bookmarks.delete(key) def move_left(self, narg=1): """Enter the parent directory""" try: directory = os.path.join(*(['..'] * narg)) except: return self.env.enter_dir(directory) def move_right(self, mode=0, narg=None): """Enter the current directory or execute the current file""" cf = self.env.cf sel = self.env.get_selection() if isinstance(narg, int): mode = narg if not self.env.enter_dir(cf): if sel: if self.execute_file(sel, mode=mode) is False: self.open_console(cmode.OPEN_QUICK) def history_go(self, relative): """Move back and forth in the history""" self.env.history_go(relative) def handle_mouse(self): """Handle mouse-buttons if one was pressed""" self.ui.handle_mouse() def display_command_help(self, console_widget): if not hasattr(self.ui, 'open_pager'): return try: command = console_widget._get_cmd_class() except: self.notify("Feature not available!", bad=True) return if not command: self.notify("Command not found!", bad=True) return if not command.__doc__: self.notify("Command has no docstring. Try using python without -OO", bad=True) return pager = self.ui.open_pager() lines = cleandoc(command.__doc__).split('\n') pager.set_source(lines) def display_help(self, topic='index', narg=None): if not hasattr(self.ui, 'open_pager'): return from ranger.help import get_help, get_help_by_index if narg is not None: help_text = get_help_by_index(narg) else: help_text = get_help(topic) pager = self.ui.open_pager() pager.markup = 'help' lines = help_text.split('\n') pager.set_source(lines) def display_log(self): if not hasattr(self.ui, 'open_pager'): return pager = self.ui.open_pager() if self.log: pager.set_source(["Message Log:"] + list(self.log)) else: pager.set_source(["Message Log:", "No messages!"]) def display_file(self): if not hasattr(self.ui, 'open_embedded_pager'): return try: f = open(self.env.cf.path, 'r') except: pass else: pager = self.ui.open_embedded_pager() pager.set_source(f) def execute_file(self, files, **kw): """Execute a file. app is the name of a method in Applications, without the "app_" flags is a string consisting of runner.ALLOWED_FLAGS mode is a positive integer. Both flags and mode specify how the program is run.""" if isinstance(files, set): files = list(files) elif type(files) not in (list, tuple): files = [files] return self.run(files=list(files), **kw) def execute_command(self, cmd, **kw): return self.run(cmd, **kw) def edit_file(self, file=None): """Calls execute_file with the current file and app='editor'""" if file is None: file = self.env.cf elif isinstance(file, str): file = File(os.path.expanduser(file)) if file is None: return self.execute_file(file, app = 'editor') def open_console(self, mode=':', string=''): """Open the console if the current UI supports that""" if hasattr(self.ui, 'open_console'): self.ui.open_console(mode, string) def move_pointer(self, relative = 0, absolute = None, narg=None): """Move the pointer down by <relative> or to <absolute>""" self.env.pwd.move(relative=relative, absolute=absolute, narg=narg) def move_pointer_by_pages(self, relative): """Move the pointer down by <relative> pages""" self.env.pwd.move(relative=int(relative * self.env.termsize[0])) def move_pointer_by_percentage(self, relative=0, absolute=None, narg=None): """Move the pointer down by <relative>% or to <absolute>%""" try: factor = len(self.env.pwd) / 100.0 except: return if narg is not None: absolute = narg self.env.pwd.move( relative=int(relative * factor), absolute=int(absolute * factor)) def scroll(self, relative): """Scroll down by <relative> lines""" if hasattr(self.ui, 'scroll'): self.ui.scroll(relative) self.env.cf = self.env.pwd.pointed_obj def redraw_window(self): """Redraw the window""" self.ui.redraw_window() def reset(self): """Reset the filemanager, clearing the directory buffer""" old_path = self.env.pwd.path self.env.directories = {} self.enter_dir(old_path) def toggle_boolean_option(self, string): """Toggle a boolean option named <string>""" if isinstance(self.env.settings[string], bool): self.env.settings[string] ^= True def sort(self, func=None, reverse=None): if reverse is not None: self.env.settings['reverse'] = bool(reverse) if func is not None: self.env.settings['sort'] = str(func) def force_load_preview(self): cf = self.env.cf if hasattr(cf, 'unload') and hasattr(cf, 'load_content'): cf.unload() cf.load_content() def reload_cwd(self): try: cwd = self.env.pwd except: pass cwd.unload() cwd.load_content() def traverse(self): cf = self.env.cf cwd = self.env.pwd if cf is not None and cf.is_directory: self.enter_dir(cf.path) elif cwd.pointer >= len(cwd) - 1: while True: self.enter_dir('..') cwd = self.env.pwd if cwd.pointer < len(cwd) - 1: break if cwd.path == '/': break self.move_pointer(1) self.traverse() else: self.move_pointer(1) self.traverse() def set_filter(self, fltr): try: self.env.pwd.filter = fltr except: pass def notify(self, text, duration=4, bad=False): if isinstance(text, Exception): if ranger.debug: raise bad = True text = str(text) self.log.appendleft(text) if hasattr(self.ui, 'notify'): self.ui.notify(text, duration=duration, bad=bad) def mark(self, all=False, toggle=False, val=None, movedown=None, narg=1): """ A wrapper for the directory.mark_xyz functions. Arguments: all - change all files of the current directory at once? toggle - toggle the marked-status? val - mark or unmark? """ if self.env.pwd is None: return pwd = self.env.pwd if not pwd.accessible: return if movedown is None: movedown = not all if val is None and toggle is False: return if all: if toggle: pwd.toggle_all_marks() else: pwd.mark_all(val) else: for i in range(pwd.pointer, min(pwd.pointer + narg, len(pwd))): item = pwd.files[i] if item is not None: if toggle: pwd.toggle_mark(item) else: pwd.mark_item(item, val) if movedown: self.move_pointer(relative=narg) if hasattr(self.ui, 'redraw_main_column'): self.ui.redraw_main_column() if hasattr(self.ui, 'status'): self.ui.status.need_redraw = True # ------------------------------------ filesystem operations def copy(self): """Copy the selected items""" selected = self.env.get_selection() self.env.copy = set(f for f in selected if f in self.env.pwd.files) self.env.cut = False def cut(self): self.copy() self.env.cut = True def paste_symlink(self): from os import symlink, getcwd from os.path import join copied_files = self.env.copy if not copied_files: return for f in copied_files: try: symlink(f.path, join(getcwd(), f.basename)) except Exception as x: self.notify(x) def paste(self, overwrite=False): """Paste the selected items into the current directory""" from os.path import join, isdir from ranger.ext import shutil_generatorized as shutil_g from ranger.fsobject.loader import LoadableObject copied_files = tuple(self.env.copy) if not copied_files: return original_path = self.env.pwd.path try: one_file = copied_files[0] except: one_file = None if self.env.cut: self.env.copy.clear() self.env.cut = False if len(copied_files) == 1: descr = "moving: " + one_file.path else: descr = "moving files from: " + one_file.dirname def generate(): for f in copied_files: for _ in shutil_g.move(src=f.path, dst=original_path, overwrite=overwrite): yield pwd = self.env.get_directory(original_path) pwd.load_content() else: if len(copied_files) == 1: descr = "copying: " + one_file.path else: descr = "copying files from: " + one_file.dirname def generate(): for f in self.env.copy: if isdir(f.path): for _ in shutil_g.copytree(src=f.path, dst=join(self.env.pwd.path, f.basename), symlinks=True, overwrite=overwrite): yield else: for _ in shutil_g.copy2(f.path, original_path, symlinks=True, overwrite=overwrite): yield pwd = self.env.get_directory(original_path) pwd.load_content() self.loader.add(LoadableObject(generate(), descr)) def delete(self): self.notify("Deleting!", duration=1) selected = self.env.get_selection() self.env.copy -= set(selected) if selected: for f in selected: if os.path.isdir(f.path) and not os.path.islink(f.path): try: shutil.rmtree(f.path) except OSError as err: self.notify(err) else: try: os.remove(f.path) except OSError as err: self.notify(err) def mkdir(self, name): try: os.mkdir(os.path.join(self.env.pwd.path, name)) except OSError as err: self.notify(err) def rename(self, src, dest): if hasattr(src, 'path'): src = src.path try: os.rename(src, dest) except OSError as err: self.notify(err)