Last active
June 18, 2017 20:57
-
-
Save epsilonhalbe/e9af1d8dccc654ebd641 to your computer and use it in GitHub Desktop.
haskell-prompt-info (zsh)
This file contains hidden or 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
function haskell_info() { | |
cabal_files=(*.cabal(N)) | |
if [ $#cabal_files -gt 0 ]; then | |
if [ -f cabal.sandbox.config ]; then | |
cabal_sandbox_info | |
elif [ -f stack.yaml ]; then | |
stack_info | |
else | |
echo "%{$fg[red]%}no stack/sandbox%{$reset_color%}" | |
fi | |
fi | |
} | |
function stack_info() { | |
ghc_version=`ghc --version | rev | cut -d' ' -f 1 | rev` | |
resolver_yaml=`cat stack.yaml | grep resolver | cut -d' ' -f 2` | |
if [ -d ".stack-work/install/x86_64-linux/$resolver_yaml" ]; then | |
ghc_stack=`ls .stack-work/install/x86_64-linux/$resolver_yaml/ | grep $ghc_version` | |
if [ $ghc_stack ]; then | |
echo "[%{$fg[green]%}$resolver_yaml %{$reset_color%}| %{$fg[green]%}$ghc_version%{$reset_color%}]" | |
else | |
ghc_stack=`ls .stack-work/install/x86_64-linux/$resolver_yaml/ | xargs` | |
echo "[%{$fg[green]%}$resolver_yaml%{$reset_color%}|%{$fg[red]%}$ghc_stack%{$reset_color%}]" | |
fi | |
else | |
echo "%{$fg[red]%}[$resolver_yaml missing please do a 'stack build']%{$reset_color%}" | |
fi | |
} | |
function cabal_sandbox_info() { | |
ghc_version=`ghc --version | rev | cut -d' ' -f 1 | rev` | |
ghc_loc=`ls .cabal-sandbox | grep ghc | cut -d'-' -f 4 | grep $ghc_version` | |
if [ $ghc_loc ]; then | |
echo "[%{$fg[green]%}$ghc_version%{$reset_color%}]" | |
else | |
ghc_version=`ls .cabal-sandbox | grep ghc | cut -d'-' -f 4 | xargs` | |
echo "[%{$fg[red]%}$ghc_version%{$reset_color%}]" | |
fi | |
} | |
RPROMPT="\$(haskell_info) $RPROMPT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cabal sandboxes are indicated by a ghc version liked [7.10.2]
for stack projects the indicator is like: [rts-3.0|7.10.0]
the default choice if both cabal-sandbox and a stack project are coexisting is cabal for stack is quite new and there are more cabal projects out there
Note: stack itself is a moving target and changes in stack might lead to a breakage in this script
Note: this setup has been made on a linux machine - if you are working on a mac/windows it might need some adjustments.