3.3.2 Argument Modifiers

You can use argument modifiers to manipulate argument values. For example, you can sort lists, remove duplicate values, capitalize words, etc. All argument modifiers are prefixed by ‘:’, so ‘$exec-path(:h:u:x/^\/home/)’ lists all of the unique parent directories of the elements in exec-path, excluding those in /home.

E

Re-evaluates the value as an Eshell argument. For example, if foo is "${echo hi}", then the result of ‘$foo(:E)’ is hi.

L

Converts the value to lower case.

U

Converts the value to upper case.

C

Capitalizes the value.

h

Treating the value as a file name, gets the directory name (the “head”). For example, ‘foo/bar/baz.el(:h)’ expands to ‘foo/bar/’.

t

Treating the value as a file name, gets the base name (the “tail”). For example, ‘foo/bar/baz.el(:t)’ expands to ‘baz.el’.

e

Treating the value as a file name, gets the final extension of the file, excluding the dot. For example, ‘foo.tar.gz(:e)’ expands to gz.

r

Treating the value as a file name, gets the file name excluding the final extension. For example, ‘foo/bar/baz.tar.gz(:r)’ expands to ‘foo/bar/baz.tar’.

q

Marks that the value should be interpreted by Eshell literally, so that any special characters like ‘$’ no longer have any special meaning.

s/pattern/replace/

Replaces the first instance of the regular expression pattern with replace. Signals an error if no match is found.

As with other modifiers taking string parameters, you can use different delimiters to separate pattern and replace, such as ‘s'…'…'’, ‘s[…][…]’, or even ‘s[…]/…/’.

gs/pattern/replace/

Replaces all instances of the regular expression pattern with replace.

i/pattern/

Filters a list of values to include only the elements matching the regular expression pattern.

x/pattern/

Filters a list of values to exclude all the elements matching the regular expression pattern.

S
S/pattern/

Splits the value using the regular expression pattern as a delimiter. If pattern is omitted, split on spaces.

j
j/delim/

Joins a list of values, inserting the string delim between each value. If delim is omitted, use a single space as the delimiter.

o

Sorts a list of strings in ascending lexicographic order, comparing pairs of characters according to their character codes (see Text Comparison in The Emacs Lisp Reference Manual).

O

Sorts a list of strings in descending lexicographic order.

u

Removes any duplicate elements from a list of values.

R

Reverses the order of a list of values.