mirror of
https://github.com/nmasur/dotfiles
synced 2025-07-06 19:00:14 +00:00
backups and fish functions
This commit is contained in:
@ -0,0 +1,46 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.nmasur.presets.programs.dotfiles;
|
||||
in
|
||||
{
|
||||
|
||||
# Allows me to make sure I can work on my dotfiles locally
|
||||
|
||||
options.nmasur.preset.programs.dotfiles = {
|
||||
enable = lib.mkEnableOption "Clone dotfiles repository";
|
||||
repo = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Git repo containing dotfiles";
|
||||
default = "git@github.com:nmasur/dotfiles";
|
||||
};
|
||||
path = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
description = "Path to dotfiles on disk";
|
||||
default = config.homePath + "/dev/personal/dotfiles";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
|
||||
home.activation = {
|
||||
|
||||
# Always clone dotfiles repository if it doesn't exist
|
||||
cloneDotfiles = 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 dotfiles repo, not necessary but convenient
|
||||
home.sessionVariables.DOTS = cfg.path;
|
||||
};
|
||||
}
|
@ -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)";
|
||||
|
@ -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
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
@ -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
|
@ -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
|
Reference in New Issue
Block a user