-
-
Save igor-ramazanov/f830db44d37b7b4d27cca4c1dee31565 to your computer and use it in GitHub Desktop.
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 -S zsh --interactive --login | |
set -eo pipefail | |
search() { | |
local DEP="" | |
local CS_PREFIX="cs complete-dep" | |
# Returns two lines: | |
# 1) fzf query | |
# 2) selected element | |
local SEARCH_RESULT=`FZF_DEFAULT_COMMAND="$CS_PREFIX '$DEP'" fzf --bind "change:reload:$CS_PREFIX {q} || true" --phony --query "$DEP" --print-query --tac --ansi` | |
local QUERY="$(echo "$SEARCH_RESULT" | head --lines 1)" | |
local ANSWER="$(echo "$SEARCH_RESULT" | tail --lines 1)" | |
local RESULT="" | |
if [[ "$QUERY" == *"$ANSWER" ]]; then | |
# In case if query is 'io.circe:circe-core_3' and selected element is 'circe-core_3'. | |
RESULT="$QUERY" | |
else | |
RESULT=`echo "$QUERY:$ANSWER" | sed 's/::/:/g'` # In case if QUERY ends with ':' | |
fi | |
echo -n "$RESULT" | |
} | |
deps() { | |
cs resolve "$1" | |
} | |
depstree() { | |
cs resolve --tree "$1" | |
} | |
print_help() { | |
TAB="$(printf '\t')" | |
/usr/bin/cat << EOF | |
Usage: csc OPTION | |
Requirements: | |
${TAB} - Natively installed 'coursier' as 'cs': https://get-coursier.io/docs/cli-installation#native-launcher | |
${TAB} - 'fzf': https://github.com/junegunn/fzf | |
${TAB} - 'zsh': https://www.zsh.org/ | |
Options: | |
${TAB}--help${TAB}${TAB}print this help | |
${TAB}find${TAB}${TAB}interactively find a library | |
${TAB}deps${TAB}${TAB}interactively find a library and show its dependencies | |
${TAB}depstree${TAB}interactively find a library and show its dependencies as a tree | |
EOF | |
} | |
case "$1" in | |
"--help") | |
print_help | |
;; | |
"find") | |
search | |
;; | |
"deps") | |
deps "$(search)" | |
;; | |
"depstree") | |
depstree "$(search)" | |
;; | |
*) | |
print_help | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment