#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <uv.h>
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/ex_cmds.h"
#include "nvim/fileio.h"
#include "nvim/lib/kvec.h"
#include "nvim/log.h"
#include "nvim/main.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/option_defs.h"
#include "nvim/os/shell.h"
#include "nvim/os/signal.h"
#include "nvim/path.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/tag.h"
#include "nvim/types.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
Data Structures | |
struct | DynamicBuffer |
Macros | |
#define | DYNAMIC_BUFFER_INIT { NULL, 0, 0 } |
#define | NS_1_SECOND 1000000000U |
#define | OUT_DATA_THRESHOLD 1024 * 10U |
#define | SHELL_SPECIAL (char_u *)"\t \"&'$;<>()\\|" |
#define | STYLE_ECHO 0 |
#define | STYLE_GLOB 1 |
#define | STYLE_VIMGLOB 2 |
#define | STYLE_PRINT 3 |
#define | STYLE_BT 4 |
#define | MAX_CHUNK_SIZE (OUT_DATA_THRESHOLD / 2) |
Functions | |
int | os_expand_wildcards (int num_pat, char_u **pat, int *num_file, char_u ***file, int flags) FUNC_ATTR_NONNULL_ARG(4) |
char ** | shell_build_argv (const char *cmd, const char *extra_args) FUNC_ATTR_NONNULL_RET |
void | shell_free_argv (char **argv) |
char * | shell_argv_to_str (char **const argv) FUNC_ATTR_NONNULL_ALL |
int | os_call_shell (char_u *cmd, ShellOpts opts, char_u *extra_args) |
int | call_shell (char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) |
char_u * | get_cmd_output (char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret_len) |
int | os_system (char **argv, const char *input, size_t len, char **output, size_t *nread) FUNC_ATTR_NONNULL_ARG(1) |
#define DYNAMIC_BUFFER_INIT { NULL, 0, 0 } |
#define MAX_CHUNK_SIZE (OUT_DATA_THRESHOLD / 2) |
#define NS_1_SECOND 1000000000U |
#define OUT_DATA_THRESHOLD 1024 * 10U |
#define SHELL_SPECIAL (char_u *)"\t \"&'$;<>()\\|" |
#define STYLE_BT 4 |
#define STYLE_ECHO 0 |
#define STYLE_GLOB 1 |
#define STYLE_PRINT 3 |
#define STYLE_VIMGLOB 2 |
os_call_shell() wrapper. Handles 'verbose', :profile, and v:shell_error. Invalidates cached tags.
Get the stdout of an external command. If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not NULL store the length there.
cmd | command to execute |
infile | optional input file name |
flags | can be kShellOptSilent or 0 |
ret_len | length of the stdout |
Calls the user-configured 'shell' (p_sh) for running a command or wildcard expansion.
cmd | The command to execute, or NULL to run an interactive shell. |
opts | Options that control how the shell will work. |
extra_args | Extra arguments to the shell, or NULL. |
Performs wildcard pattern matching using the shell.
num_pat | is the number of input patterns. | |
pat | is an array of pointers to input patterns. | |
[out] | num_file | is pointer to number of matched file names. Set to the number of pointers in *file. |
[out] | file | is pointer to array of pointers to matched file names. Memory pointed to by the initial value of *file will not be freed. Set to NULL if FAIL is returned. Otherwise points to allocated memory. |
flags | is a combination of EW_* flags used in expand_wildcards(). If matching fails but EW_NOTFOUND is set in flags or there are no wildcards, the patterns from pat are copied into *file. |
int os_system | ( | char ** | argv, |
const char * | input, | ||
size_t | len, | ||
char ** | output, | ||
size_t * | nread | ||
) |
os_system - synchronously execute a command in the shell
example: char *output = NULL; size_t nread = 0; char *argv[] = {"ls", "-la", NULL}; int exitcode = os_sytem(argv, NULL, 0, &output, &nread);
argv | The commandline arguments to be passed to the shell. argv will be consumed. | |
input | The input to the shell (NULL for no input), passed to the stdin of the resulting process. | |
len | The length of the input buffer (not used if input == NULL) | |
[out] | output | Pointer to a location where the output will be allocated and stored. Will point to NULL if the shell command did not output anything. If NULL is passed, the shell output will be ignored. |
[out] | nread | the number of bytes in the returned buffer (if the returned buffer is not NULL) |
char* shell_argv_to_str | ( | char **const | argv | ) |
Joins shell arguments from argv
into a new string. If the result is too long it is truncated with ellipsis ("...").
argv
joined to a string. char** shell_build_argv | ( | const char * | cmd, |
const char * | extra_args | ||
) |
Builds the argument vector for running the user-configured 'shell' (p_sh) with an optional command prefixed by 'shellcmdflag' (p_shcf). E.g.:
["shell", "-extra_args", "-shellcmdflag", "command with spaces"]
cmd | Command string, or NULL to run an interactive shell. |
extra_args | Extra arguments to the shell, or NULL. |
void shell_free_argv | ( | char ** | argv | ) |
Releases the memory allocated by shell_build_argv
.
argv | The argument vector. |