Bash script for see manpages in your terminal.

interpretive language scripts


Moderator: Forum moderators

Post Reply
User avatar
noje
Posts: 7
Joined: Fri Apr 08, 2022 7:22 am
Location: France
Has thanked: 1 time
Been thanked: 1 time

Bash script for see manpages in your terminal.

Post by noje »

Hello,

I made a bash script for seeing manpages on the terminal, you can go see the project here:

https://framagit.org/noje77/terminal_ma ... uppy_linux

In case you won't want leave forum :

installation

IMPORTANT : first you need install "w3m" with ppm (Puppy Package Manager)

curl https://framagit.org/noje77/terminal_manpages_for_puppy_linux/-/raw/main/mansh.sh >mansh
bash mansh --install
And just follow steps.....

usage
Type mansh with manpage you want (exemple below for ls command) :
$ mansh ls
mansh go see inside local manpages index /root/.manpage.index, if they don't found one , the bash script go look inside /usr/man/man1/.

command options
--help (see this help, mansh command without any name and argument do the same)
--install (this option launch mansh installation and get manpages index)
--get (get manpages index, if you remove them or manually install mansh, this is necessary to mansh to work)
--update (update this script serach where is mansh from $PATH, or tell you how to do)
--see (see index saved in /root/.manpage.index, helps you find which manpages are online)
--local (see local manpages on /usr/shar/man/man1, help you find manpages installed on your machine)
--clean (remove /root/. manpage. index, you need to get a new one after or mansh is broken)

correct manpage
In some case you go have wrong manpage, for correct this you need to go look inside index or local /usr/share/man/man1.
For this you can use options “--see” or “-- local”, type “/“ then type the keyword, then validate to perform a search.

Then when you find the right command or software you want to see the manpage, type the full name with dot and number, just remove the ending .gz.
exemple : you want see the manpage of zegrep.1.gz (just type : zegrep.1)

Definitly change man from Puppy Linux with mansh

Inside .bashrc file "/root/.bashrc" add an alias :
alias man="mansh"

If in some case, you want to back to original puppy linux man command, you can just type man with backslash before, (exemple below with ls manpage) :

$\man ls

Last edited by noje on Mon Apr 25, 2022 4:35 pm, edited 3 times in total.
User avatar
misko_2083
Posts: 196
Joined: Wed Dec 09, 2020 11:59 pm
Has thanked: 10 times
Been thanked: 20 times

Re: Bash script for see manpages in your terminal.

Post by misko_2083 »

I would switch to https and use less pipes.
from this

Code: Select all

curl http://manpages.ubuntu.com/manpages/focal/en/man9/ | fmt | grep "^alt=" | sed "s/..*href=\"//" | sed "s/html..*/html/" | sed "s/^/http:\/\/manpages.ubuntu.com\/manpages\/focal\/en\/man9\//"

to this

Code: Select all

curl https://manpages.ubuntu.com/manpages/focal/en/man9/ | fmt | sed "/^alt\=*/!d;s/..*href=\"//;s/html..*/html/;s/^/https:\/\/manpages.ubuntu.com\/manpages\/focal\/en\/man9\//"

"/^alt\=*/!d" - do not delete lines starting with alt=
The rest you know, separated with ";" char

# echo $1 >$output2
output2 file is not necessary in the script

You can try out in terminal

Code: Select all

# declare a function
function manpage () {
    echo $1
 }
 
# run function
manpage something

# output will be. something

Or you can declare a variable and export it to make it available to the child processes.

Code: Select all

export variable="$1"
the just use the ${variable} instead of $(cat $output2)

cat is often misused, it's a bad habit to get used to it
cat somefile | grep -o "gz"
instead of
grep -o "gz" somefile
grep can read files

making pipes and calling two commands instead of one take more time

Code: Select all

time cat random_filename | grep something
real	0m0.004s
user	0m0.003s
sys	0m0.004s

grep something random_filename
real	0m0.002s
user	0m0.000s
sys	0m0.002s

Not much but there can be a lot of commands like this in a loop or not.
Less is considered better and it's a good practice and a habit to have.

Do you want to exit the Circus? The Harsh Truth
https://www.youtube.com/watch?v=ZJwQicZHp_c

User avatar
noje
Posts: 7
Joined: Fri Apr 08, 2022 7:22 am
Location: France
Has thanked: 1 time
Been thanked: 1 time

Re: Bash script for see manpages in your terminal.

Post by noje »

I updated the script to version 1.01

:thumbup2: Thank you misko_2083, I correct the script with your advices, it's really helping me now for mansh, but generally for my bash scripting.
(it's will improve my way use cat, pipe, and reuse $1)

In the same way, it's help to see my sed with curl was wrong, and the ".manpage.index" size difference is huge:

Code: Select all

-rw-r--r-- 1 root root 7,6M avril  3 13:09 .manpage.index (version 1.01)
-rw-r--r-- 1 root root 1,2M avril  3 12:16 .manpage.index.old (version 1.00)

So now the version 1.01, give access to more man pages, "jwm" on version 1.00 wasn't available for example.

User avatar
user1234
Posts: 413
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 154 times
Been thanked: 87 times

Re: Bash script for see manpages in your terminal.

Post by user1234 »

An idea, add a file containing latest version of your program 'mansh' in its repo (or maybe somewhere else from where it can be accessible on internet) and use it for making an update command line option, maybe something like-

Code: Select all

mansh --update

In your previous version I could also see that --help or any other command line options were not available in your script. I would really like it to be included in your mansh.

And thanks for this great script, for I am noob when talking about programming (just 1 year experience into programming, and haven't taken any programming course, just read from sites) and can't create something like that to fulfill my need of viewing manpages in a terminal.

PuppyLinux 🐾 gives new life to old computers ✨

User avatar
noje
Posts: 7
Joined: Fri Apr 08, 2022 7:22 am
Location: France
Has thanked: 1 time
Been thanked: 1 time

Re: Bash script for see manpages in your terminal.

Post by noje »

Good suggestions user1234, and I updated to version 1.02 with your requests.

Adding --help, show help, originally blank of name or argument show you the same message, and I keep this way too.

Adding --update, update the script and show old and new version of the script.

I also put back --local (mixed-up my scripts when I corrected and updated version 1.00 to 1.01.

User avatar
user1234
Posts: 413
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 154 times
Been thanked: 87 times

Re: Bash script for see manpages in your terminal.

Post by user1234 »

I saw your update script function and I can see here that you are assuming that the script will always be placed at /root/my-applications/bin/mansh, though that may not be true every time.

I tried searching for a solution which can give you the dir where the script is located in and I found this.

PuppyLinux 🐾 gives new life to old computers ✨

User avatar
noje
Posts: 7
Joined: Fri Apr 08, 2022 7:22 am
Location: France
Has thanked: 1 time
Been thanked: 1 time

Re: Bash script for see manpages in your terminal.

Post by noje »

I choose to add "mansh" inside the path : /root/my-application/bin/, because it's declared in the environment "$PATH".
Bash searches each element of "$PATH" containing an executable file by that name, when you type a command (bash official documentation).

You can check typing and see "/root/my-applications/bin" is on.

Code: Select all

echo $PATH 
/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/root/my-applications/bin:/usr/games

I would think some people work differently, jump inside Puppy Linux don't look where $PATH or read documentation.
Or just keep habit they having on other GNU/Linux regular flavour or distribution.

I personally adding my scripts inside "~/. local/bin/" and export them on $PATH inside my ". zshrc".

On next release I will change the update fonction to look on declared environnement "$PATH".
Eventually for people don't follow this rule, i will just show the current version and online version, and suggest a curl.

I also think adding from --get, the choices of which version of Puppy Linux and set related link manpages of the original Linux Distribtuion inside ".manpage.index".
Thinking it's more logical than put Ubuntu Focal by default.

User avatar
user1234
Posts: 413
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 154 times
Been thanked: 87 times

Re: Bash script for see manpages in your terminal.

Post by user1234 »

noje wrote: Sun Apr 24, 2022 4:31 am

I choose to add "mansh" inside the path : /root/my-application/bin/, because it's declared in the environment "$PATH".
Bash searches each element of "$PATH" containing an executable file by that name, when you type a command (bash official documentation).

I know that all, but how many people do you think would follow all your steps? At first I thought to keep mansh at /home/spot/coding/cExecutables/ as I had added it the to PATH environment variable, and I use it to keep all of my own programs there (the ones that I create on my own).

If you really want that everyone uses the directory that you chose to keep the script in, then create an installation script. Then mansh will always remain in /root/my-applications/bin/.

PuppyLinux 🐾 gives new life to old computers ✨

User avatar
noje
Posts: 7
Joined: Fri Apr 08, 2022 7:22 am
Location: France
Has thanked: 1 time
Been thanked: 1 time

Re: Bash script for see manpages in your terminal.

Post by noje »

I update the script now it's 1.3, I change my first post.

Now an installation procedure is done, better and more simple installation : curl + bash mansh --install (follow steps, select path + select manpages of Puppy Linux Versions).

@user1234 I add possibility to set your own $PATH and it's also on the update procedure.

-- update : search where is mansh from $PATH environment variable, if not found tell how to do manually.

-- get: start at install automatically, but sill here for people, want to install manually (get options to which version of Puppy Linux manpages you want, Ubuntu only, no Slackware or raspbian at the moment).

I adding https for all manpages inside index.

User avatar
sc0ttman
Posts: 93
Joined: Sat Aug 22, 2020 3:55 pm
Has thanked: 4 times
Been thanked: 33 times

Re: Bash script for see manpages in your terminal.

Post by sc0ttman »

This might be of interest to you:

https://github.com/sc0ttj/w3m-man

Post Reply

Return to “Scripts”