Commit Graph

112 Commits

Author SHA1 Message Date
Sidharth Kshatriya
0ca81e7cec Fix: Kakoune passed environment variables in shell invocations are repeated
If a %sh{} script refers to any variables multiple times they are all multiply
included in the environment. Example: if a %sh{} invocation refers to
${kak_buffile} 5 times, the environment will have "kak_buffile=..." repeated 5
times and so on. This repetition happens for each multiply used variable that
is passed into the environment.

The variable should, of course, be only passed into the environment once. This
commit should fix this issue.
2021-06-24 14:03:58 +05:30
Maxime Coste
4a59018dcd Do not select on non-urgent fd when handling only urgent events
This avoids 100% CPU usage when we have pending fifo input while running
a shell process, as we will not end-up busy looping in pselect but not
reading the available data due to being only processing urgent events.
2021-03-11 09:02:02 +11:00
Maxime Coste
f6c8ebc4d0 Refactor pipe reader/writer 2021-03-04 20:59:15 +11:00
Maxime Coste
74fc52b3de Write to stderr if execve fails
This should be rare but should not happen silently, this way it will
show in the parent process debug buffer.
2021-01-22 17:22:15 +11:00
Maxime Coste
0fd5a9d995 Slight code cleanup in generate_env 2021-01-22 17:21:59 +11:00
Maxime Coste
74c337df5d Add a libexec/ directory and use it to find the kak command
Add that libexec directory to the PATH instead of the current kak
binary directory to avoid impacting other commands.

The libexec directory currently only contains a symlink back to
the Kakoune binary.
2020-12-09 09:13:45 +11:00
Maxime Coste
0a66eb9c47 Expand env vars as list of strings
This makes it possible to do :select `%val{selections_decs}` and to
correctly combine $kak_quoted with those.
2020-03-02 20:53:28 +11:00
Maxime Coste
4b7b5d077c Make quoting opt-in by using $kak_quoted_... 2019-06-23 12:04:21 +10:00
Maxime Coste
3e89148d74 Fix missing errno include 2019-01-24 23:24:50 +11:00
Maxime Coste
566268d7bc Refactor RegexIterator to use a Sentinel 2019-01-20 22:59:28 +11:00
Maxime Coste
20e64f34bc Use fork instead of vfork on CYGWIN
Fixes #2653
2018-12-27 13:06:31 +11:00
Jason Felice
a4f830f143 Use _exit() after vfork()
Closes #2620

The docs for Mac OS X's vfork() requires it, and _exit() conforms to
POSIX.1-2008.

http://man7.org/linux/man-pages/man2/_exit.2.html
2018-12-07 09:36:06 -05:00
Maxime Coste
b897a18aa6 Use a dummy function for SIGPIPE instead of SIG_IGN
SIG_IGN is inherited after 'execve' and requires us to reset
that signal handler, which does not work well with vfork on
OSX. Using an empty function does the trick and will be auto
reset to default on exec.
2018-12-06 20:33:13 +11:00
Maxime Coste
d1274836cd Support KAKOUNE_POSIX_SHELL environment variable to choose the shell path
The shell will always be run with 'sh' as argv[0] to make shells such
as busybox sh supported.

Closes #2547
2018-11-27 22:21:20 +11:00
Maxime Coste
5250593129 ShellManager: Use vfork instead of fork
When large buffers have been opened, copying Kakoune's memory
page descriptors can get pretty slow, making fork more expensive
than necessary.

vfork avoids that problem. While not strictly conforming, it seems
the few calls we do before execve (open, close, dup2 and
set_signal_handler) would not cause any problems on platforms we
care about.
2018-11-27 21:49:57 +11:00
Maxime Coste
68aba9e353 Use shell specific quoting for env vars
Add a test case to validate roundtrips between Kakoune and the
shell.
2018-08-29 07:53:59 +10:00
Maxime Coste
f27700cc53 Restore SIGPIPE handler to default before spawning shell
Fixes #2238
2018-07-23 08:32:17 +10:00
Maxime Coste
43b72770ec Fix wrong logic for moving filedescriptors leading to closed stdin
With this fix, tests can now use /dev/null as stdin.

Fixes #2165
2018-06-28 22:56:50 +10:00
Maxime Coste
54b62cbef7 Do not expose C++ typeid().name to user facing errors on wrong option type
Fixes #2079
2018-05-26 10:01:26 +10:00
Maxime Coste
57baad4afd Make FaceRegistry scoped
set-face now takes a scope argument, and faces can be overridden on
a buffer or window basis.

colorscheme apply on global scope, which should be good enough for
now.

Fixes #1411
2018-04-07 16:27:50 +10:00
Maxime Coste
ea66465144 Restore previous status line after notifying wait for shell
Fixes prompt getting erased by the wait for shell message, and
having to manually trigger a redraw to see it again.
2018-04-01 10:08:54 +11:00
Maxime Coste
0baf562c93 Support full redraws during shell execution and handle resize there
Fixes #1973
2018-03-30 09:58:18 +11:00
Maxime Coste
49c52b025f Remove contains_that and use any_of to be closer to the c++ stdlib 2018-03-25 16:47:19 +11:00
Maxime Coste
a480e566dc ranges: Add transform overload taking directly a pointer to member
This overload will forward to the general transform implementation
using std::mem_fn to generate a callable.
2018-03-13 14:24:03 +11:00
Maxime Coste
5924694bda ShellManager: init from a static list of env vars
No need to go through a static list and then copy them one by
one in a vector.
2018-02-18 14:52:29 +11:00
Delapouite
7ecc3d343f Remove extraneous face when clearing status line 2018-01-11 15:26:42 +01:00
Maxime Coste
b81500c0e4 Use microseconds instead of milliseconds for built-in profiling 2017-06-07 20:06:47 +01:00
Maxime Coste
4495aefea6 Use range based find_if wrapper for finding shell env vars 2017-06-07 19:46:16 +01:00
Maxime Coste
caed8a55c7 Set stdin to /dev/null instead of closing it when we dont have data to pipe to child
Fixes #1330
Fixes #1331
2017-04-22 09:39:55 +01:00
Maxime Coste
52ffa98787 When not sending data to a subprocess, close its stdin
We were letting stdin untouched, which meant child processes had
access to our terminal input. That meant `!fmt` was trying to read
from our terminal input and catching keystrokes.

Fixes #1281
2017-04-17 20:39:24 +01:00
Maxime Coste
e44f95820e Fixes some clang-tidy warning and add a few missing meta.hh include 2017-03-16 23:34:02 +00:00
Maxime Coste
5f7464d90d Try to clean up option include a bit 2017-03-16 09:57:39 +00:00
Maxime Coste
db9b863222 Migrate WithBitOps template specialization to with_bit_ops function
This way we dont depend on knowing the base template to enable bit ops
on an enum type.
2017-03-15 18:00:58 +00:00
Maxime Coste
cb2e1a17b3 Fix some bugs in non blocking pipe writing 2017-02-03 18:40:03 +00:00
Maxime Coste
02b7e58481 Make piping data into shell commands non blocking
Fixes #1180
2017-02-03 01:14:42 +00:00
Maxime Coste
dcd8f6ef01 Apply clang-tidy modernize to the codebase 2017-01-08 22:39:01 +00:00
Maxime Coste
0daf7af493 Fix getting path confstr, the returned size includes the zero terminator
Closes #1047
2016-12-20 20:14:35 +00:00
Maxime Coste
9a879262a2 Use a POSIX guaranteed way of getting the shell path 2016-12-15 23:04:53 +00:00
Maxime Coste
8a74ef9804 Read as much as possible data from shell processes on each read event
We were reading at most 1024 bytes every time, going back to the event
loop.
2016-12-03 12:41:36 +00:00
Maxime Coste
7defdd3039 Make FDWatcher support Read, Write and Except events, instead of just Read 2016-12-01 19:44:07 +00:00
Maxime Coste
99a3388e41 Hide the waiting for shell message once the shell returns 2016-11-30 13:46:20 +00:00
Maxime Coste
61b3dfd184 Use a Timer for Shell waiting notification
Without a timer we were relying on other event sources to wake us
up to display the information, which was usually a NormalIdle or
a filesystem check timer.
2016-11-30 09:55:05 +00:00
Maxime Coste
12856066b1 Cleanup include dependencies a bit 2016-11-28 23:58:08 +00:00
Maxime Coste
a7cac87753 Display a status line message when Kakoune is waiting on a shell to complete
If a shell commands takes more than 1s to execute, a message will appear
on the status line notifying the user, along with the time Kakoune has
been waiting for.
2016-10-29 11:25:58 +01:00
Maxime Coste
025b91baca Convert some uses of lambda to more concise std::mem_fn 2016-10-10 23:44:18 +01:00
Maxime Coste
46a15534c5 Introduce chrono.hh 2016-07-24 21:25:05 +01:00
Maxime Coste
457e11bdc9 time window display buffer update in debug profile mode 2016-05-06 00:24:54 +01:00
Maxime Coste
75d22a8da7 Add another missing include in shell_manager.cc 2016-04-27 09:46:53 +01:00
Maxime Coste
2435949fae Add support for env var name completion
Fixes #659
2016-04-17 19:21:43 +01:00
Maxime Coste
d1b693270e ShellManager: do not open child stdin if there is no data to write to it
Fixes #383
2016-04-12 13:41:21 +01:00