From e4e21a33460b76e61981d4a86a3751d705182d3e Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Wed, 24 Aug 2022 14:02:45 +0300 Subject: [PATCH] nix/shell: add starship prompt --- nix/home.nix | 7 ++++-- nix/shell/default.nix | 4 +--- nix/shell/prompt/default.nix | 1 + nix/shell/prompt/starship/config.nix | 31 +++++++++++++++++++++++++++ nix/shell/prompt/starship/default.nix | 28 ++++++++++++++++++++++++ nix/shell/zsh.nix | 7 +++++- 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 nix/shell/prompt/default.nix create mode 100644 nix/shell/prompt/starship/config.nix create mode 100644 nix/shell/prompt/starship/default.nix diff --git a/nix/home.nix b/nix/home.nix index d2596a2..b3b390b 100644 --- a/nix/home.nix +++ b/nix/home.nix @@ -23,7 +23,6 @@ in home.packages = with pkgs; [ # TODO: move packages to separate modules - any-nix-shell # fish and zsh support fo nix-shell asciinema # record the terminal neofetch # command-line system information @@ -46,7 +45,11 @@ in wm.xmonad.enable = true; # shell - shell.zsh.enable = true; + shell = { + zsh.enable = true; + + prompt.starship.enable = true; + }; # programs progs = { diff --git a/nix/shell/default.nix b/nix/shell/default.nix index a317de9..f75225d 100644 --- a/nix/shell/default.nix +++ b/nix/shell/default.nix @@ -1,3 +1 @@ -[ - ./zsh.nix -] +[ ./zsh.nix ] ++ (import ./prompt) diff --git a/nix/shell/prompt/default.nix b/nix/shell/prompt/default.nix new file mode 100644 index 0000000..664d604 --- /dev/null +++ b/nix/shell/prompt/default.nix @@ -0,0 +1 @@ +[ ./starship ] diff --git a/nix/shell/prompt/starship/config.nix b/nix/shell/prompt/starship/config.nix new file mode 100644 index 0000000..811d946 --- /dev/null +++ b/nix/shell/prompt/starship/config.nix @@ -0,0 +1,31 @@ +{ concatStrings }: + +{ + add_newline = true; + + format = concatStrings [ + "$directory" + "$git_branch" + "$git_commit" + "$git_state" + "$git_metrics" + "$git_status" + "$nix_shell" + "$cmd_duration" + "$jobs" + "$line_break" + "$character" + ]; + + character = { + success_symbol = "[➜](bold green)"; + error_symbol = "[➜](bold red)"; + }; + + git_commit.commit_hash_length = 6; + + directory = { + truncate_to_repo = true; + truncation_length = 6; + }; +} diff --git a/nix/shell/prompt/starship/default.nix b/nix/shell/prompt/starship/default.nix new file mode 100644 index 0000000..32afcb3 --- /dev/null +++ b/nix/shell/prompt/starship/default.nix @@ -0,0 +1,28 @@ +{ lib, config, pkgs, ... }: + +with lib; + +let + cfg = config.shell.prompt.starship; + + starshipConfig = import ./config.nix { + inherit concatStrings; + }; +in +{ + options.shell.prompt.starship = { + enable = mkOption { + type = types.bool; + default = false; + description = "Enable starship cross-shell prompt"; + }; + }; + + config = mkIf cfg.enable { + programs.starship = { + enable = true; + enableZshIntegration = config.shell.zsh.enable; + settings = starshipConfig; + }; + }; +} diff --git a/nix/shell/zsh.nix b/nix/shell/zsh.nix index 80f09eb..9dd599d 100644 --- a/nix/shell/zsh.nix +++ b/nix/shell/zsh.nix @@ -15,6 +15,9 @@ in }; config = mkIf cfg.enable { + # fish and zsh support fo nix-shell + home.packages = with pkgs; [ any-nix-shell ]; + programs.zsh = { enable = true; enableAutosuggestions = true; @@ -32,7 +35,7 @@ in }; oh-my-zsh = { - enable = true; + enable = !config.shell.prompt.starship.enable; theme = "robbyrussell"; }; @@ -53,6 +56,8 @@ in ''; initExtra = '' + any-nix-shell zsh --info-right | source /dev/stdin + eval "$(cat $HOME/repos/tas/shell/zsh)" ''; };