From 7f4ec84c491b6f5b554135537b76aa7d2c37b1cd Mon Sep 17 00:00:00 2001 From: winston Date: Tue, 16 May 2023 16:20:11 +0200 Subject: [PATCH] feat(zsh): use atuin, better xdg, lint zsh --- home/apps/kubernetes.nix | 4 +- home/apps/wezterm.nix | 2 +- home/apps/zsh.nix | 52 ++++++++++++---------- home/apps/zsh/functions/{icat.zsh => icat} | 5 ++- home/apps/zsh/functions/incognito | 12 +++++ home/xdg.nix | 50 ++++++++++----------- 6 files changed, 70 insertions(+), 55 deletions(-) rename home/apps/zsh/functions/{icat.zsh => icat} (93%) create mode 100644 home/apps/zsh/functions/incognito diff --git a/home/apps/kubernetes.nix b/home/apps/kubernetes.nix index 0b07abb..fea5c88 100644 --- a/home/apps/kubernetes.nix +++ b/home/apps/kubernetes.nix @@ -36,8 +36,8 @@ # konf source <(konf-go shellwrapper zsh) source <(konf-go completion zsh) - # open last konf on new shell session, only if konf store has been initialized - [[ -d ~/.kube/konfs/store ]] && export KUBECONFIG=$(konf-go --silent set -) + # ignore if konf store hasn't been initialized + export KUBECONFIG=$(konf-go --silent set - || true) ''; }; diff --git a/home/apps/wezterm.nix b/home/apps/wezterm.nix index 1ceaecd..d071b9e 100644 --- a/home/apps/wezterm.nix +++ b/home/apps/wezterm.nix @@ -6,7 +6,7 @@ }: { programs.wezterm = { enable = true; - package = pkgs.nur.repos.nekowinston.wezterm-nightly; + # package = pkgs.nur.repos.nekowinston.wezterm-nightly; extraConfig = '' package.path = "${flakePath}/home/apps/wezterm/?.lua;" .. package.path; return require("config") diff --git a/home/apps/zsh.nix b/home/apps/zsh.nix index cd33b61..2a807ee 100644 --- a/home/apps/zsh.nix +++ b/home/apps/zsh.nix @@ -9,8 +9,21 @@ source = config.lib.file.mkOutOfStoreSymlink "${flakePath}/${fileName}"; recursive = recursive; }; + zshPlugins = plugins: (map (plugin: rec { + name = src.name; + inherit (plugin) file src; + }) + plugins); in { programs = { + atuin = { + enable = true; + flags = ["--disable-up-arrow"]; + settings = { + inline_height = 30; + style = "compact"; + }; + }; bat.enable = true; btop = { enable = true; @@ -38,7 +51,6 @@ in { enableAliases = true; }; - mcfly.enable = true; nix-index.enable = true; starship = { @@ -71,16 +83,15 @@ in { initExtra = let functionsDir = "${config.home.homeDirectory}/${config.programs.zsh.dotDir}/functions"; in '' - for conf in "${functionsDir}"/**/*.zsh; do - source "$conf" + for script in "${functionsDir}"/**/*; do + source "$script" done ''; - - sessionVariables = { - ZVM_INIT_MODE = "sourcing"; - ZVM_CURSOR_BLINKING_BEAM = "1"; - LESSHISTFILE = "-"; - }; + envExtra = '' + export LESSHISTFILE="-" + export ZVM_INIT_MODE="sourcing" + export ZVM_CURSOR_BLINKING_BEAM="1" + ''; dotDir = ".config/zsh"; oh-my-zsh = { @@ -94,35 +105,30 @@ in { "kubectl" ]; }; - plugins = [ + plugins = with pkgs; (zshPlugins [ { - name = "zsh-fast-syntax-highlighting"; - src = pkgs.zsh-fast-syntax-highlighting; - file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh"; + src = zsh-vi-mode; + file = "share/zsh-vi-mode/zsh-vi-mode.plugin.zsh"; } { - name = "zsh-nix-shell"; - src = pkgs.zsh-nix-shell; + src = zsh-nix-shell; file = "share/zsh-nix-shell/nix-shell.plugin.zsh"; } { - name = "zsh-vi-mode"; - src = pkgs.zsh-vi-mode; - file = "share/zsh-vi-mode/zsh-vi-mode.plugin.zsh"; + src = zsh-fast-syntax-highlighting; + file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh"; } - ]; + ]); shellAliases = { cat = if isDarwin then "bat --theme=\$(defaults read -globalDomain AppleInterfaceStyle &> /dev/null && echo Catppuccin-mocha || echo Catppuccin-latte)" else "bat"; # switch between yubikeys for the same GPG key - switch_yubikeys = "gpg-connect-agent \"scd serialno\" \"learn --force\" /bye"; + switch_yubikeys = ''gpg-connect-agent "scd serialno" "learn --force" "/bye"''; tree = "lsd --tree"; }; - history = { - path = "${config.xdg.configHome}/zsh/history"; - }; + history.path = "${config.xdg.configHome}/zsh/history"; }; }; diff --git a/home/apps/zsh/functions/icat.zsh b/home/apps/zsh/functions/icat similarity index 93% rename from home/apps/zsh/functions/icat.zsh rename to home/apps/zsh/functions/icat index 4ecb6ef..c8ebb46 100644 --- a/home/apps/zsh/functions/icat.zsh +++ b/home/apps/zsh/functions/icat @@ -1,3 +1,4 @@ +# vim:ft=zsh local MAPPINGS=' video/3gpp,3gp video/3gpp2,3g2 @@ -35,8 +36,8 @@ function icat() { } if [ ! -t 0 ]; then - input="$(cat - | base64)" - headers="$(echo "$input" | base64 -d | file - --mime-type | cut -d " " -f2-)" + local input="$(cat - | base64)" + local headers="$(echo "$input" | base64 -d | file - --mime-type | cut -d " " -f2-)" case $headers in *svg*) echo "$input" | base64 -d | displaySVG ;; diff --git a/home/apps/zsh/functions/incognito b/home/apps/zsh/functions/incognito new file mode 100644 index 0000000..5b243cc --- /dev/null +++ b/home/apps/zsh/functions/incognito @@ -0,0 +1,12 @@ +# vim:ft=zsh +function incognito() { + if [[ -n $ZSH_INCOGNITO ]]; then + add-zsh-hook precmd _atuin_precmd + add-zsh-hook preexec _atuin_preexec + unset ZSH_INCOGNITO + else + add-zsh-hook -d precmd _atuin_precmd + add-zsh-hook -d preexec _atuin_preexec + export ZSH_INCOGNITO=1 + fi +} diff --git a/home/xdg.nix b/home/xdg.nix index 815ebb8..fe26d46 100644 --- a/home/xdg.nix +++ b/home/xdg.nix @@ -6,50 +6,46 @@ ... }: let inherit (pkgs.stdenv.hostPlatform) isDarwin isLinux; + inherit (config.xdg) cacheHome configHome dataHome; + inherit (config.home) homeDirectory; in { - home = { + home = rec { sessionVariables = { - AZURE_CONFIG_DIR = "${config.xdg.configHome}/azure"; - CARGO_HOME = "${config.xdg.dataHome}/cargo"; + AZURE_CONFIG_DIR = "${configHome}/azure"; + CARGO_HOME = "${dataHome}/cargo"; CARGO_REGISTRIES_CRATES_IO_PROTOCOL = "sparse"; CARGO_UNSTABLE_SPARSE_REGISTRY = "true"; - CUDA_CACHE_PATH = "${config.xdg.dataHome}/nv"; - DOCKER_CONFIG = "${config.xdg.configHome}/docker"; - GEM_HOME = "${config.xdg.dataHome}/gem"; - GEM_SPEC_CACHE = "${config.xdg.cacheHome}/gem"; - GOPATH = "${config.xdg.dataHome}/go"; - NPM_CONFIG_USERCONFIG = "${config.xdg.configHome}/npm/npmrc"; - RUSTUP_HOME = "${config.xdg.dataHome}/rustup"; - XCOMPOSECACHE = "${config.xdg.cacheHome}/X11/xcompose"; + CUDA_CACHE_PATH = "${dataHome}/nv"; + DOCKER_CONFIG = "${configHome}/docker"; + GEM_HOME = "${dataHome}/gem"; + GEM_SPEC_CACHE = "${cacheHome}/gem"; + GOPATH = "${dataHome}/go"; + NPM_CONFIG_USERCONFIG = "${configHome}/npm/npmrc"; + NODE_REPL_HISTORY = "${dataHome}/node_repl_history"; + RUSTUP_HOME = "${dataHome}/rustup"; + WINEPREFIX = "${dataHome}/wine"; + XCOMPOSECACHE = "${cacheHome}/X11/xcompose"; }; sessionPath = [ "$HOME/.local/bin" - "${config.xdg.dataHome}/krew/bin" - "${config.home.sessionVariables.GOPATH}/bin" - "${config.home.sessionVariables.CARGO_HOME}/bin" + "${dataHome}/krew/bin" + "${sessionVariables.GOPATH}/bin" + "${sessionVariables.CARGO_HOME}/bin" ]; }; - home.activation.npmrc_xdg = '' - export NPM_CONFIG_USERCONFIG="${config.home.sessionVariables.NPM_CONFIG_USERCONFIG}" - ${pkgs.nodejs + "/bin/npm"} config set \ - prefix="${config.xdg.dataHome}/npm" \ - cache="${config.xdg.cacheHome}/npm" \ - init-module="${config.xdg.configHome}/npm/config/npm-init.js" - ''; - # NOTE: workaround for gpgme on Darwin, since GUI apps aren't aware of $GNUPGHOME programs.gpg.homedir = if isDarwin - then "${config.home.homeDirectory}/.gnupg" - else "${config.xdg.configHome}/gnupg"; + then "${homeDirectory}/.gnupg" + else "${configHome}/gnupg"; xdg = { enable = true; userDirs.enable = isLinux; - cacheHome = "${config.home.homeDirectory}/.cache"; - configHome = "${config.home.homeDirectory}/.config"; - dataHome = "${config.home.homeDirectory}/.local/share"; + cacheHome = "${homeDirectory}/.cache"; + configHome = "${homeDirectory}/.config"; + dataHome = "${homeDirectory}/.local/share"; mimeApps = { enable = isLinux; defaultApplications = {