hmApps, refactor, clean up, break groups
This commit is contained in:
parent
49cb3c949c
commit
7cc650aea6
32 changed files with 13 additions and 69 deletions
43
hmModules/apps/fish/app.nix
Normal file
43
hmModules/apps/fish/app.nix
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{ config, lib, ... }:
|
||||
let
|
||||
functionModule = with lib.types; submodule {
|
||||
options = {
|
||||
body = lib.mkOption { type = lines; };
|
||||
wraps = lib.mkOption {
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
options.fish = {
|
||||
enable = lib.mkEnableOption "Enables fish";
|
||||
extraFunctions = lib.mkOption {
|
||||
type = with lib.types; attrsOf (either lines functionModule);
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf config.fish.enable {
|
||||
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;
|
||||
};
|
||||
};
|
||||
}
|
||||
69
hmModules/apps/fish/functions/git_prompt.fish
Normal file
69
hmModules/apps/fish/functions/git_prompt.fish
Normal file
|
|
@ -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
|
||||
1
hmModules/apps/fish/functions/ssh.fish
Normal file
1
hmModules/apps/fish/functions/ssh.fish
Normal file
|
|
@ -0,0 +1 @@
|
|||
command ssh -o IPQoS=0 $argv;
|
||||
Loading…
Add table
Add a link
Reference in a new issue