-
-
Save yaauie/26a3503b616f447dc596a1cf2f523cf7 to your computer and use it in GitHub Desktop.
Bash/Zsh-compliant utility function that allows you to cd into a local checkout of a Logstash Plugin's source code, whether or not you have previously cloned the repository
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
#!/usr/bin/env bash | |
# | |
# Utility that allows you to cd into a local checkout of a Logstash Plugin's | |
# source code, whether or not you have previously cloned the repository. | |
# | |
# Usage: | |
# cdlp <type> <qualifier> | |
# | |
# Example: | |
# cdlp output elasticsearch | |
# | |
# Installation: | |
# set `CDLP_DIR` and source this script in your shell's rc: | |
# | |
# ~~~ | |
# export CDLP_DIR="${HOME}/src/elastic/logstash-plugins" | |
# source "${HOME}/scripts/cdlp" | |
# ~~~ | |
# | |
# Environment: | |
# - `CDLP_DIR` : the local directory that holds logstash plugins | |
# - `CDLP_ORG` : optional github org from which to clone (default: `logstash-plugins`) | |
# - `CDLP_ORIGIN` : optional git origin name to use if a clone is necessary (default: `origin`) | |
cdlp() { | |
cdlp_dir="${CDLP_DIR:?}" # required | |
cdlp_org="${CDLP_ORG:-logstash-plugins}" # optional | |
cdlp_origin="${CDLP_ORIGIN:-origin}" # optional | |
type_req="${1:?type required}" | |
qual_req="${2:?qualifier required}" | |
case $type_req in | |
'i'|'input' ) type='input' ;; | |
'o'|'output' ) type='output';; | |
'f'|'filter' ) type='filter';; | |
'c'|'codec' ) type='codec';; | |
'm'|'mixin' ) type='mixin';; | |
'x'|'integration' ) type='integration';; | |
*) >&2 echo "unknown logstash plugin type '${type_req}'" | |
type="${type_req}" | |
esac; | |
plugin_name="logstash-${type}-${qual_req}" | |
plugin_directory="${cdlp_dir}/${plugin_name}" | |
if [ ! -d "${plugin_directory}" ]; then | |
mkdir -p "${cdlp_dir}" | |
plugin_uri="git@github.com:${cdlp_org}/${plugin_name}.git" | |
>&2 echo "Cloning from '${plugin_uri}'..." | |
git clone --origin="${cdlp_origin}" "${plugin_uri}" "${plugin_directory}" || return 1 | |
fi | |
cd "$plugin_directory" | |
} | |
$(return >/dev/null 2>&1) && sourced=1 || sourced=0 | |
if [ "$sourced" = "0" ]; then | |
cdlp "${@}" && | |
>&2 echo 'WARN: cdlp has not been sourced; you will need to `cd` manually:' && | |
echo "${PWD}" | |
exit "$?" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
neat! would be nice if it also set up the fork, maybe with a
CDLP_FORK=yaauie
+git remote add $CDLP_FORK git@github.com/$CDLP_FORK/${plugin_name}