Merge branch 'experimental' of git://github.com/Dieterbe/uzbl into replace-expand...
[uzbl-mobile] / README
1 ### THIS PROJECT IS NOT FOR:
2 * people want a browser that does everything
3 * people who want a browser with things like a built-in bookmark manager, address bar, forward/back buttons, ...
4 * people who expect something that works by default.  You'll need to read configs and write/edit scripts
5
6
7 ### TO NEW PEOPLE:
8 * please read the documentation in /usr/share/uzbl/docs
9 * invoke uzbl --help
10 * to get you started: `XDG_DATA_HOME=/usr/share/uzbl/examples/data XDG_CONFIG_HOME=/usr/share/uzbl/examples/config uzbl --uri www.archlinux.org`
11 * study the sample config, have a look at all the bindings, and note how you can call the scripts to load new url from history and the bookmarks file
12 * You can change the url with commands (if you have setup the appropriate keybinds) but to be most effective it's better to do url editing/changing _outside_ of uzbl.
13   Eg, you can use the `load_from_*` dmenu based scripts to pick/edit a url or type a new one.
14 * If you have questions, you are likely to find answers in the FAQ or in the other documentation.
15
16
17 ### INTRODUCTION
18   In my opinion, any program can only be really useful if it complies to the unix philosophy.
19   Web browsers are frequent violators of this principle:
20
21 * They build in way too much things into the browser, dramatically decreasing the options to do things the way you want.
22 * They store things in way too fancy formats (xml, rdf, sqlite, ... ) which are hard to store under version control, reuse in other scripts, ...
23
24 Time to change that!
25
26   Here are the general ideas:
27
28 * each instance of uzbl renders 1 page (eg it's a small wrapper around webkit), no tabbing, tab previews, or speed dial things.
29   For "multiple instances management" use your window managers, scripts or wrappers.
30   This way you can get something much more useful than tabbing by default
31 * very simple, plaintext , changeable at runtime configuration
32 * various interfaces for (programmatic) interaction with uzbl (see below)
33 * customizable keyboard shortcuts in vim or emacs style (whatever user wants)
34 * "outsource" logic that is not browsing to external scripts under the users control:
35     - managing bookmarks
36     - loading a url from bookmarks, history,..  Editing the curent url
37     - control cookies
38     - handling of downloads, history logging, etc.
39     - management of cache.
40     - password management
41     - Leverage the power of utilities such as grep, awk, dmenu, zenity, wget, gnupg (password file) etc.
42 * listen to signals and do useful stuff when triggered.
43 * no ad blocking built in.
44   Alternatives:
45     - privoxy looks cool and perfectly demonstrates the unix philosphy.
46     - same for http://bfilter.sourceforge.net
47     - /etc/hosts (not very good cause you need root and it affects the whole system)
48       uzblctrl would need to support an option to list all images on a page, so you can easily pick the links to ads to add them to your /etc/hosts.
49 * vimperator/konqueror-like hyperlink following.
50 * password management. maybe an encrypted store that unlocks with an ssh key?
51 * no messing in the users $HOME or in /etc: no writing of anything unless the user (or sysadmin) asks for it.
52   We recommend using XDG basedir spec for separation of config, data and cache. and state should be a subdir in the config dir (not part of the spec yet) too.
53
54
55 ### CONFIGURATION / CONTROL:
56 The general idea is that uzbl by default is very bare bones.  you can send it commands to update settings and perform actions, through various interfaces.
57 There is a limited default configuration.  Please see config.h to see what it contains.
58 By default, there are *no* keybinds defined at all.  (Default keybinds would work counterproductive when you try to customize)
59 For examples of the possibilities what you can do, please see the sample config(s).
60 There are several interfaces to interact with uzbl:
61
62 * uzbl --config <filename>: <filename> will be read line by line, and the commands in it will be executed.  useful to configure uzbl at startup.
63   If you have a file in `$XDG_CONFIG_HOME/uzbl/config` (this expands to ~/.config/uzbl/config on most systems) it will be automatically recognized
64 * stdin: to write commands into stdin, use `--config -` (or `-c -`)
65 * interactive: you can enter commands (and bind them to shortcuts, even at runtime)
66   By default, the behaviour is modal (vi style):
67   command mode: every keystroke is interpreted to run commands
68   insert mode: keystrokes are not interpreted so you can enter text into html forms
69   Press ESC/i to toggle command/insert mode
70   But if you don't like modal interfaces, you can set `always_insert_mode` and configure a modkey to execute the commands. (emacs style).
71   There is also support for "chained" commands (multiple characters long) (with backspace/esc shortcuts), and keyworded commands.
72   Also you can have incremental matching on commands or match after pressing return.  (see sampleconfig for more info)
73   Also, copy paste works when typing commands:
74   * insert (paste X cliboard)
75   * shift insert (paste primary selection buffer)
76 * FIFO & socket file: if enabled by setting their paths through one of the above means, you can have socket and fifo files available which are very useful to programatically control uzbl (from scripts etc).
77   The advantage of the fifo is you can write plaintxt commands to it, but it's half duplex only (uzbl cannot send a response to you).
78   The socket is full duplex but you need a socket-compatible wrapper such as netcat to work with it, or uzblctrl of course,
79   an utitly we include with uzbl made especially for writing commnands to the socket (and at some point, it will be able to tell you the response
80   too):  `uzblctrl -s <socketfile> -c <command>`
81
82 When uzbl forks a new instance (eg "open in new window") it will use the same commandline arguments (eg the same --config <file>), except --uri and--name.
83 If you made changes to the configuration at runtime, these are not pased on to the child.
84
85 ### COMMAND SYNTAX
86 Uzbl will read commands via standard input, named fifo pipe (if `fifo_dir` is set) and IPC socket (when `socket_dir` is set).
87 For convenience, uzbl can also be instructed to read commands from a file on startup by using the `-c` option.  Indeed, the config file is nothing more than a list of commands.
88
89 Each command starts with the name of the command, which must be the first thing on a line; preceding whitespace is not allowed.
90 A command is terminated by a newline.  Empty lines and lines that start with the hash sign are ignored by the parser.  Command names are always written in lowercase.
91
92 The following commands are recognized:
93
94 * `set <key> = <value>`
95    - used for changing variables on the fly
96    - the changes are effective immediately; for example, setting the variable `uri` will make uzbl start loading, and changing `status_format` will make the status bar react immediately
97    - if you want to unset a string, use `set` with one space after the equals sign
98 * `print @<key>`
99    - use this to print the value of a variable.
100 * `bind <string> = <command>`
101    - sets the character sequence `<string>` to invoke `<command>` when typed interactively in uzbl
102    - there are a few tricks you can do:
103        * `<string>` ends with an underscore: the command will only be invoked after pressing return/enter. If the user enters text where `<string>` has the underscore, `%s` in the `<command>` string will be replaced by this text. (optional)
104        * `<string>` ends with an asterisk: similar behavior as with an underscore, but also makes the binding incremental (i.e. the command will be invoked on every keystroke).
105        * `<string>` ends on a different character: you need to type the full string, which will trigger the command immediately, without pressing enter/return.
106    - examples:
107        * `bind o _ = uri %s`
108          - uzbl will load the url when you type: 'o <url><enter>'
109        * `bind /*  = search %s`
110          - a search command which is called on every character typed after the slash, letting you see the search narrow down while typing.
111          - Hitting return, enter or esc will terminate the search.
112        * `bind ZZ  = exit`
113          - When you type `ZZ` and nothing else, the exit command will be triggered immediately.
114
115 * `back`
116 * `forward`
117 * `scroll_vert <amount>`
118 * `scroll_horz <amount>`
119    - amount is given in pixels(?) or as a percentage of the size of the view
120    - set amount to 100% to scroll a whole page
121 * `scroll_begin`
122 * `scroll_end`
123 * `reload`
124 * `reload_ign_cache`
125 * `stop`
126 * `zoom_in`
127 * `zoom_out`
128 * `uri <address>`
129 * `js <body>`
130    - execute the javascript in `<body>`
131    - remember that the commands must not contain line breaks
132 * `script <file>`
133    - execute the javascript in `<file>`
134 * `toggle_status`
135 * `spawn <executable> <additonal args>`
136    - runs a command; see EXTERNAL SCRIPTS for details
137    - PATH is searched so giving the full path to commands is not neccessary
138    - note that the arguments as specified in "EXTERNAL SCRIPTS" are appended at the end, so the argument numbers will be higher.
139 * `sh <command>`
140    - runs a shell command by expanding `%s` in the `shell_cmd` variable with the specified command; primarily useful as a shortcut for `spawn sh -c <body>`
141    - note that the arguments as specified in "EXTERNAL SCRIPTS" are appended at the end, so the argument numbers will be higher.
142 * `sync_spawn <executable> <additional args>`
143 * `sync_sh <command>`
144    - these are synchronous variants of `spawn` and `sh`, which means uzbl will wait for them to return
145    - you should only need to use these manually if you want to use a chain command in a handler that wants output from the command it runs
146 * `exit`
147 * `search <string>`
148 * `search_reverse <string>`
149    - search with no string will search for the next/previous occurrence of the string previously searched for
150 * `toggle_insert_mode <optional state>`
151    - if the optional state is 0, disable insert mode. If 1, enable insert mode.
152 * `dump_config`
153    - dumps your current config (which may have been changed at runtime) to stdout, in a format you can use to pipe into uzbl again (or use as config file)
154 * `keycmd <string>`
155 * `keycmd_nl <string>`
156    - keycmd sets the interactive command buffer to `<string>`.  If the given string is a valid binding, it will execute.  `Keycmd_nl` is like `keycmd`, but it also emulates a press of return, causing bindings with a parameter to execute.  For example, `keycmd_nl o google.com` would load the said url if you have a binding like `bind o _ = uri %s`.
157 * `keycmd_bs`
158    - erase (backspace) one character from the command buffer
159 * `chain <command> <command> ..`
160    - use for chaining multiple commands
161    - remember to quote the commands; one command must come as one parameter
162    - if you use `chain` with a handler script which must return some output (such as a cookie handler -- uzbl will wait for and use its output), use sync_spawn or sync_sh instead of spawn or sh in the command that should give the output
163
164 ### JAVASCRIPT HELPER OBJECT
165
166 Javascript code run from uzbl is given a special object in the global namespace which gives special privileges to these scripts. This object is called `Uzbl`, and it is added and removed before and after the script execution so that it is hidden to web javascripts (There is no race condition, since all the javascript code runs in a single thread)
167
168 Currently, the `Uzbl` object provides only one function:
169
170 * `Uzbl.run( <command> )`
171    - command is any uzbl command as defined above
172    - return value: a string, either empty or containing the output of the command. Very few commands return their output currently, including js, script, and print.
173    - Examples:
174        * `Uzbl.run("spawn insert_bookmark.sh")`
175        * `uri = Uzbl.run("print @uri")` (see variable expansion below)
176
177 ### JAVASCRIPT SECURITY
178
179 Since defined variables and functions are set in the global namespace (`window` object) as default, it is recommended to wrap your scripts like this:
180
181     (function(Uzbl) {
182         ...
183     })(Uzbl);
184
185 This way, everything is kept private. It also turns Uzbl into a local variable, which can be accessed from callback functions defined inside. However for some situations, isolating everything isn't an option, for example, with binds. You can define them directly in the script body, and use `var Uzbl = window.Uzbl;` to make the Uzbl variable local, as in the following example:
186
187     function f() {
188         var Uzbl = window.Uzbl;
189         Uzbl.run(...);
190         setTimeout(function() {
191             Uzbl.run(...);
192         }, 500);
193     }
194
195 Copying the Uzbl object and creating public functions should be taken with care to avoid creating security holes. Keep in mind that the "f" function above would be defined in the `window` object, and as such any javascript in the current page can call it.
196
197 ### VARIABLE EXPANSION AND COMMAND/JAVA SCRIPT SUBSTITUTION
198
199 Variable expansion works pretty much as known from shell interpreters (sh, bash, etc.). This means you can
200 construct strings with uzbl variables in them and have uzbl replace the variable name with its contents.
201
202 In order to let uzbl know what to expand you'll need to prepend @ to the variable name:
203
204     print The variable \@show_status contains @show_status
205
206 The above example demonstrates two things:
207
208     * '\' is treated as escape character and will use the character immediatelly following it literallily
209       this means '\@show_status' will not expand to the variable content but be rather printed as
210       '@show_status'
211
212     * prepending the variable with '@' will expand to its contents
213
214     * like in the shell you can use @{uzbl_var} to denote the beginning/end of the variable name in
215       cases where it is not obvious what belongs to the name and what not.
216       E.g.:  print @{show_status}foobar
217
218
219 Command substitution will launch any commands and substitute the call with the return value of the command.
220
221 Uzbl will substitute any commands enclosed within @(  )@:
222
223     print Command substitution: @(uname -a)@
224
225 You can access any uzbl variable from within a command substitution:
226
227     print @(echo -n 'Accessing the show_status var from an external script, value: @show_status')@
228
229
230 Java script substitution works in the exact same way as command substitution but you will need to enclose
231 the java script in @< >@.
232
233     print The currently viewed document contains @<document.links.length>@ links
234
235 Variable expansion also works within a java script substitution.
236
237
238 When a piece of text needs to be XML escaped after it is expanded (for example,
239 in the status bar format), you can use @[ ]@ substitution:
240
241     print This text is XML escaped: @[<&>]@
242
243     # prints: This text is XML escaped: &lt;&amp;&gt;
244
245
246 NOTE: If you need to use literal @ or \ characters you will need to escape them:
247
248     print At sign: \@  and backslash: \\
249
250
251 ### TITLE AND STATUS BAR EVALUATION
252
253 The contents of the status bar can be customized by setting the status_format
254 variable. The contents of the window title can be customized by setting the
255 title_format_short variable (which is used when the status bar is displayed) and
256 the title_format_long variable (which is used when the status bar is not
257 displayed). Their values can be set using the expansion and substitution
258 techniques described above.
259
260 These variables are expanded in multiple stages; once when the variable is set,
261 and again every time that the status bar or window title are updated. Expansions
262 that should be evaluated on every update need to be escaped:
263
264     set title_format_short = @(date)@
265     # this expansion will be evaluated when the variable is set.
266     # the title will stay constant with the date that the variable was set.
267
268     set title_format_short = \@(date)\@
269     # this expansion will be evaluated when the window title is updated.
270     # the date in the title will change when you change pages, for example.
271
272     set title_format_short = \\\@(date)\\\@
273     # the title will stay constant as a literal "@(date)@"
274
275 The status_format variable can contain Pango markup (see
276 <http://library.gnome.org/devel/pango/stable/PangoMarkupFormat.html>). In the
277 status_format, variables that might contain characters like '<', '&' and '>',
278 should be wrapped in a @[]@ substitution so that they don't interfere with the
279 status bar's markup; see the example config for examples.
280
281
282 ### EXTERNAL SCRIPTS
283 You can use external scripts with uzbl the following ways:
284
285 * let uzbl call them. these scripts are called handlers in the uzbl config. used for handling logging history, handling a new download,..
286 * call them yourself from inside uzbl.  you can bind keys for this. examples: add new bookmark, load new url,..
287 * You could also use xbindkeys or your WM config to trigger scripts if uzbl does not have focus
288
289 Have a look at the sample configs and scripts!
290
291 Handler scripts that are called by uzbl are passed the following arguments:
292
293     $1 uzbl-config-file
294     $2 uzbl-pid
295     $3 uzbl-x-window-id
296     $4 uzbl_fifo-filename
297     $5 uzbl_socket-filename
298     $6 current page url
299     $7 current page title
300     .. [ script specific ] (optional)
301
302 The script specific arguments are this:
303
304 * history:
305
306     $8 date of visit (Y-m-d H:i:s localtime)
307
308 * add bookmark:
309
310     none
311
312 * download:
313
314     $8 url of item to download
315
316 * cookie handler
317
318     $8 GET/PUT
319     $9 request address scheme (e.g. http or https)
320     $10 request address host (if current page url is www.foo.com/somepage, this could be something else than foo, eg advertising from another host)
321     $11 request address path
322     $12 cookie (only with PUT requests)
323
324
325 Custom, userdefined scripts (`spawn foo bar`) get first the arguments as specified in the config and then the above 7 are added at the end.
326
327 ### COMMAND LINE ARGUMENTS
328     uzbl [ uri ]
329     -u, --uri=URI            alternative way to load uri on start. (equivalent to 'set uri = URI')
330     -v, --verbose            Whether to print all messages or just errors.
331     -n, --name=NAME          Name of the current instance (defaults to Xorg window id)
332     -c, --config=FILE        Config file (or `-` to use stdin)
333     -s, --socket=SOCKET      Socket ID
334     -V, --version            Print the version and exit
335     --display=DISPLAY        X display to use
336     --help                   Help
337
338
339
340
341
342 ### BUGS
343 known bugs:
344
345 * Segfaults when using zoom commands (happens when max zoom already reached?).
346
347 Please report new issues @ uzbl.org/bugs