Refactor codebase to use nix modules

This commit is contained in:
Julia Lange 2024-04-14 05:40:02 -07:00
parent a4735423b4
commit ffada2703c
114 changed files with 1018 additions and 744 deletions

View file

@ -0,0 +1,45 @@
{ config, pkgs, lib, ... }:
{
options.fish = {
enable = lib.mkEnableOption "Enables fish";
};
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}
'';
};
};
}

View file

@ -0,0 +1,13 @@
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

View file

@ -0,0 +1,61 @@
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

View file

@ -0,0 +1,4 @@
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

View file

@ -0,0 +1 @@
git_is_worktree; and not command git diff --no-ext-diff --quiet --exit-code

View file

@ -0,0 +1,5 @@
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

View file

@ -0,0 +1,3 @@
git_is_repo; and begin
not command git diff --cached --no-ext-diff --quiet --exit-code
end

View file

@ -0,0 +1,6 @@
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

View file

@ -0,0 +1,2 @@
git_is_repo
and test (command git rev-parse --is-inside-git-dir) = false

View file

@ -0,0 +1,30 @@
# Block nesting of nnn in subshells
if test -n "$NNNLVL"
if [ (expr $NNNLVL + 0) -ge 1 ]
exit
return
end
end
# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
# To cd on quit only on ^G, remove the "-x" as in:
# set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd"
# NOTE: NNN_TMPFILE is fixed, should not be modified
if test -n "$XDG_CONFIG_HOME"
set -x NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd"
else
set -x NNN_TMPFILE "$HOME/.config/nnn/.lastd"
end
# Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
# stty start undef
# stty stop undef
# stty lwrap undef
# stty lnext undef
nnn -T v $argv
if test -e $NNN_TMPFILE
source $NNN_TMPFILE
rm $NNN_TMPFILE
end

View file

@ -0,0 +1 @@
command ssh -o IPQoS=0 $argv;