Skip to content

Commit fc59ade

Browse files
committed
Show Fish / Powershell specific help
On `moar --help`, if `moar` is not the default pager, try identifying the user's shell and print instructions for setting `PAGER` in that shell. Identifies fish or Powershell, then falls back on bash / zsh instructions (since I failed to come up with a sensible way of identifying those). Before this change, we always printed bash / zsh instructions. Fixes: #251
1 parent fdec6ce commit fc59ade

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

scripts/test-path-help.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ ln -s "$MOAR" "$WORKDIR/moar"
2121
echo "moar" >"$WORKDIR/expected"
2222

2323
# Extract suggested PAGER value from moar --help
24-
PATH="$WORKDIR" PAGER="" moar --help | grep "export PAGER" | sed -E 's/.*=//' >"$WORKDIR/actual"
24+
unset PAGER
25+
PATH="$WORKDIR" PAGER="" moar --help | grep "PAGER" | grep -v "is empty" | sed -E 's/.*PAGER[= ]//' >"$WORKDIR/actual"
2526

2627
# Ensure it matches the symlink we have in $PATH
2728
cd "$WORKDIR"

usage.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ func printUsage(flagSet *flag.FlagSet, colors twin.ColorCount) {
182182
fmt.Print(envSection)
183183
}
184184

185-
// We're not the default pager
186185
printSetDefaultPagerHelp(colors)
187186

188187
fmt.Println()
@@ -194,6 +193,7 @@ func printUsage(flagSet *flag.FlagSet, colors twin.ColorCount) {
194193
fmt.Println(" \tImmediately scroll to line 1234")
195194
}
196195

196+
// If $PAGER isn't pointing to us, print a help text on how to set it.
197197
func printSetDefaultPagerHelp(colors twin.ColorCount) {
198198
absMoarPath, err := absLookPath(os.Args[0])
199199
if err != nil {
@@ -207,15 +207,32 @@ func printSetDefaultPagerHelp(colors twin.ColorCount) {
207207
}
208208

209209
if absPagerValue == absMoarPath {
210+
// We're already the default pager
210211
return
211212
}
212213

213214
fmt.Println()
214215
fmt.Println(heading("Making moar Your Default Pager", colors))
215-
fmt.Println(" Put the following line in your ~/.bashrc, ~/.bash_profile or ~/.zshrc")
216-
fmt.Println(" and moar will be used as the default pager in all new terminal windows:")
217-
fmt.Println()
218-
fmt.Printf(" export PAGER=%s\n", getMoarPath())
216+
217+
shellIsFish := strings.HasSuffix(os.Getenv("SHELL"), "fish")
218+
shellIsPowershell := len(os.Getenv("PSModulePath")) > 0
219+
220+
if shellIsFish {
221+
fmt.Println(" Write this command at your prompt:")
222+
fmt.Println()
223+
fmt.Printf(" set -Ux PAGER %s\n", getMoarPath())
224+
} else if shellIsPowershell {
225+
fmt.Println(" Put the following line in your $PROFILE file (\"echo $PROFILE\" to find it)")
226+
fmt.Println(" and moar will be used as the default pager in all new terminal windows:")
227+
fmt.Println()
228+
fmt.Printf(" $env:PAGER = \"%s\"\n", getMoarPath())
229+
} else {
230+
// I don't know how to identify bash / zsh, put generic instructions here
231+
fmt.Println(" Put the following line in your ~/.bashrc, ~/.bash_profile or ~/.zshrc")
232+
fmt.Println(" and moar will be used as the default pager in all new terminal windows:")
233+
fmt.Println()
234+
fmt.Printf(" export PAGER=%s\n", getMoarPath())
235+
}
219236
}
220237

221238
// "moar" if we're in the $PATH, otherwise an absolute path

0 commit comments

Comments
 (0)