diff options
| author | Fuwn <[email protected]> | 2025-01-03 21:20:43 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-01-03 21:20:43 -0800 |
| commit | d561a5f5f892ad989b558229e722f25d1c518e65 (patch) | |
| tree | 6c9ff641cd4944bd718af89712bd48fce4b8a4a2 /modules | |
| parent | nara: add admin to trusted nix users (diff) | |
| download | nixos-config-d561a5f5f892ad989b558229e722f25d1c518e65.tar.xz nixos-config-d561a5f5f892ad989b558229e722f25d1c518e65.zip | |
nara: configure fish
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/mac/programs/default.nix | 6 | ||||
| -rw-r--r-- | modules/mac/programs/fish.nix | 85 |
2 files changed, 87 insertions, 4 deletions
diff --git a/modules/mac/programs/default.nix b/modules/mac/programs/default.nix index a1c7eed..eee7817 100644 --- a/modules/mac/programs/default.nix +++ b/modules/mac/programs/default.nix @@ -1,12 +1,10 @@ { imports = [ ./homebrew + ./fish.nix ./gnupg.nix ./vim.nix ]; - programs = { - nix-index.enable = true; - fish.enable = true; - }; + programs.nix-index.enable = true; } diff --git a/modules/mac/programs/fish.nix b/modules/mac/programs/fish.nix new file mode 100644 index 0000000..50bc837 --- /dev/null +++ b/modules/mac/programs/fish.nix @@ -0,0 +1,85 @@ +{ + programs.fish = { + enable = true; + shellInit = "set -g fish_greeting"; + + # https://github.com/arbourd/prompt + promptInit = '' + function fish_prompt -d "Prints left prompt" + set -l last_status $status + set -l glyph "\$" + set -l glyph_color (set_color normal) + set -l pwd (prompt_pwd) + set -l pwd_color (set_color blue) + + if test (id -u "$USER") -eq 0 + set glyph "#" + end + + if test "$last_status" -ne 0 + set pwd_color (set_color red) + end + + if command git rev-parse --git-dir > /dev/null 2>/dev/null + if ! command git diff --cached --no-ext-diff --quiet --exit-code 2>/dev/null + set glyph_color (set_color green) + else if command git rev-parse --verify --quiet refs/stash > /dev/null 2>/dev/null + set glyph_color (set_color yellow) + end + end + + printf "$pwd_color$pwd $glyph_color$glyph " + end + + function fish_right_prompt -d "Prints right prompt" + function __git_branch_name + command git symbolic-ref --short HEAD 2>/dev/null \ + || command git describe --tags --exact-match HEAD 2>/dev/null \ + || command git rev-parse --short HEAD 2>/dev/null + end + + function __git_changed + ! command git diff-index --quiet HEAD 2>/dev/null \ + || count (command git ls-files --others --exclude-standard) >/dev/null + end + + function __git_modified_files + count (command git status --porcelain --ignore-submodules 2>/dev/null) + end + + function __git_symbol + command git rev-list --count --left-right @{upstream}...@ 2>/dev/null | read behind ahead + + switch "$behind $ahead" + case " " "0 0" + case "0 *" + printf " ↑" + case "* 0" + printf " ↓" + case "*" + printf " ⥄" + end + end + + if set branch_name (__git_branch_name) + set -l git_symbol (__git_symbol) + set -l git_color + set -l git_modified_files (__git_modified_files) + set -l git_changed_files + + if __git_changed + set git_color (set_color red) + else + set git_color (set_color cyan) + end + + if test "$git_modified_files" -gt 0 + set git_changed_files (set_color yellow)"$git_modified_files changed " + end + + printf "$git_changed_files$git_color$branch_name$git_symbol" + end + end + ''; + }; +} |