refactor: extract zsh config

This commit is contained in:
Michael Mandl 2024-07-10 13:06:26 +02:00
parent 8f1ca25dba
commit 55af25ccb3
Signed by: mandlm
GPG key ID: 088ED38F036C7AF2
4 changed files with 47 additions and 63 deletions

View file

@ -1,68 +1,53 @@
{ ... }:
{
programs.zsh = {
enable = true;
enableCompletion = true;
history.size = 10000;
programs.zsh.initExtra = ''
if [ -f $HOME/.nix-profile/etc/profile.d/nix.sh ];
then
source $HOME/.nix-profile/etc/profile.d/nix.sh
fi
autosuggestion = {
enable = true;
highlight = "fg=10";
};
function sc-log {
ssh smartcan "SYSTEMD_COLORS=true journalctl --follow --no-tail --unit smartcan-''${1:-*}"
}
syntaxHighlighting = {
enable = true;
};
function sc-restart {
ssh smartcan "systemctl restart smartcan-''${1}"
}
initExtra = ''
if [ -f $HOME/.nix-profile/etc/profile.d/nix.sh ];
then
source $HOME/.nix-profile/etc/profile.d/nix.sh
function fu-reboot {
ssh fusion "reboot"
}
function fu-flash {
local ssh_login="fusion"
local update_file=''${1}
if [ -z ''${update_file} ]; then
update_file=$(find build/tmp/deploy/images -name "*.swu" -type f | fzf --select-1)
fi
if [ -z ''${update_file} ]; then
echo "no file selected"
return 1
fi
function sc-log {
ssh smartcan "SYSTEMD_COLORS=true journalctl --follow --no-tail --unit smartcan-''${1:-*}"
}
if [ ! -f ''${update_file} ]; then
echo "file \"''${update_file}\" does not exist"
return 2
fi
function sc-restart {
ssh smartcan "systemctl restart smartcan-''${1}"
}
echo "flashing ''${update_file} to device..."
cat "''${update_file}" | ssh ''${ssh_login} "swupdate-client -"
function fu-reboot {
ssh fusion "reboot"
}
if [ $? -ne 0 ]; then
echo "update failed"
return 3
fi
function fu-flash {
local ssh_login="fusion"
local update_file=''${1}
echo "rebooting device"
ssh ''${ssh_login} reboot
if [ -z ''${update_file} ]; then
update_file=$(find build/tmp/deploy/images -name "*.swu" -type f | fzf --select-1)
fi
if [ -z ''${update_file} ]; then
echo "no file selected"
return 1
fi
if [ ! -f ''${update_file} ]; then
echo "file \"''${update_file}\" does not exist"
return 2
fi
echo "flashing ''${update_file} to device..."
cat "''${update_file}" | ssh ''${ssh_login} "swupdate-client -"
if [ $? -ne 0 ]; then
echo "update failed"
return 3
fi
echo "rebooting device"
ssh ''${ssh_login} reboot
echo "done."
}
'';
};
echo "done."
}
'';
}