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,9 @@
{ config, pkgs, lib, ... }:
{
imports = [
./fish
./xonsh
./zsh
];
}

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;

View file

@ -0,0 +1,22 @@
{ config, pkgs, lib, ... }:
let rootPath = ./.; in
{
options.xonsh = {
enable = lib.mkEnableOption "Enables xonsh";
};
config = lib.mkIf config.xonsh.enable {
home.packages = with pkgs; [
xonsh
];
home.sessionVariables = {
PROMPT = "τ ";
RIGHT_PROMPT = "{YELLOW}{gitstatus: {} }{BLUE}{short_cwd}{DEFAULT}";
VI_MODE = 1;
};
xdg.configFile."xonshrc" = {
source = rootPath + "/rc.xsh";
target = "xonsh/rc.xsh";
};
};
}

View file

@ -0,0 +1,7 @@
#!/usr/bin/env xonsh
if $XONSH_INTERACTIVE:
if '__HM_SESS_VARS_SOURCED' in ${...}:
del $__HM_SESS_VARS_SOURCED
source-bash "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" --suppress-skip-message
cat "$HOME/.cache/wallust/sequences"

View file

@ -0,0 +1,47 @@
{ config, pkgs, lib, ... }:
{
options.zsh = {
enable = lib.mkEnableOption "Enable zsh";
};
config = lib.mkIf config.zsh.enable {
programs.zsh = {
enable = true;
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
dotDir = ".config/zsh";
history.save = 10000;
history.size = 10000;
history.path = "${config.xdg.dataHome}/zsh/history";
initExtra = let
lf = lib.optionalString config.lf.enable ''
# Lf change directory command
lfcd () {
cd "$(command lf -print-last-dir "$@")"
}
bindkey -s '^o' 'lfcd\n'
'';
in lf + ''
# Nix-shell
${pkgs.nix-your-shell}/bin/nix-your-shell zsh | source /dev/stdin
# Prompt
autoload -U colors && colors
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr '·*'
zstyle ':vcs_info:*' stagedstr '·+'
zstyle ':vcs_info:git:*' formats '%b%u%c'
export PROMPT="%(0?.%F{white}.%? %F{red})τ%f "
export RPROMPT="%F{yellow}\$vcs_info_msg_0_%f %F{blue}%~%f"
'';
};
};
}