backups and fish functions

This commit is contained in:
Noah Masur
2025-01-31 15:40:41 -05:00
parent b123ae3e69
commit e1f987e83b
13 changed files with 225 additions and 167 deletions

View File

@ -6,13 +6,13 @@
}:
let
cfg = config.nmasur.presets.services.dotfiles;
cfg = config.nmasur.presets.programs.dotfiles;
in
{
# Allows me to make sure I can work on my dotfiles locally
options.nmasur.preset.services.dotfiles = {
options.nmasur.preset.programs.dotfiles = {
enable = lib.mkEnableOption "Clone dotfiles repository";
repo = lib.mkOption {
type = lib.types.str;

View File

@ -48,11 +48,6 @@ in
description = "Tidy up JSON using jq";
body = "pbpaste | jq '.' | pbcopy"; # Need to fix for non-macOS
};
note = {
description = "Edit or create a note";
argumentNames = "filename";
body = builtins.readFile ./functions/note.fish;
};
recent = {
description = "Open a recent file in Vim";
body = builtins.readFile ./functions/recent.fish;
@ -61,10 +56,6 @@ in
description = "Search and open the relevant file in Vim";
body = builtins.readFile ./functions/search-and-edit.fish;
};
syncnotes = {
description = "Full git commit on notes";
body = builtins.readFile ./functions/syncnotes.fish;
};
_which = {
description = "Identify the path to a program in the shell";
body = "command --search (string sub --start=2 $argv)";

View File

@ -0,0 +1,77 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.nmasur.presets.programs.notes;
in
{
options.nmasur.preset.programs.notes = {
enable = lib.mkEnableOption "Manage notes repository";
repo = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "Git repo containing notes";
default = null;
};
path = lib.mkOption {
type = lib.types.path;
description = "Path to notes on disk";
default = config.homePath + "/dev/personal/notes";
};
};
config = lib.mkIf cfg.enable {
home.activation = lib.mkIf (cfg.repo != null) {
# Always clone notes repository if it doesn't exist
clonenotes = config.lib.dag.entryAfter [ "writeBoundary" "loadkey" ] ''
if [ ! -d "${cfg.path}" ]; then
run mkdir --parents $VERBOSE_ARG $(dirname "${cfg.path}")
run ${pkgs.git}/bin/git \
clone ${cfg.repo} "${cfg.path}"
fi
'';
};
# Set a variable for notes repo, not necessary but convenient
home.sessionVariables.NOTES_PATH = cfg.path;
programs.fish.functions = {
syncnotes = {
description = "Full git commit on notes";
body = builtins.readFile lib.getExe (
pkgs.writers.writeFishBin "syncnotes" {
makeWrapperArgs = [
"--prefix"
"PATH"
":"
"${lib.makeBinPath [ pkgs.git ]}"
];
} builtins.readFile ./syncnotes.fish
);
};
note = {
description = "Edit or create a note";
argumentNames = "filename";
body = builtins.readFile lib.getExe (
pkgs.writers.writeFishBin "note" {
makeWrapperArgs = [
"--prefix"
"PATH"
":"
"${lib.makeBinPath [
pkgs.vim
pkgs.fzf
]}"
];
} builtins.readFile ./note.fish
);
};
};
};
}

View File

@ -0,0 +1,8 @@
if test -n "$filename"
vim "$NOTES_PATH/$filename.md"
else
set file (ls $NOTES_PATH | fzf)
if [ $status -eq 0 ]
vim "$NOTES_PATH/$file"
end
end

View File

@ -0,0 +1,7 @@
set current_dir $PWD
cd $NOTES_PATH
git pull
git add -A
git commit -m autosync
git push
cd $current_dir