LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   changing 'man' to use 'more' instead of 'less -is' as pager with 'alias' command (https://www.linuxquestions.org/questions/linux-newbie-8/changing-man-to-use-more-instead-of-less-is-as-pager-with-alias-command-4175439180/)

macinix 11-28-2012 01:39 PM

changing 'man' to use 'more' instead of 'less -is' as pager with 'alias' command
 
Disclosure:
Platform:
Mac OS X 10.8.2 Mountain Lion
bash --version:
3.2.48(1)-release (x86_64-apple-darwin12)
~/.bash_profile: currently empty, but compatible with test in #1 below.

Problems:
#1)
Code:

alias
yields no result, although

Code:

alias helpme='echo goodie'
works, just fine and yields expected result.
if I then type
Code:

alias
the result is
Code:

alias helpme='echo goodie'
I then unalias, as this is just a test.

I have found that pressing and holding \[ESC\] prompt me to see a list of commands and aliases (including any I just made).

However, if I attempt to look at the definition of a (system-wide/default) alias, then I get, for example:
Code:

alias pico
-bash: alias: pico: not found

I have a) verified this is listed in the 1500 commands/aliases via escape, found the alias file in /user/bin/pico, and I use it all the time because i first got my feet wet with *nix 10 years ago, and none of the platforms I used were running nano.
Code:

pico cake
appears to be identical (minus whatever flags are there in the alias) to
Code:

nano cake
but I don't know which flags are being used of course with the alias pico.

#2) I would like to have man use more instead of less when I'm browsing man pages. I would like to do this for a couple reasons, one is so I can easily copy all the text to a GUI text editor, then work with it in my preferred program.

Currently man actually uses less -is (ignore case, and squeeze blank lines respectively).

So when I man less I get this:
http://pastebin.com/5mkQdr9U
On line 724, which is fantastic, it says:
"You may define your own less commands by using the program lesskey (1)"
However, looking at https://developer.apple.com/library/...lesskey.1.html
Lets me see that:
Quote:

WARNING: This manual page does not exist in the currently shipping version of OS X. This can happen for two reasons:

It may have been renamed or combined with another manual page.
The technology in question may no longer be supported.
You should investigate the availability of this technology before relying on the contents of this page.
Well, thanks a lot apple for telling me to "investigate"... I have, needless to say, done a lot searching about this. I have looked at stackexchange sites, searched and read results from about 10 different angles, and I have found nothing that addresses this for this platform.

So I went ahead and created the $HOME/.less file and put it
Code:

LESS_IS_MORE=1
and I've also substituted "TRUE" for "1". I have quit shell, and opened a new one, to no avail (this reloads my .bash_profile, so I assume (possibly foolishly?) that this would essentially work in this case as well.

Also, I found it confusing in this section, but maybe it just means I can't do this anyjmore? line 724:
Quote:

You may define your own less commands by using the program lesskey (1)
to create a lesskey file. This file specifies a set of command keys
and an action associated with each key. You may also use lesskey to
change the line-editing keys (see LINE EDITING), and to set environment
variables. If the environment variable LESSKEY is set, less uses that
as the name of the lesskey file. Otherwise, less looks in a standard
place for the lesskey file: On Unix systems, less looks for a lesskey
file called "$HOME/.less".
.

Then I put the line:
Code:

LESSKEY=TRUE
in my ~/.bash_profile document, but to no avail. I sourced it, after a failed test, but apparently I don't need to as overwriting the file and exiting nano seems to work just fine (I tested changing my $HOME var).
So, no idea where to go from there. So I also tried something else:

I was also playing around with the /private/etc/man.conf file, and saw that these two lines might be easily changed to fix this issue. So I changed lines: 105-106 which read
Code:

PAGER          /usr/bin/less -is
BROWSER        /usr/bin/less -is

to have "more" instead of "less -is".

This worked, mostly.
Now my man pages remain visible from the top to wherever I have paged down to so far, and then more exits with my final next-page command. Good enough.

Of course this started out with me wanting to use an alias for the man + more combination which was going to be a syntax problem for me to solve, but I found it to be a little more complex. This is still my preference however, because currently I am changing the behavior of man system wide!

I then found that killing a man command with control-\ yielded this:
Code:

( cd '/usr/share/man' && /usr/bin/tbl /usr/share/man/man1/builtin.1 | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | ( /usr/bin/less -is || true ) )
as a note this also seems to screw up my input and cause what I type not to appear on the screen, and hitting return with a blank prompt creates a prompt on the same line instead of the next like usual. and I have to

investigating further by reading man man then man man.conf I came across the relevant two lines.

A question I have related to this is: is it generally not a good idea to edit files in /private ?
I've edited the hosts file (/private)/etc before to stop from connecting to ad servers. But beyond that, I'd rather not even do that system wide actually.

So I guess I may have a partial, though not ideal solution to #2. But I would still like to be able to find out the definition of an alias, and ideally... make more complicated aliases than l='ls -l' (very annoying that this is not a default alias on Mac if you ask me).

Why don't I just use something like:
Code:

man man >> myfavmanpageatm
?
because, then I look at that file with nano and it looks like this:
Code:

man(1)                                                                  man(1)



N^HNA^HAM^HME^HE
      man - format and display the on-line manual pages

S^HSY^HYN^HNO^HOP^HPS^HSI^HIS^HS
      m^Hma^Han^Hn  [-^H-a^Hac^Hcd^Hdf^HfF^HFh^Hhk^HkK^HKt^Htw^HwW^HW]  [-^H--$
      [-^H-M^HM _^Hp_^Ha_^Ht_^Hh_^Hl_^Hi_^Hs_^Ht] [-^H-P^HP _^Hp_^Ha_^Hg_^He_^$
      [_^Hs_^He_^Hc_^Ht_^Hi_^Ho_^Hn] _^Hn_^Ha_^Hm_^He _^H._^H._^H.


D^HDE^HES^HSC^HCR^HRI^HIP^HPT^HTI^HIO^HON^HN
      m^Hma^Han^Hn formats and displays the on-line manual pages.  If you spec$
      _^Ht_^Hi_^Ho_^Hn, m^Hma^Han^Hn only looks in that section of the manual.$
      the  name of the manual page, which is typically the name of a command,
      function, or file.  However, if _^Hn_^Ha_^Hm_^He contains  a  slash  (/^$
...

and even worse, when it gets to sections with flags,
the flags are all repeated, so it looks like:
-ii ignore case
-ss squeeze lines
etc.

EDit: I have figured out that those symbols can be read by 'more'... so, is there a way to remove those and have it readable by nano?


May Loki help me, I know this is a long one...

ntubski 11-28-2012 10:23 PM

Quote:

Originally Posted by macinix (Post 4838991)
However, if I attempt to look at the definition of a (system-wide/default) alias, then I get, for example:
Code:

alias pico
-bash: alias: pico: not found

I have a) verified this is listed in the 1500 commands/aliases via escape, found the alias file in /user/bin/pico

You have a misconception about aliases, an alias is just a mapping in your shell. /user/bin/pico is not an "alias file", it may be a symlink to the nano executable.

Quote:

#2) I would like to have man use more instead of less when I'm browsing man pages. I would like to do this for a couple reasons, one is so I can easily copy all the text to a GUI text editor, then work with it in my preferred program.
Looking at man man, we see:
Quote:

-P pager
Specify which pager to use. This option overrides the MANPAGER environment variable, which in
turn overrides the PAGER variable. By default, man uses /usr/bin/less -is.

So, you should be able to use
Code:

alias man='man -P more'
# or
export MANPAGER=more

Quote:

Also, I found it confusing in this section, but maybe it just means I can't do this anyjmore? line 724:
Quote:

...If the environment variable LESSKEY is set, less uses that
as the name of the lesskey file...
.

Then I put the line:
Code:

LESSKEY=TRUE
in my ~/.bash_profile document, but to no avail.
The idea was
Code:

LESSKEY=$HOME/.less # or choose another file, if you like
Quote:

EDit: I have figured out that those symbols can be read by 'more'... so, is there a way to remove those and have it readable by nano?
I think those are actually interpreted by the terminal, not 'more'. I think you might be able to remove them with
Code:

tr -cd '[:print:][:space:]'

macinix 11-29-2012 11:45 AM

Quote:

Originally Posted by ntubski (Post 4839204)
You have a misconception about aliases, an alias is just a mapping in your shell. /user/bin/pico is not an "alias file", it may be a symlink to the nano executable.

Sorry, you're correct. It's confusing, b/c as a lifelong mac user, "alias" is the equivalent term for "shortcut" on windows, etc. So, in the GUI I saw the "alias" which is now of course, actually, just a symlink file. I should have not used that term in this context obviously (*love your sig).

However, why can't I get the definition of a system alias? Is it perhaps that pico is just a symlink and not a shell alias at all? Since the single command alias with no flags/args returns nothing (when I have none in my bash profile) does that mean there are no aliases defined by default by the system?
So, as admin we have the record of what happens in my first post, but now I thought to try sudo:
Code:

sudo alias pico
/usr/bin/alias: line 4: alias: pico: not found


Another obvious point:
Quote:

Originally Posted by ntubski (Post 4839204)
Looking at man man, we see:
So, you should be able to use
Code:

alias man='man -P more'
# or
export MANPAGER=more


I used the first one. Thank you. As I'm not as comfortable with the export command.
The other part of the problem is that the below still doesn't work.
But that's fine, it's one less file to mess around with (no pun intended). And since we were cautioned by apple to just 'investigate' I'm not sure it'll ever work. For completeness I did try it as below however:
Code:

#inside ~/.less:
LESS_IS_MORE
LESS_IS_MORE=1
LESS_IS_MORE=TRUE
#none of those three combinations worked with any of the 3 path combinations in my profile:
LESSKEY=$HOME/.less
#and just for completeness
LESSKEY='$HOME/.less'
LESSKEY="$HOME/.less"

Of course I find all of the above somewhat strange because it states that "unix" systems (which is what OS X is closer to than windows or OS/2 or DOS) will look for ~/.less "by default"... (from the man page). So my interpretation of that is I wouldn't have to put a line in my bash profile anyway. Either way, it doesn't work as such.


About tr ,
Quote:

Originally Posted by ntubski (Post 4839204)
I think those are actually interpreted by the terminal, not 'more'. I think you might be able to remove them with
Code:

tr -cd '[:print:][:space:]'

it didn't seem to do anything when I did:
Code:

man man | tr -cd '[:print:][:space:]' >> man.man
That is, it didn't give different output, it had all the same Terminal code.

Also, I could do this:
Code:

man less | nano
Received SIGHUP or SIGTERM

Buffer written to nano.save

but that's kind of ugly... no file name, etc.
of course I can do this (but it's almost as ugly):
Code:

man less | nano yoyo
Received SIGHUP or SIGTERM

Buffer written to yoyo.save

Lastly, a huge thank you for looking at this with me!

ntubski 11-29-2012 04:35 PM

Quote:

Originally Posted by macinix (Post 4839696)
Sorry, you're correct. It's confusing, b/c as a lifelong mac user, "alias" is the equivalent term for "shortcut" on windows, etc. So, in the GUI I saw the "alias" which is now of course, actually, just a symlink file. I should have not used that term in this context obviously (*love your sig).

Ah, that would be confusing. I can see that "alias" is a reasonable term to use for that sort of thing, but the shell command alias has nothing to do with it.

Quote:

However, why can't I get the definition of a system alias? Is it perhaps that pico is just a symlink and not a shell alias at all? Since the single command alias with no flags/args returns nothing (when I have none in my bash profile) does that mean there are no aliases defined by default by the system?
Yes and yes. Try ls -l "$(which pico)", that will show where it points, if it's a symlink.

Quote:

The other part of the problem is that the below still doesn't work.
I reread the lesskey man page, and I'm wondering what you are actually trying to do with lesskey, since you don't seem to be defining any keys. A possible use would be

Put this ~/.lesskey
Code:

#command
Z version

Then run
Code:

lesskey ~/.lesskey
That creates the (non-readable, binary) file ~/.less which the less program will use, so that when you type Z it will show the version.


Quote:

it didn't seem to do anything when I did:
Code:

man man | tr -cd '[:print:][:space:]' >> man.man
That is, it didn't give different output, it had all the same Terminal code.
Just to be clear, when you use double >> it appends to the file, so if you had the bad output in man.man from before, the new good output would be at the end.

I haven't tested the tr command though, since on my system redirecting man to a file doesn't produce any problem characters. I was guessing that the ^Hs are control characters, but on the off chance they have been escaped somewhere along the line, you could try sed 's/\^H//g'

Quote:

Also, I could do this:
Code:

man less | nano
Received SIGHUP or SIGTERM

Buffer written to nano.save

but that's kind of ugly... no file name, etc.
of course I can do this (but it's almost as ugly):
Code:

man less | nano yoyo
Received SIGHUP or SIGTERM

Buffer written to yoyo.save


Another possibility, would be to run man less, while viewing the manpage from within less, type s, this will prompt you for a filename, it needs to be an absolute path, eg ~/yoyo.save.

macinix 02-15-2013 06:12 PM

Thanks a mil
 
Hi there again, thanks again for this, we had to get our program out so the last couple months have been rather the heaviest of my life...

Quote:

ls -l "$(which pico)"
great that's awesome: output tells me it points to 'nano'!


Quote:

lesskey
okay, so, it turns out that 'lesskey' the command has actually been removed from Mac OS X as of the last version (10.7).
::SADFACE!::


Quote:

Just to be clear, when you use double >> it appends to the file, so if you had the bad output in man.man from before, the new good output would be at the end.
Yeah, no worries I wasn't getting lost in old bad output, thanks for making sure I didn't do that noob mistake anyway, very thoughtful. (just to be sure, I rm'd the file almost each time).


Quote:

sed 's/\^H//g'
unfortunately
Code:

man man | sed 's/\^H//g' >> man.man
had even more horrific output than 'tr'!

so, I guess for now I have to settle for:
Code:

$ man man | nano manman
Received SIGHUP or SIGTERM

Buffer written to manman.save

the only thing really lacking there is the nice layout. That is, nano just collapses most of the white space so everything is all scrunched up (I guess that's its way of ignoring all those special characters?) whereas tr and sed keep the layout but try too hard and draw all those special characters.

I thought some the special characters might be denoting color, but even in a b&w terminal session the commands all have the same output.

Thanks again for checking this all out. I'm going to mark this as solved, because we've gone far and beyond answering the items in the title of the question. If you're still interested in working on the formatting issue, feel free, I'll definitely update this issue if/when I come across a more suitable solution.

Thanks ntubski!

ntubski 02-16-2013 12:03 PM

According to this Linux man page howto: 10. How do I get a plain text man page without all that ^H^_ stuff?
Code:

man man | col -bx > man.man
should work. Apparently col is a program specifically written for this kind of thing, I only just discovered it now.

macinix 02-16-2013 01:00 PM

Fantastic! That does the trick, thank you so much for going on this journey of discovery with me! I'm glad we both got something out of the trip (sounds like)!


All times are GMT -5. The time now is 03:57 PM.