move fish functions into nix

This commit is contained in:
Noah Masur
2022-04-30 10:21:43 -04:00
parent 47d09a98e2
commit f5508c747c
55 changed files with 331 additions and 727 deletions

View File

@ -227,6 +227,7 @@
window = {
border = 1;
hideEdgeBorders = "both";
titlebar = false;
};
workspaceAutoBackAndForth = false;
workspaceOutputAssign = [ ];

View File

@ -25,5 +25,10 @@
xclip # Clipboard
];
home-manager.users.${user}.programs.fish.shellAliases = {
pbcopy = "xclip -selection clipboard -in";
pbpaste = "xclip -selection clipboard -out";
};
}

View File

@ -13,6 +13,13 @@
programs.git.extraConfig.core.editor = "nvim";
home.sessionVariables = { EDITOR = "nvim"; };
programs.fish = {
shellAliases = { vim = "nvim"; };
shellAbbrs = {
vll = "vim -c 'Telescope oldfiles'";
vimrc = "vim ${builtins.toString ../../.}/nvim.configlink/init.lua";
};
};
};

View File

@ -3,15 +3,69 @@
users.users.${user}.shell = pkgs.fish;
home-manager.users.${user} = {
home.packages = with pkgs; [ fzf exa fd bat ripgrep ];
programs.fish = {
enable = true;
functions = { };
functions = {
commandline-git-commits = {
description = "Insert commit into commandline";
body = builtins.readFile
../../fish.configlink/functions/commandline-git-commits.fish;
};
copy = {
description = "Copy file contents into clipboard";
body = "cat $argv | pbcopy"; # Need to fix for non-macOS
};
edit = {
description = "Open a file in Vim";
body = builtins.readFile ../../fish.configlink/functions/edit.fish;
};
envs = {
description = "Evaluate a bash-like environment variables file";
body = ''set -gx (cat $argv | tr "=" " " | string split ' ')'';
};
fcd = {
description = "Jump to directory";
argumentNames = "directory";
body = builtins.readFile ../../fish.configlink/functions/fcd.fish;
};
fish_user_key_bindings = {
body = builtins.readFile
../../fish.configlink/functions/fish_user_key_bindings.fish;
};
ip = {
body = builtins.readFile ../../fish.configlink/functions/ip.fish;
};
json = {
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 ../../fish.configlink/functions/note.fish;
};
projects = {
description = "Jump to a project";
body = ''
set projdir (ls $PROJ | fzf)
and cd $PROJ/$projdir
and commandline -f execute
'';
};
recent = {
description = "Open a recent file in Vim";
body = builtins.readFile ../../fish.configlink/functions/recent.fish;
};
syncnotes = {
description = "Full git commit on notes";
body =
builtins.readFile ../../fish.configlink/functions/syncnotes.fish;
};
};
interactiveShellInit = "";
loginShellInit = "";
shellAliases = {
vim = "nvim";
sudo = "doas";
};
shellAliases = { ls = "exa"; };
shellAbbrs = {
# Directory aliases
@ -40,17 +94,11 @@
# Vim
v = "vim";
vl = "vim -c 'normal! `0'";
vll = "vim -c 'Telescope oldfiles'";
vimrc = "vim ${builtins.toString ../../.}/nvim.configlink/init.lua";
# Notes
qn = "quicknote";
sn = "syncnotes";
to = "today";
work = "vim $NOTES_PATH/work.md";
# CLI Tools
cat = "bat"; # Swap cat with bat
h = "http -Fh --all"; # Curl site for headers
m = "make"; # For makefiles
@ -90,7 +138,6 @@
ca = "cargo";
};
shellAliases = { };
shellInit = "";
};
@ -113,7 +160,6 @@
xdg.configFile = {
"starship.toml".source = ../../starship/starship.toml.configlink;
"fish/functions".source = ../../fish.configlink/functions;
};
programs.direnv = {

View File

@ -1,4 +1,8 @@
{ pkgs, user, fullName, ... }: {
{ config, pkgs, lib, user, fullName, ... }:
let home-packages = config.home-manager.users.${user}.home.packages;
in {
home-manager.users.${user} = {
programs.git = {
@ -25,7 +29,7 @@
gcae = "git commit --amend";
gu = "git pull";
gp = "git push";
gpp = "git_set_upstream";
gpp = "git-push-upstream";
gl = "git log --graph --decorate --oneline -20";
gll = "git log --graph --decorate --oneline";
gco = "git checkout";
@ -40,6 +44,68 @@
gcp = "git cherry-pick";
cdg = "cd (git rev-parse --show-toplevel)";
};
programs.fish.functions = lib.mkIf (builtins.elem pkgs.fzf home-packages
&& builtins.elem pkgs.bat home-packages) {
git = {
body = builtins.readFile ../../fish.configlink/functions/git.fish;
};
git-add-fuzzy = {
body = builtins.readFile
../../fish.configlink/functions/git-add-fuzzy.fish;
};
git-fuzzy-branch = {
argumentNames = "header";
body = builtins.readFile
../../fish.configlink/functions/git-fuzzy-branch.fish;
};
git-checkout-fuzzy = {
body = ''
set branch (git-fuzzy-branch "checkout branch...")
and git checkout $branch
'';
};
git-delete-fuzzy = {
body = ''
set branch (git-fuzzy-branch "delete branch...")
and git branch -d $branch
'';
};
git-force-delete-fuzzy = {
body = ''
set branch (git-fuzzy-branch "force delete branch...")
and git branch -D $branch
'';
};
git-merge-fuzzy = {
body = ''
set branch (git-fuzzy-branch "merge from...")
and git merge $branch
'';
};
git-show-fuzzy = {
body = builtins.readFile
../../fish.configlink/functions/git-show-fuzzy.fish;
};
git-commits = {
body =
builtins.readFile ../../fish.configlink/functions/git-commits.fish;
};
git-history = {
body =
builtins.readFile ../../fish.configlink/functions/git-history.fish;
};
git-push-upstream = {
description = "Create upstream branch";
body = builtins.readFile
../../fish.configlink/functions/git-push-upstream.fish;
};
uncommitted = {
description = "Find uncommitted git repos";
body =
builtins.readFile ../../fish.configlink/functions/uncommitted.fish;
};
};
};
}

View File

@ -9,13 +9,25 @@
settings.git_protocol = "https";
};
programs.fish.shellAbbrs = {
ghr = "gh repo view -w";
gha =
"gh run list | head -1 | awk '{ print $(NF-2) }' | xargs gh run view";
grw = "gh run watch";
grf = "gh run view --log-failed";
grl = "gh run view --log";
programs.fish = {
shellAbbrs = {
ghr = "gh repo view -w";
gha =
"gh run list | head -1 | awk '{ print $(NF-2) }' | xargs gh run view";
grw = "gh run watch";
grf = "gh run view --log-failed";
grl = "gh run view --log";
};
functions = {
repos = {
description = "Clone GitHub repositories";
argumentNames = "organization";
body = ''
set directory (gh-repos $organization)
and cd $directory
'';
};
};
};
};

View File

@ -13,32 +13,45 @@ let
in {
home-manager.users.${user}.home = {
home-manager.users.${user} = {
packages = with pkgs; [
home.packages = with pkgs; [
unzip
rsync
fzf
ripgrep
bat
fd
exa
sd
zoxide
jq
tealdeer
gh
direnv
tree
htop
glow
prettyping
qrencode
];
file = {
home.file = {
".rgignore".text = ignorePatterns;
".fdignore".text = ignorePatterns;
};
programs.fish.shellAbbrs = {
cat = "bat"; # Swap cat with bat
};
programs.fish.functions = {
ping = {
description = "Improved ping";
argumentNames = "target";
body = "prettyping --nolegend $target";
};
qr = {
body =
"qrencode $argv[1] -o /tmp/qr.png | open /tmp/qr.png"; # Fix for non-macOS
};
};
};
}

View File

@ -1,6 +1,6 @@
# Replace sudo with doas
{ ... }: {
{ user, ... }: {
security = {
@ -23,4 +23,6 @@
}];
};
};
home-manager.users.${user}.programs.fish.shellAliases = { sudo = "doas"; };
}