Copyright (C) 2000-2012 |
GNU Info (zsh.info)Other FunctionsOther Functions =============== There are a large number of helpful functions in the Functions/Misc directory of the zsh distribution. Most are very simple and do not require documentation here, but a few are worthy of special mention. Descriptions ------------ colors This function initializes several associative arrays to map color names to (and from) the ANSI standard eight-color terminal codes. These are used by the prompt theme system (Note: Prompt Themes). You seldom should need to run colors more than once. The eight base colors are: black, red, green, yellow, blue, magenta, cyan, and white. Each of these has codes for foreground and background. In addition there are eight intensity attributes: bold, faint, standout, underline, blink, reverse, and conceal. Finally, there are six codes used to negate attributes: none (reset all attributes to the defaults), normal (neither bold nor faint), no-standout, no-underline, no-blink, and no-reverse. Some terminals do not support all combinations of colors and intensities. The associative arrays are: color colour Map all the color names to their integer codes, and integer codes to the color names. The eight base names map to the foreground color codes, as do names prefixed with `fg-', such as `fg-red'. Names prefixed with `bg-', such as `bg-blue', refer to the background codes. The reverse mapping from code to color yields base name for foreground codes and the bg- form for backgrounds. Although it is a misnomer to call them `colors', these arrays also map the other fourteen attributes from names to codes and codes to names. fg fg_bold fg_no_bold Map the eight basic color names to ANSI terminal escape sequences that set the corresponding foreground text properties. The fg sequences change the color without changing the eight intensity attributes. bg bg_bold bg_no_bold Map the eight basic color names to ANSI terminal escape sequences that set the corresponding background properties. The bg sequences change the color without changing the eight intensity attributes. In addition, the scalar parameters reset_color and bold_color are set to the ANSI terminal escapes that turn off all attributes and turn on bold intensity, respectively. fned NAME Same as zed -f. This function does not appear in the zsh distribution, but can be created by linking zed to the name fned in some directory in your fpath. is-at-least NEEDED [ PRESENT ] Perform a greater-than-or-equal-to comparison of two strings having the format of a zsh version number; that is, a string of numbers and text with segments separated by dots or dashes. If the PRESENT string is not provided, $ZSH_VERSION is used. Segments are paired left-to-right in the two strings with leading non-number parts ignored. If one string has fewer segments than the other, the missing segments are considered zero. This is useful in startup files to set options and other state that are not available in all versions of zsh. is-at-least 3.1.6-15 && setopt NO_GLOBAL_RCS is-at-least 3.1.0 && setopt HIST_REDUCE_BLANKS is-at-least 2.6-17 || print "You can't use is-at-least here." nslookup [ ARG ... ] This wrapper function for the nslookup command requires the zsh/zpty module (see Note: The zsh/zpty Module). It behaves exactly like the standard nslookup except that it provides customizable prompts (including a right-side prompt) and completion of nslookup commands, host names, etc. (if you use the function-based completion system). Completion styles may be set with the context prefix `:completion:nslookup'. See also the pager, prompt and rprompt styles below. run-help See `Accessing On-Line Help' (Note: Utilities). zed [ -f ] NAME This function uses the ZLE editor to edit a file or function. It rebinds the return key to insert a line break, and adds bindings for `^X^W' in the emacs keymap and `ZZ' in the vicmd keymap to accept (and therefore write, in the case of a file) the edited file or function. Keybindings are otherwise the standard ones; completion is available, and styles may be set with the context prefix `:completion:zed'. Only one NAME argument is recognized (additional arguments are ignored). If the -f option is given, the name is taken to be that of a function; if the function is marked for autoloading, zed searches for it in the fpath and loads it. Note that functions edited this way are installed into the current shell, but _not_ written back to the autoload file. Without -f, NAME is the path name of the file to edit, which need not exist; it is created on write, if necessary. zcp [ -finqQvw ] SRCPAT DEST zln [ -finqQsvw ] SRCPAT DEST Same as zmv -C and zmv -L, respectively. These functions do not appear in the zsh distribution, but can be created by linking zmv to the names zcp and zln in some directory in your fpath. zkbd See `Keyboard Definition' (Note: Utilities). zmv [ -finqQsvw ] [ -C | -L | -M | -p PROGRAM ] [ -o OPTSTRING ] SRCPAT DEST Move (usually, rename) files matching the pattern SRCPAT to corresponding files having names of the form given by DEST, where SRCPAT contains parentheses surrounding patterns which will be replaced in turn by $1, $2, ... in DEST. For example, zmv '(*).lis' '$1.txt' renames `foo.lis' to `foo.txt', `my.old.stuff.lis' to `my.old.stuff.txt', and so on. The pattern is always treated as an EXTENDED_GLOB pattern. Any file whose name is not changed by the substitution is simply ignored. Any error (a substitution resulted in an empty string, two substitutions gave the same result, the destination was an existing regular file and -f was not given) causes the entire function to abort without doing anything. Options: -f Force overwriting of destination files. Not currently passed down to the mv/cp/ln command due to vagaries of implementations (but you can use -o-f to do that). -i Interactive: show each line to be executed and ask the user whether to execute it. `Y' or `y' will execute it, anything else will skip it. Note that you just need to type one character. -n No execution: print what would happen, but don't do it. -q Turn bare glob qualifiers off: now assumed by default, so this has no effect. -Q Force bare glob qualifiers on. Don't turn this on unless you are actually using glob qualifiers in a pattern. -s Symbolic, passed down to ln; only works with -L. -v Verbose: print each command as it's being executed. -w Pick out wildcard parts of the pattern, as described above, and implicitly add parentheses for referring to them. -C -L -M Force cp, ln or mv, respectively, regardless of the name of the function. -p PROGRAM Call PROGRAM instead of cp, ln or mv. Whatever it does, it should at least understand the form PROGRAM -- OLDNAME NEWNAME where OLDNAME and NEWNAME are filenames generated by zmv. -o OPTSTRING The OPTSTRING is split into words and passed down verbatim to the cp, ln or mv command called to perform the work. It should probably begin with a `-'. For more complete examples and other implementation details, see the zmv source file, usually located in one of the directories named in your fpath, or in Functions/Misc/zmv in the zsh distribution. zrecompile See `Recompiling Functions' (Note: Utilities). zstyle+ CONTEXT STYLE VALUE [ + SUBCONTEXT STYLE VALUE ... ] This makes defining styles a bit simpler by using a single `+' as a special token that allows you to append a context name to the previously used context name. Like this: zstyle+ ':foo:bar' style1 value1 \ + ':baz' style2 value2 \ + ':frob' style3 value3 This defines `style1' with `value1' for the context :foo:bar as usual, but it also defines `style2' with `value2' for the context :foo:bar:baz and `style3' with `value3' for :foo:bar:frob. Any SUBCONTEXT may be the empty string to re-use the first context unchanged. Styles ------ insert-tab The zed function _sets_ this style in context `:completion:zed:*' to turn off completion when TAB is typed at the beginning of a line. You may override this by setting your own value for this context and style. pager The nslookup function looks up this style in the context `:nslookup' to determine the program used to display output that does not fit on a single screen. prompt rprompt The nslookup function looks up this style in the context `:nslookup' to set the prompt and the right-side prompt, respectively. The usual expansions for the PS1 and RPS1 parameters may be used (see Note: Prompt Expansion). |