xd(1)

xd - fast directory changes
(xd.5.00.01)

1994-2023

NAME

xd - eXtra fast Directory changer

SYNOPSIS

xd [OPTIONS] arguments

DESCRIPTION

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/bin
        
If 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.

DIRECT KEY ENTRY

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 = 0
        
If, 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=1
        
Then, 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 "$*"`
    }

GENERALIZED DIRECTORY SEARCH

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;

With the traditional processing mode only the first one of these alternative patterns is considered.

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:

In this set all of the previous patterns showing the ...mp... combination were dropped, as a directory change is forced between the m and p characters.

RETURN VALUES

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:

OPTIONS

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.

CONFGURATION 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.

SHELL SCRIPTS

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.

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"'
        

EXAMPLES


    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 directory
    
Assuming the following directories exist:

  /usr/lib/bonobo
  /usr/lib/bonobo-activation
  /usr/local/bin
    
then 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-activation
    
Second specification:

  ignore /usr/lib/bonobo*
    

FILES

SEE ALSO

bash(1), ioctl(2), sysctl(8), tcsh(1)

BUGS

None reported

ABOUT xd

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.

ACKNOWLEDGEMENTS

GDS was added to xd following a suggestion by Bram Neijt (bram at neijt dot nl).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).