Skip to main content
Module

x/denops_std/function/mod.ts>shellescape

📚 Standard module for denops.vim
Go to Latest
function shellescape
import { shellescape } from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";

Escape {string} for use as a shell command argument. When the 'shell' contains powershell (MS-Windows) or pwsh (MS-Windows, Linux, and macOS) then it will enclose {string} in single quotes and will double up all internal single quotes. On MS-Windows, when 'shellslash' is not set, it will enclose {string} in double quotes and double all double quotes within {string}. Otherwise it will enclose {string} in single quotes and replace all "'" with "'''".

When the {special} argument is present and it's a non-zero Number or a non-empty String (non-zero-arg), then special items such as "!", "%", "#" and "<cword>" will be preceded by a backslash. This backslash will be removed again by the :! command.

The "!" character will be escaped (again with a non-zero-arg {special}) when 'shell' contains "csh" in the tail. That is because for csh and tcsh "!" is used for history replacement even when inside single quotes.

With a non-zero-arg {special} the <NL> character is also escaped. When 'shell' containing "csh" in the tail it's escaped a second time.

The "" character will be escaped when 'shell' contains "fish" in the tail. That is because for fish "" is used as an escape character inside single quotes.

Example of use with a :! command:

:exe '!dir ' .. shellescape(expand('<cfile>'), 1)

This results in a directory listing for the file under the cursor. Example of use with system():

:call system("chmod +w -- " .. shellescape(expand("%")))

See also ::S.

Can also be used as a method:

GetCommand()->shellescape()

Parameters

denops: Denops
string: unknown
optional
special: unknown

Returns

Promise<string>