dotfiles.nix/home/fish.nix

208 lines
6.4 KiB
Nix
Raw Normal View History

2022-01-23 01:32:58 +00:00
{ config, pkgs, lib, ... }:
{
# Fish Shell
# https://rycee.gitlab.io/home-manager/options.html#opt-programs.fish.enable
programs.fish.enable = true;
# Add Fish plugins
2022-12-20 02:45:46 +00:00
home.packages = builtins.attrValues {
inherit (pkgs.fishPlugins)
autopair-fish
colored-man-pages
done;
};
programs.fish.plugins = [ pkgs.fishPlugins.fisher ];
2022-01-23 01:32:58 +00:00
2022-11-28 21:55:43 +00:00
xdg.configFile."fish/fish_plugins".text = ''
2022-04-20 20:31:11 +00:00
jorgebucaran/replay.fish
americanhanko/fish-spin
joseluisq/gitnow
fishpkg/fish-humanize-duration
oh-my-fish/plugin-bang-bang
matthewess/fish-autovenv
Gazorby/fish-abbreviation-tips
'';
2022-01-23 01:32:58 +00:00
# Fish functions ----------------------------------------------------------------------------- {{{
programs.fish.functions = {
# User functions
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
'';
};
unz = {
argumentNames = [ "target" ];
body = ''
# strip extensions
string match \*.zip $target; and set target (string split -r -m1 . $target)[1]
unzip -d $target $target
'';
};
# Helpers
# 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
set -U term_background dark
else
set -U term_background light
end
'';
# Set `$term_background` based on whether macOS is light or dark mode. 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.
set-background-to-macOS.body = ''
if is-dark-mode
set -U term_background dark
else
set -U term_background light
end
'';
# 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
# Sets Fish Shell to light or dark colorscheme based on `$term_background`.
set-shell-colors = {
body = ''
# Use correct theme for `btm` and `bat`
2022-01-23 01:32:58 +00:00
if test "$term_background" = light
alias btm "btm --color default-light"
set -xg BAT_THEME OneHalfLight
2022-01-23 01:32:58 +00:00
else
alias btm "btm --color default"
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";
};
2022-07-17 16:37:52 +00:00
from-dir = {
argumentNames = [ "dir" ];
body = ''
pushd $dir
set -e argv[1]
$argv
popd
'';
};
2022-08-29 22:52:58 +00:00
2022-09-26 02:34:46 +00:00
darwin-rebuild-edit-with = {
2022-10-10 21:54:15 +00:00
argumentNames = [ "editor" "file" ];
2022-08-29 22:52:58 +00:00
body = ''
if test -z "$file"
set file flake.nix
2022-08-29 22:52:58 +00:00
end
2022-09-26 02:34:46 +00:00
from-nix $editor $file
2022-08-29 22:52:58 +00:00
'';
};
2022-10-10 21:54:15 +00:00
nix-unfree = {
argumentNames = [ "cmd" ];
body = ''
env NIX_ALLOW_UNFREE=1 nix $cmd --impure
'';
};
2022-01-23 01:32:58 +00:00
};
# }}}
# Fish configuration ------------------------------------------------------------------------- {{{
# Aliases
programs.fish.shellAliases =
let
2022-10-10 21:54:15 +00:00
inherit (config.home.primaryUser) nixConfigDirectory;
in
2022-12-20 02:45:46 +00:00
{
# Nix related
2022-10-10 21:54:15 +00:00
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 = "from-nix darwin-rebuild switch --flake . --override-input homebrew-enabled github:boolean-option/false";
2022-09-15 21:17:21 +00:00
# edit darwin-rebuild config in code/codium
2022-10-10 21:54:15 +00:00
drc = "code ${nixConfigDirectory}";
# edit darwin-rebuild config in vim
2022-10-10 21:54:15 +00:00
drv = "vim ${nixConfigDirectory}";
2022-09-26 02:34:46 +00:00
# edit darwin-rebuild config in helix
drh = "darwin-rebuild-edit-with hx";
2022-10-10 21:54:15 +00:00
flakeup = "nix flake update ${nixConfigDirectory}/";
nb = "nix build";
nd = "nix develop";
nf = "nix flake";
nr = "nix run";
2022-10-10 21:54:15 +00:00
nru = "nix-unfree run";
2022-04-21 01:26:30 +00:00
ns = "nix search nixpkgs";
2022-05-08 01:43:56 +00:00
nsh = "nix shell";
2022-10-10 21:54:15 +00:00
nshu = "nix-unfree shell";
nrp = "nix repl --expr '{ pkgs = (import <nixpkgs> { }); }'";
nrpu = "nix repl --expr '{ pkgs = (import <nixpkgs> { config.allowUnfree = true; }); }' --impure";
2022-01-23 01:32:58 +00:00
# Other
".." = "cd ..";
":q" = "exit";
2022-12-21 05:22:57 +00:00
cat = "${pkgs.bat}/bin/bat --style=plain --paging=never";
du = "${pkgs.du-dust}/bin/dust";
g = "${pkgs.gitAndTools.git}/bin/git";
ls = "${pkgs.exa}/bin/exa";
ll = "ls -l --time-style long-iso --icons";
la = "ll -a";
2022-12-21 05:22:57 +00:00
http = "${pkgs.xh}/bin/xh";
https = "${pkgs.xh}/bin/xhs";
top = "${pkgs.bottom}/bin/btm";
htop = "${pkgs.bottom}/bin/btm";
tb = "toggle-background";
2023-04-14 19:57:47 +00:00
colortest = "${pkgs.terminal-colors}/bin/terminal-colors -o";
2022-12-21 05:22:57 +00:00
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
2022-06-27 18:50:03 +00:00
sb = "set-background-to-macOS";
2022-11-17 01:02:03 +00:00
conda-init = "eval /opt/homebrew/bin/conda 'shell.fish' 'hook' $argv | source";
};
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"}
'';
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
set VIRTUAL_ENV_DISABLE_PROMPT true
bind -M insert ! __history_previous_command
bind -M insert '$' __history_previous_command_arguments
${pkgs.thefuck}/bin/thefuck --alias | source
2022-05-08 01:43:56 +00:00
# Run function to set colors that are dependent on `$term_background` and to register them so
# they are triggered when the relevent event happens or variable changes.
2022-01-23 01:32:58 +00:00
set-shell-colors
'';
# }}}
}