Created
March 29, 2018 12:33
-
-
Save halhenke/fdc2f688fda65bd1cfcac675869d343d 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
#------------------------------------------------------------------ | |
# STACK HELP | |
#------------------------------------------------------------------ | |
# Check if this is actually a stack project | |
function _is_stack() | |
{ | |
if ! [[ -f stack.yaml ]] | |
then | |
echo "Current directory does not appear to be a stack project..." | |
return 1 | |
fi | |
} | |
function _stack_snapshot_path() | |
{ | |
_is_stack || return 1; | |
local _stack_snap_path="$(stack path | grep local-install-root | sed -E 's/local-install-root: //' | sed -E 's/(.*)\/.*\/.*/\1\//')"; | |
echo ${_stack_snap_path#"$(pwd)"/} | |
} | |
# Get the stack resolver in a stack project | |
function stack-version() | |
{ | |
_is_stack || return 1; | |
cat stack.yaml | grep -E ^resolver: | |
} | |
# Get the stack resolver in a stack project | |
function stack-version-clean() | |
{ | |
_is_stack || return 1; | |
stack-version | sed -E 's/resolver: //' | |
} | |
# Show which resolvers have been installed | |
function stack-local-installs() | |
{ | |
_is_stack || return 1; | |
stack path | grep local-install-root | sed -E 's/local-install-root: //' | sed -E 's/(.*)\/.*\/.*/\1/' | xargs ls -l -1 | |
} | |
# Show which resolvers have been installed that no longer match the current version | |
function stack-local-old-installs() | |
{ | |
_is_stack || return 1; | |
stack-local-installs | grep -v "$(stack-version-clean)" | |
} | |
# Remove old stack-works that no longer match the current version | |
function stack-local-old-cleanup() | |
{ | |
_is_stack || return 1; | |
local prefix="$(_stack_snapshot_path)" | |
stack-local-old-installs | sed -E "s#(.*)#${prefix}\1#" | xargs rm -rf | |
} | |
# Show how much disk space is used by each stack installation | |
function stack-local-installs-usage() | |
{ | |
_is_stack || return 1; | |
local _dirs=$(stack path | grep local-install-root | sed -E 's/local-install-root: //' | sed -E 's/(.*)\/.*\/.*/\1\/\*/') | |
# ${~var} - Allow globbing, file expansion on result | |
du -sh ${~_dirs} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment