dotfiles.nix/home/fish.nix

170 lines
5.0 KiB
Nix
Raw Normal View History

2023-10-26 02:37:42 +00:00
{ pkgs, lib, ... }: {
2022-01-23 01:32:58 +00:00
programs.fish.enable = true;
2022-12-20 02:45:46 +00:00
programs.fish.plugins = [ pkgs.fishPlugins.fisher ];
2022-11-28 21:55:43 +00:00
xdg.configFile."fish/fish_plugins".text = ''
2023-10-26 02:37:42 +00:00
fishpkg/fish-humanize-duration
franciscolourenco/done
Gazorby/fish-abbreviation-tips
jorgebucaran/autopair.fish
2022-04-20 20:31:11 +00:00
jorgebucaran/replay.fish
joseluisq/gitnow
matthewess/fish-autovenv
2023-10-26 02:37:42 +00:00
nbsmokee/fish-spin
oh-my-fish/plugin-bang-bang
PatrickF1/colored_man_pages.fish
2022-04-20 20:31:11 +00:00
'';
2022-01-23 01:32:58 +00:00
programs.fish.functions = {
2023-10-26 02:37:42 +00:00
# user functions
2022-01-23 01:32:58 +00:00
mkdcd = {
argumentNames = [ "target" ];
body = ''
2022-11-30 03:20:03 +00:00
if test -z "$target"
echo "mkdcd requires an argument" 1>&2
return 1
end
2022-05-08 01:43:56 +00:00
mkdir -p $target
2022-01-23 01:32:58 +00:00
cd $target
'';
};
2023-10-26 02:37:42 +00:00
from-dir = {
argumentNames = [ "dir" ];
2022-01-23 01:32:58 +00:00
body = ''
2023-10-26 02:37:42 +00:00
pushd $dir
set -e argv[1]
$argv
popd
'';
};
darwin-rebuild-edit-with = {
argumentNames = [ "editor" "file" ];
body = ''
if test -z "$file"
set file flake.nix
end
from-nix $editor $file
2022-01-23 01:32:58 +00:00
'';
};
2023-10-26 02:37:42 +00:00
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
# light/dark mode helpers
# determine if dark mode is active
is-dark-mode.body = ''
defaults read -g AppleInterfaceStyle &>/dev/null
'';
2022-01-23 01:32:58 +00:00
2023-10-26 02:37:42 +00:00
# toggles `$term_background` between "light" and "dark". other Fish functions trigger when this
# variable changes. we use a universal variable so that all instances of Fish have the same
2022-01-23 01:32:58 +00:00
# value for the variable.
toggle-background.body = ''
if test "$term_background" = light
set -U term_background dark
else
set -U term_background light
end
'';
2023-10-26 02:37:42 +00:00
# set `$term_background` based on whether macOS is light or dark mode
set-background-to-macOS.body = ''
if is-dark-mode
set -U term_background dark
else
set -U term_background light
end
'';
2023-10-26 02:37:42 +00:00
# set `$term_background` based on an env var
set-background-to-env = {
argumentNames = [ "env_var" ];
2022-06-27 19:02:02 +00:00
body = ''
switch $$env_var
case 1
2022-10-16 23:43:04 +00:00
echo "Setting dark mode"
2022-06-27 19:02:02 +00:00
set -U term_background dark
case 0
2022-10-16 23:43:04 +00:00
echo "Setting light mode"
2022-06-27 19:02:02 +00:00
set -U term_background light
end
'';
};
2022-01-23 01:32:58 +00:00
2023-10-26 02:37:42 +00:00
# sets shell utilities to light or dark colorscheme based on `$term_background`.
2022-01-23 01:32:58 +00:00
set-shell-colors = {
body = ''
# Use correct theme for `btm` and `bat`
2022-01-23 01:32:58 +00:00
if test "$term_background" = light
2023-08-22 22:55:12 +00:00
alias btm "btm --color nord-light"
set -xg BAT_THEME OneHalfLight
2022-01-23 01:32:58 +00:00
else
2023-08-22 22:55:12 +00:00
alias btm "btm --color nord"
set -xg BAT_THEME OneHalfDark
2022-01-23 01:32:58 +00:00
end
# Set LS_COLORS
set -xg LS_COLORS (${pkgs.vivid}/bin/vivid generate one-$term_background)
2022-01-23 01:32:58 +00:00
'';
onVariable = "term_background";
};
};
2023-10-26 02:37:42 +00:00
# aliases
# TODO: refactor into abbreviations
programs.fish.shellAliases = let nixConfigDirectory = "~/dotfiles.nix";
in {
# Nix related
from-nix = "from-dir ${nixConfigDirectory}";
# darwin-rebuild build
drb = "from-nix darwin-rebuild build --flake .";
# darwin-rebuild switch full
drsf = "from-nix darwin-rebuild switch --flake .";
# darwin-rebuild switch (no homebrew)
drs = "drsf --override-input homebrew-enabled github:boolean-option/false";
# edit darwin-rebuild config in code/codium
drc = "code ${nixConfigDirectory}";
# edit darwin-rebuild config in (neo)vim
drv = "vim ${nixConfigDirectory}";
# edit darwin-rebuild config in helix
drh = "darwin-rebuild-edit-with hx";
flakeup = "nix flake update ${nixConfigDirectory}/";
nb = "nix build";
nd = "nix develop";
nf = "nix flake";
nr = "nix run";
ns = "nix search nixpkgs";
nsh = "nix shell";
nrp = "nix repl --expr '{ pkgs = (import <nixpkgs> { }); }'";
# Other
".." = "cd ..";
":q" = "exit";
cat = "${pkgs.bat}/bin/bat --style=plain --paging=never";
du = "${pkgs.du-dust}/bin/dust";
g = "${pkgs.gitAndTools.git}/bin/git";
ls = "${pkgs.eza}/bin/eza";
ll = "ls -l --time-style long-iso --icons";
la = "ll -a";
http = "${pkgs.xh}/bin/xh";
https = "${pkgs.xh}/bin/xhs";
top = "${pkgs.bottom}/bin/btm";
htop = "${pkgs.bottom}/bin/btm";
colortest = "${pkgs.terminal-colors}/bin/terminal-colors -o";
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
tb = "toggle-background";
sb = "set-background-to-macOS";
};
2022-01-23 01:32:58 +00:00
# Configuration that should be above `loginShellInit` and `interactiveShellInit`.
programs.fish.shellInit = ''
set -U fish_term24bit 1
${lib.optionalString pkgs.stdenv.isDarwin "set-background-to-macOS"}
'';
2023-10-26 02:37:42 +00:00
home.sessionVariables.VIRTUAL_ENV_DISABLE_PROMPT = "true";
2022-01-23 01:32:58 +00:00
programs.fish.interactiveShellInit = ''
2022-12-21 05:22:57 +00:00
set -g fish_greeting (set_color blue)"( ³) "(set_color cyan)"h"(set_color red)"e"(set_color yellow)"l"(set_color green)"l"(set_color magenta)"o "(set_color blue)"( ³)"(set_color normal)
2022-01-23 01:32:58 +00:00
fish_vi_key_bindings
2023-10-26 02:37:42 +00:00
${lib.optionalString pkgs.stdenv.isDarwin "set-shell-colors"}
2022-01-23 01:32:58 +00:00
'';
}