Skip to content

Instantly share code, notes, and snippets.

@halhenke
Created March 29, 2018 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halhenke/fdc2f688fda65bd1cfcac675869d343d to your computer and use it in GitHub Desktop.
Save halhenke/fdc2f688fda65bd1cfcac675869d343d to your computer and use it in GitHub Desktop.
#------------------------------------------------------------------
# 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