nix/home-manager/common/software/cli/fish.nix
2024-05-06 12:01:37 +09:00

202 lines
6.4 KiB
Nix

{ ... }: {
programs.kitty.shellIntegration.enableFishIntegration = true;
programs.starship.enableFishIntegration = true;
programs.fish = {
enable = true;
shellInit = ''
set fish_greeting
set EDITOR vim
eval (ssh-agent -c) > /dev/null &> /dev/null
ssh-add > /dev/null &> /dev/null
'';
loginShellInit = ''ssh-add > /dev/null &> /dev/null'';
interactiveShellInit = ''
if not set -q TMUX && not set -q DISABLE_TMUX
if tmux has-session -t Main
exec tmux attach-session -t Main
exit
else
exec tmux new-session -t Main
end
end
'';
functions = {
__fish_command_not_found_handler = {
body = "__fish_default_command_not_found_handler $argv[1]";
onEvent = "fish_command_not_found";
};
# GPG related functions
encrypt = ''
set output $argv-$(ddate).enc
gpg --encrypt --armor --output $output -r $PGP_KEY_ID "$argv" && echo "Encrypted: $argv -> $output"
'';
decrypt = ''
set output $(echo $argv | rev | cut -c16- | rev)
gpg --decrypt --output $output && echo "Decrypted: $argv -> $output"
'';
update_secrets = ''
pushd /etc/nixos/git
nix develop -c \
find secrets -name "*.yaml" -exec sops updatekeys {} \;
'';
restart-docker = ''
pushd /Storage/Data/docker-compose/sysctl.io/
docker stop $argv
docker rm $argv
git pull
docker compose up -d $argv
popd
'';
# Build ISOs/SD Card Images
nixos-build-all-images = ''
echo "Building Linode image..."
nixos-build-linode-img $argv
echo "Building Raspberry Pi image..."
nixos-build-pi-img $argv
echo "Building ISO Console image..."
nixos-build-console $argv
echo "Building ISO Desktop image..."
nixos-build-desktop $argv
ls -lah ~/ | grep nixos
'';
nixos-build-pi-img-verbose = ''
pushd /etc/nixos/git
git pull
nix build .#imageConfigurations.nixos-rpi4-img --show-trace --verbose
cp result/sd-image/nixos-sd-image* ~/.
rm -f result
popd
'';
nixos-build-linode-img-verbose = ''
pushd /etc/nixos/git
git pull
nix build .#imageConfigurations.nixos-linode-img --show-trace --verbose
cp result/nixos.img.gz ~/nixos-linode-`ddate`-`git rev-parse HEAD | cut -b 1-7`.img.gz
rm -f result
popd
'';
nixos-build-console-verbose = ''
pushd /etc/nixos/git
git pull
nix build .#imageConfigurations.nixos-iso-console --show-trace --verbose
cp result/iso/nixos.iso ~/nixos-console-`ddate`-`git rev-parse HEAD | cut -b 1-7`.iso
rm -f result
popd
'';
nixos-build-desktop-verbose = ''
pushd /etc/nixos/git
git pull
nix build .#imageConfigurations.nixos-iso-desktop --show-trace --verbose
cp result/iso/nixos.iso ~/nixos-desktop-`ddate`-`git rev-parse HEAD | cut -b 1-7`.iso
rm -f result
popd
'';
nixos-build-pi-img = ''
pushd /etc/nixos/git
git pull
nix build .#imageConfigurations.nixos-rpi4-img
cp result/sd-image/nixos-sd-image* ~/.
rm -f result
popd
'';
nixos-build-linode-img = ''
pushd /etc/nixos/git
git pull
nix build .#imageConfigurations.nixos-linode-img
cp result/nixos.img.gz ~/nixos-linode-`ddate`-`git rev-parse HEAD | cut -b 1-7`.img.gz
rm -f result
popd
'';
nixos-build-console = ''
pushd /etc/nixos/git
git pull
nix build .#imageConfigurations.nixos-iso-console
cp result/iso/nixos.iso ~/nixos-console-`ddate`-`git rev-parse HEAD | cut -b 1-7`.iso
rm -f result
popd
'';
nixos-build-desktop = ''
pushd /etc/nixos/git
git pull
nix build .#imageConfigurations.nixos-iso-desktop
cp result/iso/nixos.iso ~/nixos-desktop-`ddate`-`git rev-parse HEAD | cut -b 1-7`.iso
rm -f result
popd
'';
# NixOS Related
nix-clean-all = ''
echo "Optimizing the nix store..."
sudo nix-store --optimize
echo "nix-store: Collecting Garbage..."
sudo nix-store --gc
echo "Collecting garbage..."
sudo nix-collect-garbage -d
'';
};
shellAliases = {
# GPG Related
sign = "gpg --armor --clearsign";
verify = "gpg --verify";
prime-select = "nvidia-offload";
screenshot = ''grim -g "$(slurp)" | wl-copy -t image/png'';
# Don't use X to open emacs
emacs = "emacs -nw";
# docker
d = "docker";
dc = "docker compose";
de = "docker exec -it";
dl = "docker logs -f ";
dps = ''docker ps --format "table [{{.ID}}] {{.Names}}\t{{.Status}}\t{{.State}}\t{{.Label \"type\"}}"'';
# fish / system
ls = "exa --icons -F --group-directories-first --git";
cp = "rsync -avr";
ll = "exa -lah --icons -F --group-directories-first --git";
rm = "rm -i";
df = "duf";
cat = "bat";
# git
g = "git";
ga = "git add -A";
gb = "git branch";
gc = "git commit";
gca = "git commit -a";
gco = "git checkout";
gd = "git diff";
gp = "git pull --prune";
gpu = "git push origin HEAD";
gs = "git status -sb";
# time / date
tdate = "date +%Y.%m.%d..%H.%M";
ttime = "date +%H.%M";
ddate = "date +%Y.%m.%d";
dday = "date +%A";
# nixos-rebuild
nr = "sudo nixos-rebuild";
nrs = "sudo nixos-rebuild --upgrade switch";
nrt = "sudo nixos-rebuild test";
nrb = "sudo nixos-rebuild build";
# Rebuild everything
rebuild-home = "git -C /etc/nixos/git pull && home-manager switch -b backup --flake /etc/nixos/git";
rebuild-host = "git -C /etc/nixos/git pull && sudo nixos-rebuild switch --flake /etc/nixos/git";
rebuild-all = "rebuild-host && rebuild-home";
rebuild-host-remote = "git -C /etc/nixos/git pull && sudo nixos-rebuild switch --flake /etc/nixos/git -j0";
rebuild-home-remote = "git -C /etc/nixos/git pull && home-manager switch -b backup --flake /etc/nixos/git --max-jobs 0";
rebuild-all-remote = "rebuild-host-remote && rebuild-home-remote";
};
};
}