Skip to content

Instantly share code, notes, and snippets.

@pdobb
Last active June 25, 2023 09:45
Show Gist options
  • Save pdobb/5952eda52cbd1540c75d13f7390588b2 to your computer and use it in GitHub Desktop.
Save pdobb/5952eda52cbd1540c75d13f7390588b2 to your computer and use it in GitHub Desktop.
Open Rubocop Docs for Department/CopName from ZSH Shell
# Open Rubocop documentation. Optionally, by <Department> or by <Department>/<Name>.
#
# Example:
# `copd` -> Opens https://docs.rubocop.org/rubocop/index.html
# `copd Naming` -> Opens https://docs.rubocop.org/rubocop/cops_naming.html
# `copd Style/ArgumentsForwarding` -> Opens https://docs.rubocop.org/rubocop/cops_style.html#styleargumentsforwarding
function copd() {
if [[ $# -eq 0 ]]; then
open "https://docs.rubocop.org/rubocop/index.html"
else
local department="${1%%/*}" # Extract the department before '/'
local department_lowercase="${department:l}" # Convert department URL to lowercase
local url="https://docs.rubocop.org/rubocop/cops_${department_lowercase}.html"
if [[ -n $1 && $1 != */* ]]; then
open "$url"
else
local cop="${1#*/}" # Remove everything before '/'
local cop_lowercase="${cop:l}" # Convert cop name to lowercase
url="${url}#${department_lowercase}${cop_lowercase}"
open "$url"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment