Commit Graph

40 Commits

Author SHA1 Message Date
Érico Nogueira 8e956a0ded Change prompt character.
It's just more stylish.
2022-08-12 04:37:34 -03:00
Érico Nogueira 3de3e8b411 Avoid dirtying git state if possible. 2021-10-10 03:41:13 -03:00
Érico Nogueira d76a8794d5 Speed up git-status call.
Since we don't display the untracked files in the git repo info, we can
simply omit them from the git-status output. This makes it considerably
faster (about 5x - ~300ms to ~60ms - in my void-packages checkout) for
no loss of functionality.
2021-07-25 00:36:26 -03:00
Érico Nogueira bd30334277 Manually set thread stack sizes.
8KB was empirically determined to work on musl. We can't go lower (musl
supports up to 2KB) because posix_spawn allocates a temporary stack for
vfork (via clone(2)) on its own stack.

This improves our resource consumption and increases the likeliness for
pthread_create to work even when there isn't a lot of free memory.

Using pthread_setattr_default_np isn't possible, because on musl it
doesn't allow us to go below the default thread stack size. This way is
also more portable.

We don't remove the guard pages entirely, because a shell prompt might
be active in attacker controlled directories, and it's a reasonable
protection against any stack overflow exploits that might appear.
2021-07-17 20:58:16 -03:00
Érico Nogueira 9dc6a30743 Make pthread_create failures non-fatal. 2021-07-17 20:04:15 -03:00
Érico Nogueira 8ffece2e54 Disable color support in lang output.
Looks ugly when using emoji.
2021-07-17 19:52:29 -03:00
Érico Nogueira 089bb40acc Use color support where appropriate.
Color choice might still be refined, as could support for 8 bit colors.
2021-07-17 19:47:50 -03:00
Érico Nogueira 765316cf81 Add color support.
Use fwrite() directly instead of p(), since we know the string size.
Foreground color values from table in [1].

Also add NOCOLOR option in Makefile to completely disable color support.

[1] https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
2021-07-17 19:39:15 -03:00
Érico Nogueira b3d101fdce Improve Makefile.
- make LANGUAGE a simpler variable instead of the complete file path
- add more warnings
- add clean target
2021-07-17 18:55:56 -03:00
Érico Nogueira d5a37495b0 Remove outdated comment.
We treat allocation failures correctly: some features are lost, but most
of the prompt is still printed.
2021-07-17 18:46:26 -03:00
Érico Nogueira 11e4318cda Optimize git status parsing slightly.
Instead of paying for multiple function calls and any string parsing at
all, use a fast integer that can fit at least two chars inside and
compare them directly.

We also move the struct and enum declarations into the only function
that uses them.

Also make the .s buffer for the resulting string smaller. It doesn't
need 64 chars.
2021-07-17 18:40:32 -03:00
Érico Nogueira 2bf4d41ff1 Add timeout for git status command.
0.8s is an empirically good value here; prevents the prompt for hanging
on big repos that aren't cached.
2021-07-17 18:26:50 -03:00
Érico Nogueira fe592ae335 Keep special characters in a #define block.
Makes it easy to customize their usage.
2021-07-17 18:23:51 -03:00
Érico Nogueira fbb035e1f9 Fix memory leak in ep.c.
The masks were allocated in the lang scanner function and should be
freed after being read. Add macro to do the whole operation cleanly.
2021-06-23 16:05:22 -03:00
Érico Nogueira c20e6f66f1 Fix memory leaks in lang.c.
If opendir() failed, mask would leak.

The directory stream returned by opendir() wasn't being closed anywhere.
2021-06-23 15:59:34 -03:00
Érico Nogueira 8161ac446e Fix calloc in lang.c.
calloc should receive the size of the variable mask points to, not the
size of the pointer itself. Could have lead to memory corruption in
32-bit platforms.
2021-03-11 02:49:44 -03:00
Érico Nogueira aa2817dd77 Don't depend on getenv being reentrant in ssh.c.
This is likely a standards bug and getenv should be re-entrant (it
should, after all, also be threadsafe if no one is writing to the
environment), but it didn't cost much to work around it.
2021-03-11 02:44:21 -03:00
Érico Rolim 46ea87ea21 Fix showing current path again.
Avoid unnecessary heap allocations (though we added new ones in main())
if possible by using a PATH_MAX buffer.

Check for PWD matching current directory ourselves, which allows us to
save a stat syscall, by re-using the stat(".") result to compare to
stat("$HOME"). Improve how we check if HOME is actually part of pwd -
previous would get confused with "${HOME}char", which should not get the
prompt to display '~'.

Use strtok_r to scan characters now. Writing directly to p() makes more
sense than writing chars to a buffer, so remove that.

I'm somewhat unhappy with the rpwd and mrpwd solution, since while
coding I forgot to set one or the other a couple of times. It would be
nice if I could "unconst" the variable at some point, though I greatly
dislike that pattern.
2021-03-07 04:17:23 -03:00
Érico Rolim cd48564223 Remove global variables from git.c.
Use a struct to handle the produced values and pass them around.
Also improve error handling very slightly, and free some memory.
2021-03-07 02:36:13 -03:00
Érico Rolim 6a59d13de2 Use get_current_dir_name in path.c.
get_current_dir_name will use the value of PWD if it matches the current
directory, which allows us to show the current directory using the path
the shell's prompt would show (the shell exports PWD to the process).

Also re-organize the function, fixing the lack of path shortening in
paths outside HOME - fish_style_dir was being applied only for paths
under HOME.
2021-03-07 01:30:10 -03:00
Érico Rolim 4ca87587df Remove unnecessary usage of sig_atomic_t.
Member launched of struct threaded_task should be accessed after some
sort of synchronization happens (what we currently do is join the thread
that touches the struct), so it doesn't need to be an atomic variable.
2021-03-07 01:24:48 -03:00
Érico Rolim 89d0c706a6 Show time as 1h31m45s for command duration. 2021-02-23 01:09:41 -03:00
Érico Rolim 9eecdc24bc Detect a void-packages repository. 2021-02-22 12:35:53 -03:00
Érico Rolim 815fdf1294 Fix hostname printing.
ssh doesn't set HOSTNAME in env, that has to be determined separately.
What indicates a ssh session are some SSH_* env vars.
2021-02-22 12:34:34 -03:00
Érico Rolim 1f1adc1663 Don't print exit status when it's due to command not found. 2021-02-22 12:24:07 -03:00
Érico Rolim 54c8d17c2b Add support for printing information about previous process. 2021-02-22 05:52:34 -03:00
Érico Rolim 7d65dfbd88 Add more languages / misc detections. 2021-02-22 05:37:45 -03:00
Érico Rolim 558c62cd14 Improve the git status prompt a bit. 2021-02-22 05:12:26 -03:00
Érico Rolim 35d6806b54 Add python detection and some utility macros to avoid repetition. 2021-02-22 05:11:16 -03:00
Érico Rolim 14cb4cbed4 Avoid using any globals in language detection. 2021-02-22 05:00:11 -03:00
Érico Rolim 81c7f243a7 Add framework to display detected programming languages.
Very dumb initial C detection.
2021-02-22 04:43:40 -03:00
Érico Rolim c7a24d775d Support more of git status output. 2021-02-22 03:12:52 -03:00
Érico Rolim dc4a59881c Enable git status reporting.
Also reorganize git.c to contain most of the implementation details,
main just calls the functions without any arguments.
2021-02-22 02:40:31 -03:00
Érico Rolim 31069036ab Add missing -pthread to Makefile and -static for convenience. 2021-02-22 02:39:33 -03:00
Érico Rolim 780151cfee Change translated strings to .c file. 2021-02-22 01:57:46 -03:00
Érico Rolim fdf2b43b34 Move output and path handling code outside main.
Temporarily add static to translation strings to allow compilation to
work.
2021-02-22 01:53:44 -03:00
Érico Rolim d8b6432c6b Fix git.h, move it to ep.h. 2021-02-22 01:43:22 -03:00
Érico Rolim 3fe513c4c9 Add basic git functionality and error logging. 2021-02-22 01:39:58 -03:00
Érico Rolim c5cb3277a9 Add chroot and job count support. 2021-02-22 01:09:07 -03:00
Érico Rolim e779146066 Initial commit. 2021-02-22 00:38:41 -03:00