Last active
October 12, 2017 23:57
-
-
Save agwells/4b42a4904fc51d2247dc28b9008b1e28 to your computer and use it in GitHub Desktop.
Use R-style "?CMD" to pull up man pages in Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add the following to your ~/.bashrc file. | |
# | |
# I was inspired to do this because, after learning R and getting | |
# used to doing e.g. "?install.packages" when I wanted a reminder | |
# of the parameters list for a function, I kept accidentally trying | |
# to use the question mark to pull up help in Bash as well, e.g. | |
# "?grep" instead of "man grep" | |
# R-style help lookup, by doing "?CMD" for "man CMD" | |
# or "??CMD" for "man -K CMD" | |
function command_not_found_handle() { | |
if [ "${#1}" -gt 1 -a "${1:0:1}" = "?" ]; then | |
if [ "${#1}" -gt 2 -a "${1:0:2}" = "??" ]; then | |
echo /usr/bin/man -K "${1:2}" | |
/usr/bin/man -K "${1:2}" | |
return $?; | |
else | |
echo /usr/bin/man "${1:1}" | |
/usr/bin/man "${1:1}" | |
return $?; | |
fi | |
else | |
# Fallback to the Ubuntu default setting, | |
# the "command-not-found" program. | |
/usr/lib/command-not-found -- $1; | |
return $?; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment