Typex
Unix CLI that provides salient information about installed commands and programs, combining elements from standard Unix utilities type, which, and file.
Install / Use
/learn @mklement0/TypexREADME
Contents
<!-- END doctoc generated TOC please keep comment here to allow auto update -->typex — introduction
typex is an enhanced version of the type Unix shell builtin that
incorporates features from the which and file utilities:
By default, it provides information about the current shell.
Given a name, it indicates how the current shell would interpret that name as a command, and provides information about each command form found.
Given a filesystem path, it provides information such as file type and canonical path.
typex extends type as follows:
- All defined forms of a given command name are (always) reported, which includes shell keywords, aliases, shell functions, builtins, and executables.
- Defined forms are listed in descending order of precedence - the first form listed is the effective one.
- If an executable is a symlink, the entire chain of symlinks up to and including the ultimate target is printed, using absolute paths.
- The type of executable is printed, including the specific shell/interpreter used to run executable scripts.
- Version information, if available, is printed for executables.
- Optionally, you can get information about any filesystem object, including its canoncial path and symlink chain, if applicable.
Note: typex is designed for interactive use, to provide humans with concise, salient information about a command or filesystem object.
As such, its output is geared toward readability by humans, and should not be relied on for programmatic parsing.
See the examples below, concise usage information further below, or read the manual.
For supported platforms and shells, see the Installation chapter.
Examples
# Print information about the current shell.
$ typex
BINARY: /bin/bash [GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)]
# Print information about command forms named 'printf' in order of precedence.
$ typex printf
BUILTIN: printf
BINARY: /usr/bin/printf [printf (GNU coreutils) 8.21]
# Print information about binary 'nawk'; note the chain of symlinks,
# and its use of *absolute* paths, as well as the version information.
$ typex nawk
BINARY: /usr/bin/nawk@ -> /etc/alternatives/nawk@ -> /usr/bin/gawk [GNU Awk 4.0.1]
# Print information about executable script 'npm';
# note the interpreter information ('POSIX shell script').
$ typex npm
SCRIPT: /usr/bin/npm@ -> /usr/lib/node_modules/npm/bin/npm-cli.js (POSIX shell script) [2.11.3]
# Print information about an alias:
$ alias lsx='ls -FAhl'
$ typex lsx
ALIAS: lsx='ls -FAhl'
BINARY: /bin/ls [ls (GNU coreutils) 8.21]
# Print the canonical path of a directory:
$ typex /etc/apache2/
DIRECTORY: /etc/apache2 -> /private/etc/apache2
# Print extended information about special file /dev/null
$ typex -v /dev/null
FILE: /dev/null (character special )
crw-rw-rw- 1 root root 1, 3 Feb 1 19:43
Installation
Supported platforms
- When installing from the npm registry: Linux and OS X
- When installing manually: any Unix-like platform with Bash that uses either BSD or GNU utilities.
Supported shells
For this utility to detect the current shell's aliases, keywords, functions, and builtins, it must be sourced, which is supported in the following shells:
- Bash, Ksh, and Zsh
typex can still be useful in unsupported shells when invoked standalone (in which case it runs in bash), albeit in limited form:
- only executable files and filesystem objects will be detected - no other command forms.
- a warning to that effect is printed; you can suppress it with
-p
Simply put, non-sourced use of typex amounts to an enhanced version of the which utility.
Installation from the npm registry
<sup>Note: Even if you don't use Node.js, its package manager, npm, works across platforms and is easy to install; try curl -L http://git.io/n-install | bash</sup>
With Node.js or io.js installed, install the package as follows:
[sudo] npm install typex -g
Note:
- Whether you need
sudodepends on how you installed Node.js / io.js and whether you've changed permissions later; if you get anEACCESerror, try again withsudo. - The
-gensures global installation and is needed to puttypexin your system's$PATH.
IMPORTANT: After installation, run typex -i to add sourcing of typex to the per-user initialization file of all supported shells that are present (e.g., ~/.bashrc).
To remove these sourcing commands later, run typex -u.
Manual installation
- Download this
bashscript astypex. - Make it executable with
chmod +x typex. - Move it or symlink it to a folder in your
$PATH, such as/usr/local/bin(OS X) or/usr/bin(Linux).
IMPORTANT: After installation, run typex -i to add sourcing of typex to the per-user initialization file of all supported shells that are present (e.g., ~/.bashrc).
To remove these sourcing commands later, run typex -u.
Usage
Find concise usage information below; for complete documentation, read the manual online, or, once installed, run man typex (typex --man if installed manually).
$ typex --help
Reports salient information about available commands, programs, and
filesystem items, such as command or file type, (ultimate) location,
and version.
typex [-p] [-V] [-v] [<nameOrPath>...]
-p look for files only (ignore shell aliases, keywords, functions,
builtins)
-V skip attempt to obtain executable version information
-v verbose mode: report additional information
Install / uninstall sourcing via shell-initialization files (required
to detect aliases, functions, shell builtins - supported in
Bash, Ksh, Zsh):
typex -i
typex -u
<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the contents of 'LICENSE.md'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. -->
License
Copyright (c) 2015-2020 Michael Klement mklement0@gmail.com (http://same2u.net), released under the MIT license.
Acknowledgements
This project gratefully depends on the following open-source components, according to the terms of their respective licenses.
npm dependencies below have optional suffixes denoting the type of dependency; the absence of a suffix denotes a required run-time dependency: (D) denotes a development-time-only dependency, (O) an optional dependency, and (P) a peer dependency.
npm dependencies
<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the contents of 'CHANGELOG.md'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. -->Changelog
Versioning complies with semantic versioning (semver).
<!-- NOTE: An entry template is automatically added each time `make version` is called. Fill in changes afterwards. -->-
v0.4.3 (2020-10-13):
- [fix] npm v6.14.8 inexplicably complains about the "install" command in package.json (which simply printfs an informational message), so it is diabled for now.
-
v0.4.2 (2020-10-13):
- [fix] Syntax error fixed that was masked by an accidental non-breaking space Unicode char.
-
v0.4.1 (2015-09-21):
- [fix]
typex /now works correctly.
- [fix]
-
v0.4.0 (2015-09-21):
- [potentially breaking change]
typexnow accepts options after operands as well (except after--), and now also accepts long option names. - [doc]
typexnow has a man page (if manually installed, usetypex --man);typex -hnow just prints concise usage information. - [doc] Read-me improved.
- [f
- [potentially breaking change]
