fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . powerline-go ; 8 9# Convert an option value to a string to be passed as argument to 10# powerline-go: 11valueToString = value : 12if builtins . isList value then 13builtins . concatStringsSep "," ( builtins . map valueToString value ) 14else if builtins . isAttrs value then 15valueToString 16( mapAttrsToList ( key :val :" ${ valueToString key } = ${ valueToString val } " ) 17value ) 18else 19builtins . toString value ; 20 21modulesArgument = optionalString ( cfg . modules != null ) 22" -modules ${ valueToString cfg . modules } " ; 23 24modulesRightArgument = optionalString ( cfg . modulesRight != null ) 25" -modules-right ${ valueToString cfg . modulesRight } " ; 26 27evalMode = cfg . modulesRight != null ; 28 29evalArgument = optionalString ( evalMode ) " -eval" ; 30 31newlineArgument = optionalString cfg . newline " -newline" ; 32 33pathAliasesArgument = optionalString ( cfg . pathAliases != null ) 34" -path-aliases ${ valueToString cfg . pathAliases } " ; 35 36otherSettingPairArgument = name :value : 37if value == true then " - ${ name } " else " - ${ name } ${ valueToString value } " ; 38 39otherSettingsArgument = optionalString ( cfg . settings != { }) 40( concatStringsSep "" 41( mapAttrsToList otherSettingPairArgument cfg . settings )); 42 43commandLineArguments = '' 44${ evalArgument }${ modulesArgument }${ modulesRightArgument }${ newlineArgument }${ pathAliasesArgument }${ otherSettingsArgument } 45'' ; 46 47in { 48meta . maintainers = [ maintainers . DamienCassou ]; 49 50options = { 51programs . powerline-go = { 52enable = mkEnableOption 53"Powerline-go, a beautiful and useful low-latency prompt for your shell" ; 54 55modules = mkOption { 56default = null ; 57type = types . nullOr ( types . listOf types . str ); 58description = '' 59List of module names to load. The list of all available 60modules as well as the choice of default ones are at 61<https://github.com/justjanne/powerline-go>. 62'' ; 63example = [ "host" "ssh" "cwd" "gitlite" "jobs" "exit" ]; 64}; 65 66modulesRight = mkOption { 67default = null ; 68type = types . nullOr ( types . listOf types . str ); 69description = '' 70List of module names to load to be displayed on the right side. 71Currently not supported by bash. Specifying a value for this 72option will force powerline-go to use the eval format to set 73the prompt. 74'' ; 75example = [ "host" "venv" "git" ]; 76}; 77 78newline = mkOption { 79default = false ; 80type = types . bool ; 81description = '' 82Set to true if the prompt should be on a line of its own. 83'' ; 84example = true ; 85}; 86 87pathAliases = mkOption { 88default = null ; 89type = types . nullOr ( types . attrsOf types . str ); 90description = '' 91Pairs of full-path and corresponding desired short name. You 92may use '~' to represent your home directory but you should 93protect it to avoid shell substitution. 94'' ; 95example = literalExpression '' 96{ "\\~/projects/home-manager" = "prj:home-manager"; } 97'' ; 98}; 99 100settings = mkOption { 101default = { }; 102type = with types ; attrsOf ( oneOf [ bool int str ( listOf str ) ]); 103description = '' 104This can be any key/value pair as described in 105<https://github.com/justjanne/powerline-go>. 106'' ; 107example = literalExpression '' 108{ 109hostname-only-if-ssh = true; 110numeric-exit-codes = true; 111cwd-max-depth = 7; 112ignore-repos = [ "/home/me/big-project" "/home/me/huge-project" ]; 113} 114'' ; 115}; 116 117extraUpdatePS1 = mkOption { 118default = "" ; 119description = "Shell code to execute after the prompt is set." ; 120example = '' 121PS1=$PS1"NixOS> "; 122'' ; 123type = types . str ; 124}; 125}; 126}; 127 128config = { 129programs . bash . initExtra = 130mkIf ( cfg . enable && config . programs . bash . enable ) '' 131function _update_ps1() { 132local old_exit_status=$? 133${ 134if evalMode then "eval " else "PS1=" 135} "$( ${ pkgs . powerline-go } /bin/powerline-go -error $old_exit_status -shell bash ${ commandLineArguments } )" 136${ cfg . extraUpdatePS1 } 137return $old_exit_status 138} 139 140if [ "$TERM" != "linux" ]; then 141PROMPT_COMMAND="_update_ps1;$PROMPT_COMMAND" 142fi 143'' ; 144 145programs . zsh . initExtra = mkIf ( cfg . enable && config . programs . zsh . enable ) '' 146function powerline_precmd() { 147${ 148if evalMode then "eval " else "PS1=" 149} "$( ${ pkgs . powerline-go } /bin/powerline-go -error $? -shell zsh ${ commandLineArguments } )" 150${ cfg . extraUpdatePS1 } 151} 152 153function install_powerline_precmd() { 154for s in "$\{precmd_functions[@]}"; do 155if [ "$s" = "powerline_precmd" ]; then 156return 157fi 158done 159precmd_functions+=(powerline_precmd) 160} 161 162if [ "$TERM" != "linux" ]; then 163install_powerline_precmd 164fi 165'' ; 166 167# https://github.com/justjanne/powerline-go#fish 168programs . fish . interactiveShellInit = 169mkIf ( cfg . enable && config . programs . fish . enable ) '' 170function fish_prompt 171eval ${ pkgs . powerline-go } /bin/powerline-go -error $status -jobs (count (jobs -p)) ${ commandLineArguments } 172${ cfg . extraUpdatePS1 } 173end 174'' ; 175}; 176}