diff --git a/hmModules/apps/file-browsers/nnn/default.nix b/hmModules/apps/file-browsers/nnn/default.nix index f68cec2..8900ee7 100644 --- a/hmModules/apps/file-browsers/nnn/default.nix +++ b/hmModules/apps/file-browsers/nnn/default.nix @@ -13,5 +13,8 @@ NNN_FIFO = "/tmp/nnn.fifo"; NNN_TRASH = lib.mkIf config.trash.enable "1"; }; + fish.extraFunctions = lib.mkIf config.fish.enable { + n = ''${builtins.readFile ./nnn_fish_function.fish}''; + }; }; } diff --git a/hmModules/apps/shells/fish/functions/n.fish b/hmModules/apps/file-browsers/nnn/nnn_fish_function.fish similarity index 100% rename from hmModules/apps/shells/fish/functions/n.fish rename to hmModules/apps/file-browsers/nnn/nnn_fish_function.fish diff --git a/hmModules/apps/shells/fish/default.nix b/hmModules/apps/shells/fish/default.nix index 46e6de1..0390a09 100644 --- a/hmModules/apps/shells/fish/default.nix +++ b/hmModules/apps/shells/fish/default.nix @@ -3,43 +3,32 @@ { options.fish = { enable = lib.mkEnableOption "Enables fish"; + extraFunctions = lib.mkOption { + type = with lib.types; attrsOf lines; + default = {}; + }; }; config = lib.mkIf config.fish.enable { - programs.fish.enable = true; - - programs.fish.functions = { - fish_greeting = ""; - fish_prompt = '' - ${builtins.readFile ./functions/fish_prompt.fish} - ''; - fish_right_prompt = '' - ${builtins.readFile ./functions/fish_right_prompt.fish} - ''; - git_branch_name = '' - ${builtins.readFile ./functions/git_branch_name.fish} - ''; - git_is_dirty = '' - ${builtins.readFile ./functions/git_is_dirty.fish} - ''; - git_is_repo = '' - ${builtins.readFile ./functions/git_is_repo.fish} - ''; - git_is_staged = '' - ${builtins.readFile ./functions/git_is_staged.fish} - ''; - git_is_touched = '' - ${builtins.readFile ./functions/git_is_touched.fish} - ''; - git_is_worktree = '' - ${builtins.readFile ./functions/git_is_worktree.fish} - ''; - ssh = '' - ${builtins.readFile ./functions/ssh.fish} - ''; - n = lib.mkIf config.nnn.enable '' - ${builtins.readFile ./functions/n.fish} - ''; + programs.fish = { + enable = true; + functions = { + fish_greeting = ""; + fish_prompt = '' + if test $status -eq 0 + echo -n -s (set_color blue -o) τ " " (set_color normal) + else + echo -n -s (set_color red -o) τ " " (set_color normal) + end + ''; + fish_right_prompt = '' + git_prompt + echo -n -s (set_color blue) (prompt_pwd) " " + echo -n -s (set_color yellow) $CMD_DURATION ms + echo -n -s (set_color normal) + ''; + git_prompt = ''${builtins.readFile ./functions/git_prompt.fish}''; + } // config.fish.extraFunctions; }; }; } diff --git a/hmModules/apps/shells/fish/functions/fish_prompt.fish b/hmModules/apps/shells/fish/functions/fish_prompt.fish deleted file mode 100644 index 1740f57..0000000 --- a/hmModules/apps/shells/fish/functions/fish_prompt.fish +++ /dev/null @@ -1,13 +0,0 @@ -set -l last_command_status $status - -set -l symbol 'τ' - -set -l normal_color (set_color normal) -set -l symbol_color (set_color blue -o) -set -l error_color (set_color red -o) - -if test $last_command_status -eq 0 - echo -n -s $symbol_color $symbol " " $normal_color -else - echo -n -s $error_color $symbol " " $normal_color -end diff --git a/hmModules/apps/shells/fish/functions/fish_right_prompt.fish b/hmModules/apps/shells/fish/functions/fish_right_prompt.fish deleted file mode 100644 index f46799d..0000000 --- a/hmModules/apps/shells/fish/functions/fish_right_prompt.fish +++ /dev/null @@ -1,61 +0,0 @@ -set -l cwd -set -l cwd_color (set_color blue) -set -l normal_color (set_color normal) -set -l branch_color (set_color yellow) -set -l meta_color (set_color red) - -if git_is_repo - echo -n -s $branch_color (git_branch_name) $normal_color - set -l git_meta "" - if test (command git ls-files --others --exclude-standard | wc -w 2> /dev/null) -gt 0 - set git_meta "$git_meta?" - end - if test (command git rev-list --walk-reflogs --count refs/stash 2> /dev/null) - set git_meta "$git_meta\$" - end - if git_is_touched - git_is_dirty && set git_meta "$git_meta⨯" - git_is_staged && set git_meta "$git_meta●" - end - set -l commit_count (command git rev-list --count --left-right (git remote)/(git_branch_name)"...HEAD" 2> /dev/null) - if test $commit_count - set -l behind (echo $commit_count | cut -f 1) - set -l ahead (echo $commit_count | cut -f 2) - if test $behind -gt 0 - set git_meta "$git_meta🠋" - end - if test $ahead -gt 0 - set git_meta "$git_meta🠉" - end - end - if test $git_meta - echo -n -s $meta_color " " $git_meta " " $normal_color - else - echo -n -s " " - end - - - set root_folder (command git rev-parse --show-toplevel 2> /dev/null) - set parent_root_folder (dirname $root_folder) - set cwd (echo $PWD | sed -e "s|$parent_root_folder/||") -else - set cwd (prompt_pwd) -end - - -echo -n -s $cwd_color "$cwd" -set_color --dim - -set -l S (math $CMD_DURATION/1000) -set -l M (math $S/60) - - -echo -n -s " " -if test $M -gt 1 - echo -n -s $M m -else if test $S -gt 1 - echo -n -s $S s -else - echo -n -s $CMD_DURATION ms -end -set_color normal diff --git a/hmModules/apps/shells/fish/functions/git_branch_name.fish b/hmModules/apps/shells/fish/functions/git_branch_name.fish deleted file mode 100644 index 20b4149..0000000 --- a/hmModules/apps/shells/fish/functions/git_branch_name.fish +++ /dev/null @@ -1,4 +0,0 @@ -git_is_repo; and begin - command git symbolic-ref --short HEAD 2> /dev/null; - or command git show-ref --head -s --abbrev | head -n1 2> /dev/null -end diff --git a/hmModules/apps/shells/fish/functions/git_is_dirty.fish b/hmModules/apps/shells/fish/functions/git_is_dirty.fish deleted file mode 100644 index f92e54d..0000000 --- a/hmModules/apps/shells/fish/functions/git_is_dirty.fish +++ /dev/null @@ -1 +0,0 @@ -git_is_worktree; and not command git diff --no-ext-diff --quiet --exit-code diff --git a/hmModules/apps/shells/fish/functions/git_is_repo.fish b/hmModules/apps/shells/fish/functions/git_is_repo.fish deleted file mode 100644 index 00a2cfc..0000000 --- a/hmModules/apps/shells/fish/functions/git_is_repo.fish +++ /dev/null @@ -1,5 +0,0 @@ -test -d .git -or begin - set -l info (command git rev-parse --git-dir --is-bare-repository 2>/dev/null) - and test $info[2] = false -end diff --git a/hmModules/apps/shells/fish/functions/git_is_staged.fish b/hmModules/apps/shells/fish/functions/git_is_staged.fish deleted file mode 100644 index ef6b7ac..0000000 --- a/hmModules/apps/shells/fish/functions/git_is_staged.fish +++ /dev/null @@ -1,3 +0,0 @@ -git_is_repo; and begin - not command git diff --cached --no-ext-diff --quiet --exit-code -end diff --git a/hmModules/apps/shells/fish/functions/git_is_touched.fish b/hmModules/apps/shells/fish/functions/git_is_touched.fish deleted file mode 100644 index 5605630..0000000 --- a/hmModules/apps/shells/fish/functions/git_is_touched.fish +++ /dev/null @@ -1,6 +0,0 @@ -git_is_worktree; and begin - # The first checks for staged changes, the second for unstaged ones. - # We put them in this order because checking staged changes is *fast*. - not command git diff-index --cached --quiet HEAD -- >/dev/null 2>&1 - or not command git diff --no-ext-diff --quiet --exit-code >/dev/null 2>&1 -end diff --git a/hmModules/apps/shells/fish/functions/git_is_worktree.fish b/hmModules/apps/shells/fish/functions/git_is_worktree.fish deleted file mode 100644 index 8b2c700..0000000 --- a/hmModules/apps/shells/fish/functions/git_is_worktree.fish +++ /dev/null @@ -1,2 +0,0 @@ -git_is_repo -and test (command git rev-parse --is-inside-git-dir) = false diff --git a/hmModules/apps/shells/fish/functions/git_prompt.fish b/hmModules/apps/shells/fish/functions/git_prompt.fish new file mode 100644 index 0000000..a0bb65b --- /dev/null +++ b/hmModules/apps/shells/fish/functions/git_prompt.fish @@ -0,0 +1,69 @@ +function git_is_repo + test -d .git + or begin + set -l info (command git rev-parse --git-dir --is-bare-repository 2>/dev/null) + and test $info[2] = false + end +end + +function git_is_worktree + git_is_repo + and test (command git rev-parse --is-inside-git-dir) = false +end + +function git_is_dirty + git_is_worktree; and not command git diff --no-ext-diff --quiet --exit-code +end + +function git_is_staged + git_is_repo; and begin + not command git diff --cached --no-ext-diff --quiet --exit-code + end +end + +function git_branch_name + git_is_repo; and begin + command git symbolic-ref --short HEAD 2> /dev/null; + or command git show-ref --head -s --abbrev | head -n1 2> /dev/null + end +end + +function git_is_touched + git_is_worktree; and begin + # The first checks for staged changes, the second for unstaged ones. + # We put them in this order because checking staged changes is *fast*. + not command git diff-index --cached --quiet HEAD -- >/dev/null 2>&1 + or not command git diff --no-ext-diff --quiet --exit-code >/dev/null 2>&1 + end +end + +if git_is_repo + echo -n -s (set_color yellow) (git_branch_name) (set_color normal) + set -l git_meta "" + if test (command git ls-files --others --exclude-standard | wc -w 2> /dev/null) -gt 0 + set git_meta "$git_meta?" + end + if test (command git rev-list --walk-reflogs --count refs/stash 2> /dev/null) + set git_meta "$git_meta\$" + end + if git_is_touched + git_is_dirty && set git_meta "$git_meta⨯" + git_is_staged && set git_meta "$git_meta●" + end + set -l commit_count (command git rev-list --count --left-right (git remote)/(git_branch_name)"...HEAD" 2> /dev/null) + if test $commit_count + set -l behind (echo $commit_count | cut -f 1) + set -l ahead (echo $commit_count | cut -f 2) + if test $behind -gt 0 + set git_meta "$git_meta🠋" + end + if test $ahead -gt 0 + set git_meta "$git_meta🠉" + end + end + if test $git_meta + echo -n -s (set_color red) " " $git_meta " " (set_color normal) + else + echo -n -s " " + end +end diff --git a/systems/pan/default.nix b/systems/pan/default.nix index 7910e57..d05f21e 100644 --- a/systems/pan/default.nix +++ b/systems/pan/default.nix @@ -15,7 +15,7 @@ manpages.enable = true; trash.enable = true; - zsh.enable = true; + fish.enable = true; kitty.enable = true; kitty.font = "Cascadia Code"; git.enable = true;