121 lines
3.1 KiB
Nix
Raw Normal View History

2024-04-20 09:42:06 -04:00
{
config,
lib,
...
}:
2025-01-20 22:35:40 -05:00
let
cfg = config.nmasur.presets.programs.fish;
in
{
2022-04-28 21:56:21 -04:00
2025-02-02 21:45:34 -05:00
options.nmasur.presets.programs.fish = {
enable = lib.mkEnableOption "Fish shell";
fish_user_key_bindings = lib.mkOption {
type = lib.types.lines;
description = "Text of fish_user_key_bindings function";
default = "";
};
};
2022-04-30 11:08:16 -04:00
2025-01-20 22:35:40 -05:00
config = lib.mkIf cfg.enable {
2022-04-30 11:08:16 -04:00
2025-02-02 21:45:34 -05:00
cfg.fish_user_key_bindings = # fish
''
# Shift-Enter (defined by terminal)
bind -M insert \x1F accept-autosuggestion
bind -M default \x1F accept-autosuggestion
'';
programs.fish = {
enable = true;
2022-04-30 10:21:43 -04:00
functions = {
copy = {
description = "Copy file contents into clipboard";
body = "cat $argv | pbcopy"; # Need to fix for non-macOS
};
envs = {
description = "Evaluate a bash-like environment variables file";
body = ''set -gx (cat $argv | tr "=" " " | string split ' ')'';
};
fish_user_key_bindings = {
2022-05-06 09:44:21 -04:00
body = builtins.readFile ./functions/fish_user_key_bindings.fish;
2022-04-30 10:21:43 -04:00
};
2024-04-20 09:42:06 -04:00
ip = {
body = builtins.readFile ./functions/ip.fish;
};
2022-04-30 10:21:43 -04:00
json = {
description = "Tidy up JSON using jq";
body = "pbpaste | jq '.' | pbcopy"; # Need to fix for non-macOS
};
2024-09-25 16:43:48 -04:00
_which = {
description = "Identify the path to a program in the shell";
body = "command --search (string sub --start=2 $argv)";
};
2022-04-30 10:21:43 -04:00
};
2022-04-30 11:08:16 -04:00
interactiveShellInit = ''
2022-06-19 09:34:17 -04:00
fish_vi_key_bindings
2022-04-30 11:08:16 -04:00
bind yy fish_clipboard_copy
bind Y fish_clipboard_copy
bind -M visual y fish_clipboard_copy
2022-06-18 15:45:51 -04:00
bind -M default p fish_clipboard_paste
2022-04-30 11:08:16 -04:00
set -g fish_vi_force_cursor
set -g fish_cursor_default block
set -g fish_cursor_insert line
set -g fish_cursor_visual block
set -g fish_cursor_replace_one underscore
'';
loginShellInit = "";
shellAbbrs = {
# Directory aliases
2022-05-06 08:58:44 -04:00
l = "ls -lh";
lh = "ls -lh";
ll = "ls -alhF";
la = "ls -a";
c = "cd";
"-" = "cd -";
mkd = "mkdir -pv";
2024-09-25 16:43:48 -04:00
# Convert a program into its full path
"=" = {
position = "anywhere";
regex = "=\\w+";
function = "_which";
};
# System
s = "sudo";
sc = "systemctl";
scs = "systemctl status";
2024-08-18 19:35:30 -04:00
sca = "systemctl cat";
2022-05-06 09:29:25 -04:00
m = "make";
2023-03-05 23:04:06 -05:00
t = "trash";
2022-05-29 13:44:45 -04:00
# Vim (overwritten by Neovim)
v = "vim";
vl = "vim -c 'normal! `0'";
# Notes
sn = "syncnotes";
# Cheat Sheets
2024-04-20 09:42:06 -04:00
ssl = "openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr";
fingerprint = "ssh-keyscan myhost.com | ssh-keygen -lf -";
publickey = "ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub";
forloop = "for i in (seq 1 100)";
# Docker
dc = "$DOTS/bin/docker_cleanup";
dr = "docker run --rm -it";
db = "docker build . -t";
};
shellInit = "";
2022-04-28 18:55:15 -04:00
};
2022-05-06 09:29:25 -04:00
home.sessionVariables.fish_greeting = "";
2022-04-28 19:11:33 -04:00
};
2022-04-28 18:55:15 -04:00
}