208 lines
6.4 KiB
Nix
208 lines
6.4 KiB
Nix
{ config, pkgs, lib, ... }:
|
|
|
|
{
|
|
# Fish Shell
|
|
# https://rycee.gitlab.io/home-manager/options.html#opt-programs.fish.enable
|
|
programs.fish.enable = true;
|
|
|
|
# Add Fish plugins
|
|
home.packages = builtins.attrValues {
|
|
inherit (pkgs.fishPlugins)
|
|
autopair-fish
|
|
colored-man-pages
|
|
done;
|
|
};
|
|
programs.fish.plugins = [ pkgs.fishPlugins.fisher ];
|
|
|
|
xdg.configFile."fish/fish_plugins".text = ''
|
|
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
|
|
'';
|
|
|
|
# Fish functions ----------------------------------------------------------------------------- {{{
|
|
|
|
programs.fish.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
|
|
'';
|
|
};
|
|
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" ];
|
|
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 Fish Shell 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";
|
|
};
|
|
|
|
from-dir = {
|
|
argumentNames = [ "dir" ];
|
|
body = ''
|
|
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
|
|
'';
|
|
};
|
|
|
|
nix-unfree = {
|
|
argumentNames = [ "cmd" ];
|
|
body = ''
|
|
env NIX_ALLOW_UNFREE=1 nix $cmd --impure
|
|
'';
|
|
};
|
|
};
|
|
# }}}
|
|
|
|
# Fish configuration ------------------------------------------------------------------------- {{{
|
|
|
|
# Aliases
|
|
programs.fish.shellAliases =
|
|
let
|
|
inherit (config.home.primaryUser) nixConfigDirectory;
|
|
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 = "from-nix darwin-rebuild switch --flake . --override-input homebrew-enabled github:boolean-option/false";
|
|
# edit darwin-rebuild config in code/codium
|
|
drc = "code ${nixConfigDirectory}";
|
|
# edit darwin-rebuild config in 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";
|
|
nru = "nix-unfree run";
|
|
ns = "nix search nixpkgs";
|
|
nsh = "nix shell";
|
|
nshu = "nix-unfree shell";
|
|
nrp = "nix repl --expr '{ pkgs = (import <nixpkgs> { }); }'";
|
|
nrpu = "nix repl --expr '{ pkgs = (import <nixpkgs> { config.allowUnfree = true; }); }' --impure";
|
|
|
|
# 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.exa}/bin/exa";
|
|
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";
|
|
tb = "toggle-background";
|
|
colortest = "${pkgs.terminal-colors}/bin/terminal-colors -o";
|
|
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
|
|
sb = "set-background-to-macOS";
|
|
conda-init = "eval /opt/homebrew/bin/conda 'shell.fish' 'hook' $argv | source";
|
|
};
|
|
|
|
# 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 = ''
|
|
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)
|
|
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
|
|
# 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.
|
|
set-shell-colors
|
|
'';
|
|
# }}}
|
|
}
|