1
Fork 0

zsh: Make nix-shell pretty and update ps1

This commit is contained in:
caem 2024-07-15 01:25:14 +02:00
parent 947368779d
commit 032fd38053
Signed by: caem
GPG key ID: 69A830D03203405F
7 changed files with 39 additions and 14 deletions

View file

@ -2,3 +2,7 @@
alias reload="exec zsh"
if [ -x "$(command -v nix)" ]; then
alias nix-develop="nix develop -c $SHELL"
fi

View file

@ -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

View file

@ -0,0 +1,7 @@
#!/usr/bin/env zsh
# Nix specific zsh configuration
if [ -x "$(command -v nix)" ]; then
source "$NIX_SHELL_PLUGIN"
fi

View file

@ -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 '
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 > '

View file

@ -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

View file

@ -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

View file

@ -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);
};
}