Commit Graph

21 Commits

Author SHA1 Message Date
Johannes Altmanninger
ec939fb22f Work around BSD man calling pager when stdout is not a TTY
With BSD man, "PAGER=vim man man | cat" hangs because
[man](https://cgit.freebsd.org/src/tree/usr.bin/man/man.sh) wrongly
calls the pager even though stdout is not a terminal.

This hang manifests in places where we call apropos in a subshell,
such as in "complete -Ccar".

Let's work around this I guess. This should really be fixed upstream
because it's a problem in every app that wants to display man pages
but doesn't emulate a complete terminal.

Weirdly, the Apple derivative of man.sh uses WHATISPAGER instead
of MANPAGER.

Closes #10820
2024-10-30 04:58:50 +01:00
Peter Ammon
c227233571
fish_apropos: use realpath instead of readlink
readlink -f is not supported on macOS Big Sur (from 2020).
2024-09-29 18:13:36 -07:00
Rebecca Turner
a6c8cd6e85 Fix man completions on macOS with symlinked manpath
When `manpath` prints a symlink to a directory, `/usr/libexec/makewhatis`
ignores the entire directory:

```
$ /usr/libexec/makewhatis -o /tmp/whatis \
    (/usr/bin/manpath | string split :)
makewhatis: /Users/wiggles/.nix-profile/share/man: Not a directory
```

This means that the built-in `man` completions will not index any commands in
these directories.

If we pass the directories to `readlink -f` first, `makewhatis` correctly
indexes the `man` pages.

```
$ /usr/libexec/makewhatis -o /tmp/whatis \
    (/usr/bin/manpath | string split : | xargs readlink -f)
```
2024-09-14 13:38:33 -07:00
Amy Grace
4c9fa511e8 Force use of macOS's builtin manpath
Prevent a useless warning msg if Homebrew's `man-db` is installed and configured
2023-06-06 13:12:30 -05:00
Aaron Gyes
c887e5dbde Fix apropos completions
The 'str' variable was apparently mistakenly removed by 49c5f96470.

Re-add it, and regex-escape it as well.

Allow completing on apropos <TAB> instaed of requiring an initial char.

Use __fish_apropos instead of apropos.

New regex to hopefully work on more platforms.

Explicitly use ^ instead of adding it at __fish_apropos
2022-10-28 10:01:35 -07:00
Aaron Gyes
53cb3a98fc fish_apropos: manpath instead of man --path
On macOS Ventura, `man` does not take --path
2022-10-21 15:20:57 -07:00
Fabian Boehm
5dfb64b547
Add path mtime (#9057)
This can be used to print the modification time, like `stat` with some
options.

The reason is that `stat` has caused us a number of portability
headaches:

1. It's not available everywhere by default
2. The versions are quite different

For instance, with GNU stat it's `stat -c '%Y'`, with macOS it's `stat
-f %m`.

So now checking a cache file can be done just with builtins.
2022-07-18 20:39:01 +02:00
Max Nordlund
85ea9bf781
Hide whatis database building from the user (#8310)
* Hide whatis database building from the user

It's really an internal detail, but shows up in prompts that display how many
background jobs are running.

By disowning it keeps running but won't show up in `jobs` or get killed if the user
exits the shell.

* Update __fish_apropos.fish
2021-09-23 10:59:44 +02:00
Fabian Homborg
fcbf303e05 Only do the macOS apropos thing if makewhatis is available
This won't work without it, and happens to be broken on jailbroken
iOS.

Fixes #8205.
2021-08-04 18:55:01 +02:00
Johannes Altmanninger
1b20e75f19 Run fish_indent on share/**.fish 2021-08-01 18:59:45 +02:00
Fabian Homborg
2e9dab71a3 __fish_apropos: Don't overwrite $dir 2021-04-30 20:09:56 +02:00
Fabian Homborg
c25efeed7a __fish_apropos: Fix broken variable name 2021-04-30 20:07:20 +02:00
Fabian Homborg
f485169391 __fish_apropos: Fix on macOS
Because MacOS' apropos is bad and doesn't support the `--` option
separator, this apparently spews errors.

Because the argument _can't_ start with a `-` (because we add a `^`),
we can just remove it.

Fixes #7965.
2021-04-30 19:16:57 +02:00
Fabian Homborg
19004642ba __fish_apropos: Define again on non-macOS
This had a weirdly broken if condition.
2021-04-02 16:58:34 +02:00
Aaron Gyes
b9b2010342 rebuild whatis database weekly, not daily
I still don't think we even address rebuilding
manpage completions yet. Maybe they could share a
solution.
2021-04-02 02:12:00 -07:00
Aaron Gyes
0e03e49eb9 __fish_apropos: prepend $argv with ^
Because macOS' `apropos` is just using grep, and we only need
a prefix match for __fish_describe_command, we can shave off
some ok total execution time here.
2021-04-02 01:58:38 -07:00
Aaron Gyes
85e3381480 __fish_apropos: refactor, limit to 10.15+, change default cache dir.
No longer uses the __fish_apropos hack on every version of macOS.
Juat Catalina+.

The whatis database generated and replaced daily is 2 megabytes on
my computer, and in ~/.cache on a home dir might wind up on a net
mount or something annoying. or, definitely it's backed up by default.

It's wiser to throw that junk in with other cache files on the system
aka DARWIN_USER_CACHE_DIR, and only use the XDG directory if
someone specifically configured that.

Mainly, this just means at least it won't automatically get backed
up by Time Machine and stuff every day, which is no big deal but
y'know...

Rearranged stuff a little to not shell out every time.
2021-04-02 01:58:38 -07:00
Fabian Homborg
dfebfcf376 __fish_apropos: Also add "--" separator
This actually *worked* in my tests which confuses me.

It really shouldn't, `apropos -foo` will complain about "-o" not being
a valid option.

It should be `apropos -- -foo`.

Now, of course there are awful apropos implementations, so let's see
if someone complains
2021-03-10 07:22:17 +01:00
Fabian Homborg
fb57ca8791 __fish_apropos: Use macOS' stat explicitly
Overrides the GNU tools some people use.

Fixes #7390.
2020-10-09 18:58:35 +02:00
ridiculousfish
a6686ca310 Run makewhatis in the background
In the new __fish_apropos, makewhatis is run explicitly to generate the
whatis database. However this can be a little slow. Run it in the
background, after the apropos call completes so as to avoid a weird
race.

This means that descriptions may not be available the first time the
user invokes it, but that's better than appearing to hang for a while.
2020-10-03 17:09:00 -07:00
Folke Lemaitre
a6a0d43c9c Better __fish_describe_command for Macos
override MANPATH used by apropos with local whatis database and update it once a day

get rid of xargs

Created __fish_apropos and fixed __fish_complete_man to use that as well

moved macos apropos comment
2020-10-03 16:18:44 -07:00