Created
August 13, 2014 06:05
-
-
Save boneskull/3b3688bf4e5e0eff955b to your computer and use it in GitHub Desktop.
"man" integration for Dash.app
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
#!/bin/bash | |
# Put this in your .bash_profile or whatever. | |
# | |
# To override the DocSet shortcut Man Pages name, export DASH_MAN_DOCSET somewhere. | |
DASH_MAN_DOCSET=${DASH_MAN_DOCSET-manpages} | |
if [[ `uname` != Darwin ]]; then | |
echo The Dash.app plugin is only available on Mac OS X. Sorry! | |
exit | |
elif [[ ! -d /Applications/Dash.app ]]; then | |
echo To use the Dash.app plugin, install Dash.app from http://kapeli.com/dash | |
exit | |
elif [[ ! -d "$HOME/Library/Application Support/Dash/DocSets/Man_Pages" ]]; then | |
echo To use the Dash.app plugin, install the "Man Pages" DocSet from within Dash.app. | |
exit | |
else | |
# http://stackoverflow.com/questions/296536/urlencode-from-a-bash-script | |
# this enables to search multiple strings; "man git fetch" will find the "git" page and search for "fetch" within | |
function rawurlencode() { | |
local string="${@}" | |
local strlen=${#string} | |
local encoded="" | |
for (( pos=0 ; pos<strlen ; pos++ )); do | |
c=${string:$pos:1} | |
case "$c" in | |
[-_.~a-zA-Z0-9] ) o="${c}" ;; | |
* ) printf -v o '%%%02x' "'$c" | |
esac | |
encoded+="${o}" | |
done | |
echo "${encoded}" # You can either set a return variable (FASTER) | |
} | |
function dash_man { | |
/usr/bin/open dash://${DASH_MAN_DOCSET}:`rawurlencode ${@}` | |
} | |
alias man=dash_man | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment