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-10-10 21:54:15 +00:00
|
|
|
home.packages = with pkgs.fishPlugins; [ done ];
|
2022-01-23 01:32:58 +00:00
|
|
|
|
|
|
|
programs.fish.plugins = [
|
|
|
|
{
|
|
|
|
name = "fisher";
|
2022-10-17 17:29:38 +00:00
|
|
|
src = pkgs.fisher-src;
|
2022-01-23 01:32:58 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-04-20 20:31:48 +00:00
|
|
|
home.file.".config/fish/fish_plugins".text = ''
|
2022-04-20 20:31:11 +00:00
|
|
|
jorgebucaran/autopair.fish
|
|
|
|
jorgebucaran/replay.fish
|
|
|
|
jorgebucaran/getopts.fish
|
|
|
|
americanhanko/fish-spin
|
|
|
|
joseluisq/gitnow
|
|
|
|
fishpkg/fish-humanize-duration
|
|
|
|
oh-my-fish/plugin-bang-bang
|
|
|
|
matthewess/fish-autovenv
|
|
|
|
jethrokuan/z
|
|
|
|
Gazorby/fish-abbreviation-tips
|
|
|
|
'';
|
2022-01-23 01:32:58 +00:00
|
|
|
|
|
|
|
# Fish functions ----------------------------------------------------------------------------- {{{
|
|
|
|
|
|
|
|
programs.fish.functions = {
|
|
|
|
# User functions
|
|
|
|
mkdcd = {
|
|
|
|
argumentNames = [ "target" ];
|
|
|
|
body = ''
|
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.
|
2022-07-16 20:34:47 +00:00
|
|
|
set-background-to-macOS.body = ''
|
2022-07-24 19:58:03 +00:00
|
|
|
if is-dark-mode
|
2022-07-16 20:34:47 +00:00
|
|
|
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 = ''
|
2022-07-16 20:34:47 +00:00
|
|
|
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
|
2022-07-16 20:34:47 +00:00
|
|
|
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`
|
|
|
|
if test "$term_background" = light
|
|
|
|
alias btm "btm --color default-light"
|
|
|
|
else
|
|
|
|
alias btm "btm --color default"
|
|
|
|
end
|
|
|
|
# Set LS_COLORS
|
2022-07-24 19:58:03 +00:00
|
|
|
set -xg LS_COLORS (${pkgs.vivid}/bin/vivid generate one-$term_background)
|
2022-01-23 01:32:58 +00:00
|
|
|
# Set color variables
|
|
|
|
if test "$term_background" = light
|
|
|
|
set emphasized_text brgreen # base01
|
|
|
|
set normal_text bryellow # base00
|
|
|
|
set secondary_text brcyan # base1
|
|
|
|
set background_light white # base2
|
|
|
|
set background brwhite # base3
|
|
|
|
else
|
|
|
|
set emphasized_text brcyan # base1
|
|
|
|
set normal_text brblue # base0
|
|
|
|
set secondary_text brgreen # base01
|
|
|
|
set background_light black # base02
|
|
|
|
set background brblack # base03
|
|
|
|
end
|
|
|
|
# Set Fish colors that change when background changes
|
|
|
|
set -g fish_color_command $emphasized_text --bold # color of commands
|
|
|
|
set -g fish_color_param $normal_text # color of regular command parameters
|
|
|
|
set -g fish_color_comment $secondary_text # color of comments
|
|
|
|
set -g fish_color_autosuggestion $secondary_text # color of autosuggestions
|
|
|
|
set -g fish_pager_color_prefix $emphasized_text --bold # color of the pager prefix string
|
|
|
|
set -g fish_pager_color_description $selection_text # color of the completion description
|
|
|
|
set -g fish_pager_color_selected_prefix $background
|
|
|
|
set -g fish_pager_color_selected_completion $background
|
|
|
|
set -g fish_pager_color_selected_description $background
|
|
|
|
'';
|
|
|
|
onVariable = "term_background";
|
|
|
|
};
|
2022-07-17 16:37:52 +00:00
|
|
|
|
|
|
|
init-shell-colors.body = ''
|
|
|
|
set -g fish_color_quote cyan # color of commands
|
|
|
|
set -g fish_color_redirection brmagenta # color of IO redirections
|
|
|
|
set -g fish_color_end blue # color of process separators like ';' and '&'
|
|
|
|
set -g fish_color_error red # color of potential errors
|
|
|
|
set -g fish_color_match --reverse # color of highlighted matching parenthesis
|
|
|
|
set -g fish_color_search_match --background=yellow
|
|
|
|
set -g fish_color_selection --reverse # color of selected text (vi mode)
|
|
|
|
set -g fish_color_operator green # color of parameter expansion operators like '*' and '~'
|
|
|
|
set -g fish_color_escape red # color of character escapes like '\n' and and '\x70'
|
|
|
|
set -g fish_color_cancel red # color of the '^C' indicator on a canceled command
|
|
|
|
'';
|
2022-07-24 19:58:03 +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"
|
2022-09-06 14:51:18 +00:00
|
|
|
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
|
2022-01-23 23:50:34 +00:00
|
|
|
programs.fish.shellAliases =
|
|
|
|
let
|
2022-10-10 21:54:15 +00:00
|
|
|
inherit (config.home.primaryUser) nixConfigDirectory;
|
2022-01-23 23:50:34 +00:00
|
|
|
in
|
|
|
|
with pkgs; {
|
|
|
|
# Nix related
|
2022-10-10 21:54:15 +00:00
|
|
|
from-nix = "from-dir ${nixConfigDirectory}";
|
2022-07-24 19:58:03 +00:00
|
|
|
# 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}";
|
2022-07-24 19:58:03 +00:00
|
|
|
# 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}/";
|
2022-01-23 23:50:34 +00:00
|
|
|
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
|
|
|
|
2022-01-23 23:50:34 +00:00
|
|
|
# Other
|
|
|
|
".." = "cd ..";
|
|
|
|
":q" = "exit";
|
2022-11-19 20:13:42 +00:00
|
|
|
cat = "${bat}/bin/bat --style=plain --paging=never";
|
2022-01-23 23:50:34 +00:00
|
|
|
du = "${du-dust}/bin/dust";
|
|
|
|
g = "${gitAndTools.git}/bin/git";
|
|
|
|
ls = "${exa}/bin/exa";
|
2022-07-24 19:58:03 +00:00
|
|
|
ll = "ls -l --time-style long-iso --icons";
|
|
|
|
la = "ll -a";
|
|
|
|
http = "${xh}/bin/xh";
|
|
|
|
https = "${xh}/bin/xhs";
|
|
|
|
top = "${bottom}/bin/btm";
|
|
|
|
htop = "${bottom}/bin/btm";
|
2022-01-23 23:50:34 +00:00
|
|
|
tb = "toggle-background";
|
2022-09-15 21:17:21 +00:00
|
|
|
} // lib.optionalAttrs 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 23:50:34 +00:00
|
|
|
};
|
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-08-31 04:48:48 +00:00
|
|
|
set -g fish_greeting "(づ ̄ ³ ̄)づ hello (づ ̄ ³ ̄)づ"
|
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
|
2022-05-08 01:43:56 +00:00
|
|
|
# Set Fish colors that aren't dependent the `$term_background`.
|
2022-07-17 16:37:52 +00:00
|
|
|
init-shell-colors
|
2022-01-23 01:32:58 +00:00
|
|
|
'';
|
|
|
|
# }}}
|
|
|
|
}
|