dotfiles.nix/home/fish.nix

186 lines
5.3 KiB
Nix
Raw Normal View History

{ pkgs, lib, ... }:
let nixConfigDirectory = "~/dotfiles.nix";
in {
programs.fish = {
enable = true;
2023-10-26 02:37:42 +00:00
# see flake.nix and pkgs/default.nix
plugins = pkgs.fishPlugins.flakePlugins;
2023-10-26 02:37:42 +00:00
functions = {
# user functions
mkdcd = {
argumentNames = [ "target" ];
body = ''
if test -z "$target"
echo "mkdcd requires an argument" 1>&2
return 1
end
mkdir -p $target
cd $target
'';
};
2022-01-23 01:32:58 +00:00
from-dir = {
argumentNames = [ "dir" ];
body = ''
pushd $dir
set -e argv[1]
$argv
popd
'';
};
2022-01-23 01:32:58 +00:00
darwin-rebuild-edit-with = {
argumentNames = [ "editor" "file" ];
body = ''
if test -z "$file"
set file flake.nix
end
from-nix $editor $file
'';
};
# TODO: use these to implement !! and .. abbreviations
# blocked on additional support for abbr in home-manager
# https://github.com/nix-community/home-manager/issues/3706
#
# taken from
# https://fishshell.com/docs/current/relnotes.html#fish-3-6-0-released-january-7-2023
# last-history-item.body = ''
# echo $history[1]
# '';
# multi-cd.body = ''
# echo cd (string repeat -n (math (string length -- $argv[1]) - 1) ../)
# '';
} // 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
'';
# 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
# value for the variable.
toggle-background.body = ''
if test "$term_background" = light
2022-06-27 19:02:02 +00:00
set -U term_background dark
else
2022-06-27 19:02:02 +00:00
set -U term_background light
end
'';
2022-01-23 01:32:58 +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
2022-01-23 01:32:58 +00:00
else
set -U term_background light
2022-01-23 01:32:58 +00:00
end
'';
# set `$term_background` based on an env var
set-background-to-env = {
argumentNames = [ "env_var" ];
body = ''
switch $$env_var
case 1
echo "Setting dark mode"
set -U term_background dark
case 0
echo "Setting light mode"
set -U term_background light
end
'';
};
# sets shell utilities to light or dark colorscheme based on `$term_background`.
set-shell-colors = {
body = ''
# Use correct theme for `btm` and `bat`
if test "$term_background" = light
alias btm "btm --color nord-light"
set -xg BAT_THEME OneHalfLight
else
alias btm "btm --color nord"
set -xg BAT_THEME OneHalfDark
end
# Set LS_COLORS
set -xg LS_COLORS (${pkgs.vivid}/bin/vivid generate one-$term_background)
'';
onVariable = "term_background";
};
2022-01-23 01:32:58 +00:00
};
shellAbbrs = {
".." = "cd ..";
# 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 =
"from-nix darwin-rebuild switch --flake . --override-input homebrew-enabled github:boolean-option/false";
# edit darwin-rebuild config in helix
drh = "darwin-rebuild-edit-with hx";
# edit darwin-rebuild config in zed
drz = "zed ${nixConfigDirectory}";
2022-01-23 01:32:58 +00:00
nb = "nix build";
nd = "nix develop";
nf = "nix flake";
nfc = "nix flake check";
nfi = "nix flake init";
nfs = "nix flake show";
nfu = "nix flake update";
nr = "nix run";
ns = "nix search nixpkgs";
nsh = "nix shell";
nrp = "nix repl --expr '{ pkgs = (import <nixpkgs> { }); }'";
g = "git";
2023-12-23 01:49:53 +00:00
ga = "git add";
gc = "git commit";
gd = "git diff";
gl = "git log";
gp = "git push";
stage = "git add .";
commit = "git commit";
push = "git push";
2023-12-23 01:49:53 +00:00
pull = "git pull";
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
tb = "toggle-background";
sb = "set-background-to-macOS";
};
shellAliases = {
# nix related
from-nix = "from-dir ${nixConfigDirectory}";
# other
":q" = "exit";
cat = "bat --style=plain --paging=never";
du = "dust";
http = "xh";
https = "xhs";
top = "btm";
htop = "btm --basic";
colortest = "terminal-colors -o";
};
2022-01-23 01:32:58 +00:00
# configuration that should be above `loginShellInit` and `interactiveShellInit`.
shellInit = ''
set -U fish_term24bit 1
${lib.optionalString pkgs.stdenv.isDarwin "set-background-to-macOS"}
'';
interactiveShellInit = ''
set -g fish_greeting (set_color red)"( ³)"(set_color yellow)" hello "(set_color blue)"( ³)"(set_color normal)
fish_vi_key_bindings
${lib.optionalString pkgs.stdenv.isDarwin "set-shell-colors"}
'';
};
2023-10-26 02:37:42 +00:00
home.sessionVariables.VIRTUAL_ENV_DISABLE_PROMPT = "true";
2022-01-23 01:32:58 +00:00
}