From 55af25ccb32bb63d51e0f3fe799c726d7026b059 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 10 Jul 2024 13:06:26 +0200 Subject: [PATCH] refactor: extract zsh config --- horsch/home.nix | 1 + horsch/zsh.nix | 97 ++++++++++++++++---------------------- private/home.nix | 2 +- private/zsh.nix => zsh.nix | 10 ++-- 4 files changed, 47 insertions(+), 63 deletions(-) rename private/zsh.nix => zsh.nix (78%) diff --git a/horsch/home.nix b/horsch/home.nix index 535176f..e51921f 100644 --- a/horsch/home.nix +++ b/horsch/home.nix @@ -34,6 +34,7 @@ ../starship.nix ../tree.nix ../zoxide.nix + ../zsh.nix ./ssh.nix ./zsh.nix ]; diff --git a/horsch/zsh.nix b/horsch/zsh.nix index 5588dff..d3919cc 100644 --- a/horsch/zsh.nix +++ b/horsch/zsh.nix @@ -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." + } + ''; } diff --git a/private/home.nix b/private/home.nix index 700d018..bf61c77 100644 --- a/private/home.nix +++ b/private/home.nix @@ -71,6 +71,6 @@ ../sway ../tree.nix ../zoxide.nix - ./zsh.nix + ../zsh.nix ]; } diff --git a/private/zsh.nix b/zsh.nix similarity index 78% rename from private/zsh.nix rename to zsh.nix index e95a159..f451771 100644 --- a/private/zsh.nix +++ b/zsh.nix @@ -13,6 +13,10 @@ in highlight = zsh_autosuggest_highlight_style; }; + syntaxHighlighting = { + enable = true; + }; + initExtra = '' function set_win_title(){ local TITLE=$(git config --get remote.origin.url || echo "$PWD") @@ -21,11 +25,5 @@ in precmd_functions+=(set_win_title) ''; - - shellAliases = { - ls = "eza --group-directories-first --git"; - neovide = "neovide --multigrid"; - xclip = "xclip -selection clipboard"; - }; }; }