-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmantastic
executable file
·172 lines (161 loc) · 8.17 KB
/
mantastic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/sh
clear
VER="0.30"
#----------------------------------------------------------------#
# Name: mantastic #
# #
# Purpose: Provide the shell user with an easy to use prompt #
# to find and display man pages. #
# #
# Syntax: mantastic man-keyword #
# #
# man-keyword is either a man page or keyword to search #
# in the man database #
# -d will just display the man page #
# the specific man command #
# ?, -h, -help display help information #
# #
# Dependencies: gum plus less or more #
# mandb - must be run after any install/upgrade #
# of shell packages #
# #
# Platforms: Any shell where less or gum are installed #
# #
# Author/Contributors (or whom to blame for this) #
# Lionel B. Dyck ([email protected]) #
# #
# Change History (top down): #
# 2024/05/07 LBD - 0.30 Add --soft-wrap pager option #
# 2024/02/16 LBD - 0.29 Change name in banner #
# 2024/02/15 LBD - 0.28 Remove the color option (not needed) #
# 2024/02/11 LBD - 0.27 Change prompt to use keyword instead #
# of string to be more accurate #
# Allow only arg to be number to test #
# colors #
# 2024/02/10 LBD - 0.26 Add more color options #
# 2024/02/08 LBD - 0.25 Change to use -d to display man now #
# Allow mantastic ? for help #
# 2024/02/08 LBD - 0.24 Bug fix for passed arguments #
# 2024/02/08 LBD - 0.23 Improve help for and and or #
# 2024/02/08 LBD - 0.22 Check for no option on call #
# Fixup test if no filter provided #
# 2024/02/07 LBD - 0.21 Check for no filter #
# 2024/02/03 LBD - 0.20 Add -h and -help #
# 2024/02/03 LBD - 0.10 Add option for direct to man #
# 2024/02/02 LBD - 0.08 Add exports for _TAG #
# 2024/01/29 LBD - 0.07 Simplify color change for banner #
# 2024/01/29 LBD - 0.06 Fix tail on man -k results #
# 2024/01/28 LBD - 0.05 Fix prompt color #
# 2024/01/27 LBD - 0.04 Cleanup color and usage #
# 2024/01/22 LBD - 0.03 add comment about more #
# 2024/01/22 LBD - 0.02 add comments and generalize pager #
# 2024/01/08 LBD - 0.00 creation #
# #
#----------------------------------------------------------------#
# Repository: github.com/lbdyck/prompters #
#----------------------------------------------------------------#
# Copyleft by Lionel B. Dyck 2024 #
# Name credit to Igor Todorovski #
#----------------------------------------------------------------#
#----------------------------------------------------------------#
# Comment and uncomment to define which pager to use for viewing #
#----------------------------------------------------------------#
PAGER="gum pager --soft-wrap"
# PAGER="more"
# PAGER="less"
#----------------------------------------------------------------#
# Define the color for the banner #
# 5 - purple #
# 9 - red #
# 12 - light blue #
# 33 - darker blue #
# 46 - green #
# 51 - turq shade #
# 86 - aqua #
# 253 - blue #
# #
# Note: some colors work great for the banner but the prompt #
# color may be unreadable #
#----------------------------------------------------------------#
COLOR=51
export GUM_INPUT_PROMPT_FOREGROUND="#$COLOR"
export GUM_INPUT_PLACEHOLDER=". . ."
export GUM_IMPORT_PROMPT="* "
export TERM=xterm-256color
#----------------------------------------------------------------#
# Define the TAG REDIR for our needs #
#----------------------------------------------------------------#
export _TAG_REDIR_IN=txt
export _TAG_REDIR_OUT=txt
export _TAG_REDIR_ERR=txt
#----------------------------------------------------------------#
# Display normal banner unless -h or -help #
#----------------------------------------------------------------#
if [ "$1" != "-help" -a "$1" != "-h" -a "$1" != "?" ]; then
gum style \
--foreground $COLOR --border-foreground $COLOR --border double \
--align center --width 50 --margin "1 2" --padding "2 4" \
'Mantastic man page Viewer' $VER
else
gum style \
--foreground $COLOR --border-foreground $COLOR --border double \
--align left --width 74 --margin "1 2" --padding "1 2" \
"Mantastic man page Viewer version -- $VER"\
' ' \
'mantastic syntax is: ' \
' ' \
'mantastic man-page -d to display man page without additional prompts' \
'mantastic keyword find keyword in man page description and list' \
'mantastic -help, -h, ? display this help ' \
'mantastic prompt for keyword' \
' ' \
'Note: The keyword is processed as logical OR for each word.' \
' Use the -a between words for an AND search.'\
' e.g. mantastic git -a push'
exit 0
fi
#----------------------------------------------------------------#
# Check for zero arguments and prompt if none #
#----------------------------------------------------------------#
if [ "$#" -eq 0 ]; then
ARG=$(gum input --prompt "Enter a command for a man page or a keyword to search for:" \
--placeholder="e.g. ssh" --value=" " --header.foreground="11")
else
ARG=$@
fi
#-----------------------------------------------------#
# Now test for a blank argument and make it null #
#-----------------------------------------------------#
if [ "$ARG" = " " ]; then
ARG=""
fi
#-----------------------------------------------------#
# Now test for a null argument #
#-----------------------------------------------------#
if [ -z "$ARG" ]; then
echo 'No search entered - try again...'
exit 0
fi
#----------------------------------------------------------------#
# If any arguments then do a search unless arg 2 is -d #
# in which case we bypass the prompt and go right to the display #
#----------------------------------------------------------------#
if [ "$2" != "-d" ]; then
if [ -n "$ARG" ]; then
MAN=$(gum choose $(man -k $ARG | cut -d" " -f1 | tail -n +1) \
--header "Select Man Page to View" --header.foreground="11")
MAN=$(echo $MAN | cut -d" " -f1)
else
MAN=$ARG
fi
else
MAN=$1
fi
#----------------------------------------------------------------#
# If we have a man page then display it else report no selection #
#----------------------------------------------------------------#
if [ -z "$MAN" ]; then
echo 'No Selection.'
else
man $MAN | $PAGER
fi