aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/shell.h
blob: 776c36d38475e6119f7ded8b1c8b041cfc6e1eea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef NEOVIM_OS_SHELL_H
#define NEOVIM_OS_SHELL_H

#include <stdbool.h>

#include "types.h"

// Flags for mch_call_shell() second argument
typedef enum {
  kShellOptFilter = 1,      ///< filtering text
  kShellOptExpand = 2,      ///< expanding wildcards
  kShellOptCooked = 4,      ///< set term to cooked mode
  kShellOptDoOut = 8,       ///< redirecting output
  kShellOptSilent = 16,     ///< don't print error returned by command
  kShellOptRead = 32,       ///< read lines and insert into buffer
  kShellOptWrite = 64,      ///< write lines from buffer
  kShellOptHideMess = 128,  ///< previously a global variable from os_unix.c
} ShellOpts;

/// Builds the argument vector for running the shell configured in `sh`
/// ('shell' option), optionally with a command that will be passed with `shcf`
/// ('shellcmdflag').
///
/// @param cmd Command string. If NULL it will run an interactive shell.
/// @param extra_shell_opt Extra argument to the shell. If NULL it is ignored
/// @return A newly allocated argument vector. It must be freed with
///         `shell_free_argv` when no longer needed.
char ** shell_build_argv(char_u *cmd, char_u *extra_shell_arg);

/// Releases the memory allocated by `shell_build_argv`.
///
/// @param argv The argument vector.
void shell_free_argv(char **argv);

/// Calls the user shell for running a command, interactive session or
/// wildcard expansion. It uses the shell set in the `sh` option.
///
/// @param cmd The command to be executed. If NULL it will run an interactive
///        shell
/// @param opts Various options that control how the shell will work
/// @param extra_shell_arg Extra argument to be passed to the shell
int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg);

#endif  // NEOVIM_OS_SHELL_H