Data Structures | Macros | Functions
shell.c File Reference
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <uv.h>
#include "nvim/ascii.h"
#include "nvim/lib/kvec.h"
#include "nvim/log.h"
#include "nvim/event/loop.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/rstream.h"
#include "nvim/os/shell.h"
#include "nvim/os/signal.h"
#include "nvim/types.h"
#include "nvim/main.h"
#include "nvim/vim.h"
#include "nvim/message.h"
#include "nvim/memory.h"
#include "nvim/ui.h"
#include "nvim/screen.h"
#include "nvim/memline.h"
#include "nvim/option_defs.h"
#include "nvim/charset.h"
#include "nvim/strings.h"

Data Structures

struct  DynamicBuffer


#define DYNAMIC_BUFFER_INIT   { NULL, 0, 0 }
#define NS_1_SECOND   1000000000U
#define OUT_DATA_THRESHOLD   1024 * 10U


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 os_system (char **argv, const char *input, size_t len, char **output, size_t *nread) FUNC_ATTR_NONNULL_ARG(1)

Macro Definition Documentation

#define DYNAMIC_BUFFER_INIT   { NULL, 0, 0 }
#define NS_1_SECOND   1000000000U
#define OUT_DATA_THRESHOLD   1024 * 10U

Function Documentation

int os_call_shell ( char_u cmd,
ShellOpts  opts,
char_u extra_args 

Calls the user-configured 'shell' (p_sh) for running a command or wildcard expansion.

cmdThe command to execute, or NULL to run an interactive shell.
optsOptions that control how the shell will work.
extra_argsExtra arguments to the shell, or NULL.
shell command exit code
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);

argvThe commandline arguments to be passed to the shell. argv will be consumed.
inputThe input to the shell (NULL for no input), passed to the stdin of the resulting process.
lenThe length of the input buffer (not used if input == NULL)
[out]outputPointer 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]nreadthe number of bytes in the returned buffer (if the returned buffer is not NULL)
the return code of the process, -1 if the process couldn't be started properly
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 ("...").

[allocated] 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"]

cmdCommand string, or NULL to run an interactive shell.
extra_argsExtra arguments to the shell, or NULL.
Newly allocated argument vector. Must be freed with shell_free_argv.
void shell_free_argv ( char **  argv)

Releases the memory allocated by shell_build_argv.

argvThe argument vector.