Code Monkey home page Code Monkey logo

Comments (7)

tpope avatar tpope commented on June 12, 2024 1

Looks like man uses MANPAGER even when not connected to a terminal, which isn't what I would expect, but works to our advantage as a straightforward solution.

from vim-fugitive.

finite-state-machine avatar finite-state-machine commented on June 12, 2024

Relevant, and perhaps helpful: https://stackoverflow.com/questions/60106514/

from vim-fugitive.

tpope avatar tpope commented on June 12, 2024

This works fine on Linux, and I could have sworn it used to work fine on macOS. I wonder if something changed.

https://unix.stackexchange.com/questions/13267/how-to-disable-styling-on-man-pages demonstrates the behavior I expect: ASCII style formatting is disabled when TERM=dumb. Making Fugitive responsible for cleaning it up is inconvenient, to say the least.

from vim-fugitive.

finite-state-machine avatar finite-state-machine commented on June 12, 2024

I agree it doesn't make sense for Fugitive to mess around with control bytes.

I can see three possible fixes:

  • [always] set TERM=dumb or pipe through col -b, if this doesn't cause other problems
  • [always] wrap man in a shell script, put the wrapper in a temp dir, and put the temp dir at the front of the $PATH when invoking git
  • [conditional] detect --help (but presumably not after --) and conditionally use TERM or col

Obviously some of this doesn't make sense on Windows or other non-POSIXy platforms.

The wrapper script might look like this:

#!/usr/bin/env sh

TERM=dumb /path/to/real/man $@

(My shell script is rusty; take this with a grain of salt.)

I'm willing to help in principle, but I'm not experienced with VIm scripting.

from vim-fugitive.

tpope avatar tpope commented on June 12, 2024

I agree it doesn't make sense for Fugitive to mess around with control bytes.

I can see three possible fixes:

  • [always] set TERM=dumb or pipe through col -b, if this doesn't cause other problems

We do always set TERM=dumb. The problem is that on macOS, TERM=dumb is ignored.

Always setting col -b feels like a bad idea. For other commands, I don't want to be perpetually unsure if the output is mangled or not.

  • [always] wrap man in a shell script, put the wrapper in a temp dir, and put the temp dir at the front of the $PATH when invoking git

This is probably the least worst option. Inconvenient but not impossible. There's also man.man.path that could be pointed at the wrapper script to avoid getting PATH involved.

  • [conditional] detect --help (but presumably not after --) and conditionally use TERM or col

We already detect --help, so that part's fine. But conditionally using col means we can't just directly execute git, we need to involve the shell. This is more disruptive than the last one.

Obviously some of this doesn't make sense on Windows or other non-POSIXy platforms.

This complicates the implementation, and is part of the "inconvenient", but not a deal breaker.

The wrapper script might look like this:

#!/usr/bin/env sh

TERM=dumb /path/to/real/man $@

What is /path/to/real/man here? If there's another man we could call that does the right thing, we could do away with the wrapper script entirely, and it gets a lot less annoying.

from vim-fugitive.

finite-state-machine avatar finite-state-machine commented on June 12, 2024

What is /path/to/real/man here? If there's another man we could call that does the right thing, we could do away with the wrapper script entirely, and it gets a lot less annoying.

The idea of using a separate script was that we could set TERM (or pipe man output through col -b) without impacting output from git itself – if git doesn't invoke man, the script is never executed and nothing changes.

If you can pass git a config setting (you mentioned man.man.path) to invoke a wrapper script by path, there's no need to "spell out" the path to man in the script, in which case the 2nd line would become TERM=dumb man $@ rather than TERM=dumb /path/to/man $@.

  • If you need to find /path/to/man (i.e., the path to the system's man) – and it sounds like you don't – you'd probably choose to capture the output of which man prior to altering the $PATH to include the directory enclosing the wrapper.

Taking all of that into account, it sounds like the best approach might be (pseudo-code):

$script_path := new_temporary_file_path()
write this literal to $script_path:
    #!/usr/bin/env sh
    TERM=dumb man $@ | col -b  # presumably, on any given platform, either `TERM` or `col -b` will do the trick
when it's time to invoke git:
    run "git -c man.man.path=" + shell_escape($script_path) + "  <usual git arguments>"

from vim-fugitive.

finite-state-machine avatar finite-state-machine commented on June 12, 2024

That works beautifully! Thank you, @tpope!

from vim-fugitive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.