From 032fd3805380cd679efe65db0617405ee5db609d Mon Sep 17 00:00:00 2001 From: caem Date: Mon, 15 Jul 2024 01:25:14 +0200 Subject: [PATCH] zsh: Make nix-shell pretty and update ps1 --- users/hu/packages/zsh/config/conf.d/alias.zsh | 4 ++++ .../hu/packages/zsh/config/conf.d/completions.zsh | 6 +++--- users/hu/packages/zsh/config/conf.d/nix.zsh | 7 +++++++ users/hu/packages/zsh/config/conf.d/ps1.zsh | 15 +++++++++++++-- .../hu/packages/zsh/config/conf.d/suggestions.zsh | 4 ++-- users/hu/packages/zsh/config/conf.d/syntax.zsh | 4 ++-- users/hu/packages/zsh/zsh-home.nix | 13 ++++++++----- 7 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 users/hu/packages/zsh/config/conf.d/nix.zsh diff --git a/users/hu/packages/zsh/config/conf.d/alias.zsh b/users/hu/packages/zsh/config/conf.d/alias.zsh index f964c9e..5079bde 100644 --- a/users/hu/packages/zsh/config/conf.d/alias.zsh +++ b/users/hu/packages/zsh/config/conf.d/alias.zsh @@ -2,3 +2,7 @@ alias reload="exec zsh" +if [ -x "$(command -v nix)" ]; then + alias nix-develop="nix develop -c $SHELL" +fi + diff --git a/users/hu/packages/zsh/config/conf.d/completions.zsh b/users/hu/packages/zsh/config/conf.d/completions.zsh index 1afdd64..a367270 100755 --- a/users/hu/packages/zsh/config/conf.d/completions.zsh +++ b/users/hu/packages/zsh/config/conf.d/completions.zsh @@ -1,17 +1,17 @@ #!/usr/bin/env zsh -if [ -z "$FZF_TAB_FILE" ]; then +if [ -z "$FZF_TAB_PLUGIN" ]; then if [ ! -d "$HOME/.cache/fzf-tab" ]; then echo "Installing fzf-tab" git clone "https://github.com/Aloxaf/fzf-tab" "$HOME/.cache/fzf-tab" fi - FZF_TAB_FILE="$HOME/.cache/fzf-tab/fzf-tab.plugin.zsh" + FZF_TAB_PLUGIN="$HOME/.cache/fzf-tab/fzf-tab.plugin.zsh" fi autoload -Uz compinit compinit -source "$FZF_TAB_FILE" +source "$FZF_TAB_PLUGIN" zstyle ':completion:*:git-checkout:*' sort false if [ -n "$TMUX" ]; then diff --git a/users/hu/packages/zsh/config/conf.d/nix.zsh b/users/hu/packages/zsh/config/conf.d/nix.zsh new file mode 100644 index 0000000..b828b58 --- /dev/null +++ b/users/hu/packages/zsh/config/conf.d/nix.zsh @@ -0,0 +1,7 @@ +#!/usr/bin/env zsh + +# Nix specific zsh configuration +if [ -x "$(command -v nix)" ]; then + source "$NIX_SHELL_PLUGIN" +fi + diff --git a/users/hu/packages/zsh/config/conf.d/ps1.zsh b/users/hu/packages/zsh/config/conf.d/ps1.zsh index c172cc5..2738ad4 100755 --- a/users/hu/packages/zsh/config/conf.d/ps1.zsh +++ b/users/hu/packages/zsh/config/conf.d/ps1.zsh @@ -9,10 +9,21 @@ case "$distro" in *) dicon="%F{yellow}[󰘧]%f" ;; esac +if [ -n "$IN_NIX_SHELL" ]; then + if [ -z "$NIX_SHELL_PACKAGES" ]; then + nix_shell_ps1="%F{red}nix-shell%f" + else + nix_shell_ps1="%F{red}{ $NIX_SHELL_PACKAGES }%f" + fi +else + nix_shell_ps1="" +fi + setopt prompt_subst autoload -Uz vcs_info precmd () { vcs_info } -zstyle ':vcs_info:*' formats ' %F{yellow}(%b)%f' +zstyle ':vcs_info:*' formats ' %F{yellow}(%b)%f ' -export PS1='$dicon %n@%m %F{green}%~%f$vcs_info_msg_0_> ' +NL=$'\n' +export PS1='%F{green}%~%f$vcs_info_msg_0_$nix_shell_ps1$NL$dicon > ' diff --git a/users/hu/packages/zsh/config/conf.d/suggestions.zsh b/users/hu/packages/zsh/config/conf.d/suggestions.zsh index f8f333e..1325a7b 100755 --- a/users/hu/packages/zsh/config/conf.d/suggestions.zsh +++ b/users/hu/packages/zsh/config/conf.d/suggestions.zsh @@ -9,10 +9,10 @@ setopt SHARE_HISTORY setopt HIST_IGNORE_SPACE setopt HIST_SAVE_NO_DUPS -if [ -z "$AUTOSUGGEST_FILE" ]; then +if [ -z "$AUTOSUGGEST_PLUGIN" ]; then import_file="/usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh" else - import_file="$AUTOSUGGEST_FILE" + import_file="$AUTOSUGGEST_PLUGIN" fi if [ ! -f "$import_file" ]; then diff --git a/users/hu/packages/zsh/config/conf.d/syntax.zsh b/users/hu/packages/zsh/config/conf.d/syntax.zsh index 421f230..752aec3 100755 --- a/users/hu/packages/zsh/config/conf.d/syntax.zsh +++ b/users/hu/packages/zsh/config/conf.d/syntax.zsh @@ -1,9 +1,9 @@ #!/usr/bin/env zsh -if [ -z "$SYNTAX_FILE" ]; then +if [ -z "$SYNTAX_PLUGIN" ]; then import_file="/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" else - import_file="$SYNTAX_FILE" + import_file="$SYNTAX_PLUGIN" fi if [ ! -f "$import_file" ]; then diff --git a/users/hu/packages/zsh/zsh-home.nix b/users/hu/packages/zsh/zsh-home.nix index 3e9a4d5..2b8dbca 100644 --- a/users/hu/packages/zsh/zsh-home.nix +++ b/users/hu/packages/zsh/zsh-home.nix @@ -3,12 +3,13 @@ { home.packages = with pkgs; [ fzf + thefuck zsh-fzf-tab zsh-completions zsh-autosuggestions zsh-syntax-highlighting nix-zsh-completions - #thefuck + zsh-nix-shell ]; home.sessionVariables = { @@ -23,19 +24,21 @@ home.file."${config.xdg.configHome}/zsh/.zshrc" = { text = '' #!/usr/bin/env zsh - SYNTAX_FILE="${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" + + SYNTAX_PLUGIN="${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" + AUTOSUGGEST_PLUGIN="${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh" + NIX_SHELL_PLUGIN="${pkgs.zsh-nix-shell}/share/zsh-nix-shell/nix-shell.plugin.zsh" # On systems that are not on glibc 2.38, loading fzf-tab will fail. This prevents that. if [ -f "/lib/x86_64-linux-gnu/libc.so.6" ]; then GLIBC_VERSION="$(/lib/x86_64-linux-gnu/libc.so.6 | head -n1 | sed -e 's/.* //g' | rev | cut -c2- | rev)" if [ "$GLIBC_VERSION" = "2.38" ]; then - FZF_TAB_FILE="${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh" + FZF_TAB_PLUGIN="${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh" fi else - FZF_TAB_FILE="${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh" + FZF_TAB_PLUGIN="${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh" fi - AUTOSUGGEST_FILE="${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh" '' + (builtins.readFile config/.zshrc); }; }