1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-30 18:38:31 +02:00
home-manager/modules/programs/powerline-go.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

178 lines
5.4 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.powerline-go;
# Convert an option value to a string to be passed as argument to
# powerline-go:
valueToString = value:
if builtins.isList value then
builtins.concatStringsSep "," (builtins.map valueToString value)
else if builtins.isAttrs value then
valueToString
(mapAttrsToList (key: val: "${valueToString key}=${valueToString val}")
value)
else
builtins.toString value;
modulesArgument = optionalString (cfg.modules != null)
" -modules ${valueToString cfg.modules}";
modulesRightArgument = optionalString (cfg.modulesRight != null)
" -modules-right ${valueToString cfg.modulesRight}";
evalMode = cfg.modulesRight != null;
evalArgument = optionalString (evalMode) " -eval";
newlineArgument = optionalString cfg.newline " -newline";
pathAliasesArgument = optionalString (cfg.pathAliases != null)
" -path-aliases ${valueToString cfg.pathAliases}";
otherSettingPairArgument = name: value:
if value == true then " -${name}" else " -${name} ${valueToString value}";
otherSettingsArgument = optionalString (cfg.settings != { })
(concatStringsSep ""
(mapAttrsToList otherSettingPairArgument cfg.settings));
commandLineArguments = ''
${evalArgument}${modulesArgument}${modulesRightArgument}${newlineArgument}${pathAliasesArgument}${otherSettingsArgument}
'';
in {
meta.maintainers = [ maintainers.DamienCassou ];
options = {
programs.powerline-go = {
enable = mkEnableOption (lib.mdDoc
"Powerline-go, a beautiful and useful low-latency prompt for your shell");
modules = mkOption {
default = null;
type = types.nullOr (types.listOf types.str);
description = lib.mdDoc ''
List of module names to load. The list of all available
modules as well as the choice of default ones are at
<https://github.com/justjanne/powerline-go>.
'';
example = [ "host" "ssh" "cwd" "gitlite" "jobs" "exit" ];
};
modulesRight = mkOption {
default = null;
type = types.nullOr (types.listOf types.str);
description = lib.mdDoc ''
List of module names to load to be displayed on the right side.
Currently not supported by bash. Specifying a value for this
option will force powerline-go to use the eval format to set
the prompt.
'';
example = [ "host" "venv" "git" ];
};
newline = mkOption {
default = false;
type = types.bool;
description = lib.mdDoc ''
Set to true if the prompt should be on a line of its own.
'';
example = true;
};
pathAliases = mkOption {
default = null;
type = types.nullOr (types.attrsOf types.str);
description = lib.mdDoc ''
Pairs of full-path and corresponding desired short name. You
may use '~' to represent your home directory but you should
protect it to avoid shell substitution.
'';
example = literalExpression ''
{ "\\~/projects/home-manager" = "prj:home-manager"; }
'';
};
settings = mkOption {
default = { };
type = with types; attrsOf (oneOf [ bool int str (listOf str) ]);
description = lib.mdDoc ''
This can be any key/value pair as described in
<https://github.com/justjanne/powerline-go>.
'';
example = literalExpression ''
{
hostname-only-if-ssh = true;
numeric-exit-codes = true;
cwd-max-depth = 7;
ignore-repos = [ "/home/me/big-project" "/home/me/huge-project" ];
}
'';
};
extraUpdatePS1 = mkOption {
default = "";
description =
lib.mdDoc "Shell code to execute after the prompt is set.";
example = ''
PS1=$PS1"NixOS> ";
'';
type = types.str;
};
};
};
config = {
programs.bash.initExtra =
mkIf (cfg.enable && config.programs.bash.enable) ''
function _update_ps1() {
local old_exit_status=$?
${
if evalMode then "eval " else "PS1="
}"$(${pkgs.powerline-go}/bin/powerline-go -error $old_exit_status -shell bash${commandLineArguments})"
${cfg.extraUpdatePS1}
return $old_exit_status
}
if [ "$TERM" != "linux" ]; then
PROMPT_COMMAND="_update_ps1;$PROMPT_COMMAND"
fi
'';
programs.zsh.initExtra = mkIf (cfg.enable && config.programs.zsh.enable) ''
function powerline_precmd() {
${
if evalMode then "eval " else "PS1="
}"$(${pkgs.powerline-go}/bin/powerline-go -error $? -shell zsh${commandLineArguments})"
${cfg.extraUpdatePS1}
}
function install_powerline_precmd() {
for s in "$\{precmd_functions[@]}"; do
if [ "$s" = "powerline_precmd" ]; then
return
fi
done
precmd_functions+=(powerline_precmd)
}
if [ "$TERM" != "linux" ]; then
install_powerline_precmd
fi
'';
# https://github.com/justjanne/powerline-go#fish
programs.fish.interactiveShellInit =
mkIf (cfg.enable && config.programs.fish.enable) ''
function fish_prompt
eval ${pkgs.powerline-go}/bin/powerline-go -error $status -jobs (count (jobs -p))${commandLineArguments}
${cfg.extraUpdatePS1}
end
'';
};
}