Last active
November 4, 2016 16:40
-
-
Save samtay/c4134212178d7bf653cc31a286a2bc5a to your computer and use it in GitHub Desktop.
Easy BA skel commands
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
### Put this file in ~/.oh-my-zsh/custom/plugins/skel/skel.plugin.zsh | |
### and add to ~/.zshrc -> plugins = (skel) | |
# compdef ba-skel | |
function _ba-skel() { | |
_detect_skel || return 1 | |
_files -W "$(_get_repo_root)/skel/bin" | |
} | |
compdef _ba-skel ba-skel |
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
### Put this file in ~/.oh-my-zsh/custom/skel.zsh | |
# check cwd is in git repo | |
_is_in_git_dir() { | |
[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1 | |
} | |
# get repo root | |
_get_repo_root() { | |
git rev-parse --show-toplevel | |
} | |
# check cwd is in a skel | |
_detect_skel() { | |
_is_in_git_dir && \ | |
[ -d "$(_get_repo_root)/skel/bin" ] | |
} | |
# execute skel/bin/* commands from anywhere in repo | |
ba-skel() { | |
_detect_skel || { echo "skel not detected" ; return 1 } | |
local repo_root=$(_get_repo_root); | |
local command=$1 | |
if [ -z $command ]; then | |
ls -l "$repo_root/skel/bin" | |
elif [ -e "$repo_root/skel/bin/$command" ]; then | |
shift | |
$repo_root/skel/bin/$command $@ | |
else | |
echo "skel/bin/$command not found" ; exit 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment