The program xd is used to perform eXtra fast Directory changes. Usually to change a directory the user is required to enter a command like, e.g., cd /usr/local/bin, possibly using shell completion. Often this is a tedious task: shell completion shows all entries, including files, when we're only interested in directories and the full specification of our intented directory may eventually require many keyboard actions.
Xd was designed a long time ago (in the early 90s) to reduce the effort of changing directories. Often we're well aware to which directory we want to change, and it's easy to provide the initial directory characters of that directory. E.g., if the intent is to cd to /usr/local/bin, it's easy to specify the letters ulb.
Xd capitalizes on this capability. By providing the initial directory characters of directories xd determines the expansion(s) allowing you to do fast directory changes. So, after entering the command xd ulb xd may directly perform the change-directory to /usr/local/bin.
Often, however, multiple alternatives can match the specified series of characters. E.g., when entering xd ulb xd may find several alternatives, like
1: /usr/lib/base-config 2: /usr/lib/bonobo 3: /usr/lib/bonobo-activation 4: /usr/local/binIf these are the alternatives, then this is exactly what xd shows you. Then, by simply pressing the 4 key (no Enter key required) xd performs the required /usr/local/bin (see also the section DIRECT KEY ENTRY).
Xd's behavior can be fine-tuned in various ways:
If there's only one solution, Xd prepares for a direct directory change to the solution's directory.
If there are multiple solutions, then by default lists of at most 62 alternatives (10 for the numbers 0..9, 26 for the letters a..z and 26 for the letters A..Z) are written to the standard error stream from which the user may select an alternative by simply pressing the key associated with the selection of choice. If no selection is requested any other key may be pressed (e.g., the space bar or the Enter key). If there is no solutioon xd writes the text No Solutions to the standard error stream.
When xd is given at least one argument, all its output is sent to the standard error stream, except for the selected directory name which should become the next working directory.
Xd may insert the cd command directly into the command shell from where xd was called. See also section SHELL SCRIPTS). In this mode of operation xd returns a single dot if no selection is made, preventing an unintended change of directory.
If no selection is made or if the selection process is aborted a single dot is written to the standard output stream. Usually xd will be called by a shell alias, providing the cd command with xd's output (see below at the SHELL SCRIPTS section) executing cd `xd $*`. The default dot produced by xd prevents an unintended change of directory.
When xd is merely given an initial directory specification, like a single dot (.) or digit (a digit in the set [0..9]) then xd returns the implied path. Specifying a parent before the root-directory (E.g., entering `xd 5' when the current working directory is `/tmp') results in writing the root directory (`/') to the standard output stream.
If xd is called without arguments its usage information is written to the standard error stream.
Xd may be further configured using options and a configuration file, discussed in the OPTIONS and CONFIGURATION FILE sections below.
To pass the directory change command to the shell's input buffer xd calls the function ioctl(2). That function is still available, although it's also considered a somewhat deprecated function. But even though it's available, by default it may not work. The program sysctl(8) shows the values of system variables, among which dev.tty.legacy_tiocsti:
sysctl -a | grep tiocsti dev.tty.legacy_tiocsti = 0If, at your computer, sysctl shows dev.tty.legacy_tiocsti = 0 then define a file /etc/sysctl.d/tiocsti.conf containing the line
dev.tty.legacy_tiocsti=1Then, after rebooting ioctl will work as described in its man-page.
Alternatively, a shell script or alias can be defined to pass the command to your shell. E.g., when using the tcsh shell program the following alias can be defined:
alias xd 'cd `\xd --no-input \!*`'Or, when using bash, define a function xd calling, e.g., /usr/bin/xd:
xd() { cd `/usr/bin/xd --no-input "$*"` }
Xd also supports generalized directory search commands (GDS). When GDS is requested separators are no longer required, and xd finds all possible alternatives resulting from all possible sequential combinations of the initial search command. GDS is activated either by specifying the -g option or by entering generalized-search in xd's configuration file. Alternatively, when the latter is specified then the --traditional command line option suppresses GDS.
When using GDS each initial substring of the command to xd is considered as the initial characters of a directory. E.g., if the command xd tmps is entered using GDS then directories matching the following search patterns will be found;
Multiple command line arguments, the slash, and the underscore can still be used with GDS. In this case they force a directory change using the considered patterns. E.g., with the command xd tm/ps the following patterns will be considered:
Xd may return the following values to its caller, allowing scripts calling xd to make decisions that depend on the actually performed action by xd:
If available, single letter options are listed between parentheses following their associated long-option variants. Single letter options require arguments if their associated long options require arguments as well.
Most options can also be specified in xd's configuration file, in which case the long option variants must be used, omitting the initial two dashes (see the section CONFIGURATION FILE below for specific details about the configuration file.
By default the options can also be specified in the configuration file. If an option cannot be specifiied in the configuration file it is explicitly stated at its description.
Options that are specified as command-line options take priority over options specified in the configuration file.
- never (no additional search is performed),
- if-empty (an additional search is performed if the initial search did not yield any directory),
- always (an additional search is always performed);
When alternatives are split up in blocks, a + is displayed after listing the first block, a - is displayed after listing the last block, and -+ is displayed after listing the intermediate blocks. In these cases, pressing - redisplays the previous block, pressing + displays the next block;
Although these block-end prompts only show - and +, the characters , and < (usually combined in one key) can be used instead of -, while . and > (also usually combined in one key) can be used instead of +.
This option cannot be specified in the configuration file;
This option cannot be specified in the configuration file;
Caveat: command shells by default interpret characters like ``~ $ ' " ` < > |'' etc., which therefore should probably not be specified as home directory specifiers;
1292596154 1 /home/frank/svn/xd/The first field is the time (in seconds since the epoch) the entry was written, the second field is the number of times the entry has been selected and the third field is the associated path.
The following history-... options are only interpreted if the history option is also specified.
This directive is overruled by the ---all command line option;
By specifying this option (or by entering input in the configuration file) an extra shell alias or script is not necessary. In this input mode xd directly inserts the requested cd command into the shell's input buffer. This mode has an additional feature: if a key is pressed that is not assiciated with a possible directory then the current directory is kept, and the character corresponding to the pressed key is entered into the shell's input buffer. E.g., if xd ulb shows a list of five alternatives, but the L key is pressed then xd ends and the shell's input buffer shows l. Merely pressing s + Enter will then show the current directory content. To merely end xd in this mode the space bar or Enter key can be pressed;
To merely end xd press the Enter key or space-bar;
By suppressing the input mode xd writes the name of the directory to change to to its standard output stream. This allows shell functions to process the directory returned by xd. An example of its use is the function pxd (pushd using xd) shown in section SHELL SCRIPTS;
This option cannot be specified in the configuration file;
This option cannot be specified in the configuration file.
The default configuration file is .xdrc in the user's home directory. It may be overruled by the program's --config-file command-line option.
Empty lines are ignored. Information at and beyond #-characters is interpreted as comment and is also ignored.
Directives in xd configuration files follow the pattern
directive value(for some directives there is no value term).
A line may at most contain one directive, but white space (including comment at the end of the line) is OK. The same directive may be specified multiple times, in which case the last directive will be used (except for the ignore directive, which are all interpreted). All directives are interpreted case sensitively unless option icase is specified. Non-empty lines not beginning with a recognized directive are silently ignored.
Assuming xd is installed in /usr/bin scripts can be defined around xd for various shell programs. This allows the shell to change directories under control of xd.
To use xd in combination with the pushd shell command xd itself should not perform directory changes. In such cases the no-input option should be specified in the shell function combining pushd and xd.
To use xd with the bash(1)-shell, the following function can be used (which could be added to, e.g., .bash_login):
pxd() # function to do `pushd` using `xd` { pushd "`/usr/bin/xd --no-input $*`" }To use xd with the tcsh(1)-shell, the following alias can be defined in, e.g., the ~/.alias file:
alias pxd 'pushd `\xd --no-input \!*`'
If the input option is specified (as command-line or configuration file option) then this example can be ignored.
To use xd with the bash(1)-shell, the following function can be used (which could be added to, e.g., .bash_login):
xd() # function to do `cd` using `xd` { cd "`/usr/bin/xd $*`" }To use xd with the tcsh(1)-shell, the following alias can be defined in, e.g., the ~/.alias file:
alias xd 'cd `\xd \!*`'Having defined the xd alias or script xd ... commands results in the automatic (or optional) change of the current working directory
If your system uses blanks in directory names, the above tcsh-alias cannot be used as the blanks are interpreted as argument-separaters. In that case the following alias can be defined as the xd alias:
alias xd 'setenv XD "`\xd \!*`";cd "$XD"'
xd ulb - all directories starting subsequently, with u, l and b origin is default, or specified in .xdrc as home or root xd 0t - all directories starting with t below the cwd xd 2t - all directories starting at the `grandparent' (2 steps up) of the cwd xd --start-at root t - all directories at the root starting with t xd .. - all directories starting with a dot in the cwd xd . - the user's home directory xd 0 - the current working directory xd 1 - the current directory's parent directoryAssuming the following directories exist:
/usr/lib/bonobo /usr/lib/bonobo-activation /usr/local/binthen the following two ignore specifications in xd's configuration file will result in ignoring the bonobo directory alternatives:
First specification:
ignore /usr/lib/bonobo ignore /usr/lib/bonobo-activationSecond specification:
ignore /usr/lib/bonobo*
None reported
The program xd was initially (before 1994) written for the MS-DOS platform. In 1994 it was redesigned to work under Unix (Linux, AIX) and it was converted to C++. The original C++ code is still available from tag start (https://gitlab.com/fbb-git/xd/tags, find the start tag and download) and is funny to look at as it is a remarkable illustration of C++ code written by C programmers who had just learned about C++. Versions 2.x were used until 2008, and in late August 2008 I rewrote xd completely, reflecting my then views about C++, eventually resulting in versions 3.x.y and beyond. The 3.x.y and later versions extensively use the facilities offered by the bobcat(7) library.
GDS was added to xd following a suggestion by Bram Neijt (bram at neijt dot nl).
Frank B. Brokken (f.b.brokken@rug.nl).