Skip to main content
Code Review

Return to Question

Tweeted twitter.com/StackCodeReview/status/1057557894311411717
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

This is update to a previously asked question Bash manual page selection menu Bash manual page selection menu. This script generates a menu for the user to select which manual page he/she would like to read.

This is update to a previously asked question Bash manual page selection menu. This script generates a menu for the user to select which manual page he/she would like to read.

This is update to a previously asked question Bash manual page selection menu. This script generates a menu for the user to select which manual page he/she would like to read.

edited tags
Link
I0_ol
  • 453
  • 3
  • 9
Source Link
I0_ol
  • 453
  • 3
  • 9

Bash manual page selection menu (version 2)

This is update to a previously asked question Bash manual page selection menu. This script generates a menu for the user to select which manual page he/she would like to read.

#!/bin/bash
# Mac OS X specific function to clear completely clear the screen.
# Seems to work well for the purposes of this script 
clear(){ 
 osascript -e \
 'set theApp to (get the path to the frontmost application) as text
 set this_app to the name of application theApp
 activate application this_app
 tell application "System Events" to keystroke "k" using command down' 
}
clear
COLUMNS=80
while true
do
 printf 'Man Pages: main menu\n ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\n'
 PS3=$'\nMake a selection: '
 select dir in $(ls -d ${PATH//:/ })
 do
 case $REPLY in
 [0-9]*) ls $dir; break 1;;
 *) echo "Exiting" && exit 1;;
 esac
 done
 clear
 printf "Man Pages: $dir"$'\n ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\n' 
 PS3=$'\n(B)ack to main menu\n(Q)uit\n\nMake your selection: '
 while true
 do
 select file in $(ls ${dir} | column -t)
 do
 case $REPLY in
 [0-9]*) man $file; clear; break 1;;
 [bB]) clear; break 2;;
 [qQ]) echo "Exiting" && exit;;
 *) echo "Exiting" && exit 1;;
 esac
 done
 done
done

I wanted to make it so that any programs without a manual page wouldn't be listed in the menu. But to do so would require checking to see if every command found in the user's PATH had a manual page associated with it and then creating a database of commands with manual pages. As it is, if a command does not contain a manual page, the user is directed back to the previous menu page to choose another selection.

I realize there is already a clear command in most user's terminals. But the clear command in my system clears the screen but still allows the user to scroll up past where the screen was just cleared. I made the clear function to completely clear the screen to enhance the overall aesthetic when running the script. It's not really necessary but I think it looks nice.

I think this script does what I intended it to do. So now I'd like other's opinions on it. Is there anything I could do to improve it?

lang-bash

AltStyle によって変換されたページ (->オリジナル) /