Skip to content

Instantly share code, notes, and snippets.

@zorgiepoo
Forked from samdmarshall/gist:db653963479f1a281106
Last active August 29, 2015 14:13
Show Gist options
  • Save zorgiepoo/21188981e90b2a9641d2 to your computer and use it in GitHub Desktop.
Save zorgiepoo/21188981e90b2a9641d2 to your computer and use it in GitHub Desktop.
function xman
set lookup_name "$argv[-1]"
set lookup_section "$argv[1]"
set open_string ""
set grep_string ""
set beginning_pattern "(^|[ \t\r\n\f])"
if [ $lookup_name = $lookup_section ]; set open_string "x-man-page://$lookup_name"; set grep_string "$beginning_pattern$lookup_name\\("; end;
if [ $lookup_name != $lookup_section ]; set open_string "x-man-page://$lookup_section/$lookup_name"; set grep_string "$beginning_pattern$lookup_name\\($lookup_section\\)"; end;
if man -k "$lookup_name" | grep -q -E "$grep_string" > /dev/null
open "$open_string"
else
echo "No man page found!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment