nix: Add powerline-go for zsh

This commit is contained in:
Geoffrey Frogeye 2023-11-05 21:37:36 +01:00
parent 6d9d2078a6
commit 8820d5edc4
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
3 changed files with 21 additions and 73 deletions

View file

@ -10,6 +10,27 @@
enableCompletion = true;
enableSyntaxHighlighting = true;
# syntaxHighlighting.enable = true; # 23.11 syntax
historySubstringSearch.enable = true;
initExtra = ''
# powerline-go duration support
zmodload zsh/datetime
function preexec() {
__TIMER=$EPOCHREALTIME
}
'';
};
powerline-go = {
enable = true;
modules = [ "user" "host" "venv" "cwd" "perms" "git" ];
modulesRight = [ "jobs" "exit" "duration" "load" ];
settings = {
colorize-hostname = true;
max-width = 25;
cwd-max-dir-size = 10;
duration = "$( test -n \"$__TIMER\" && echo $(( $EPOCHREALTIME - $\{__TIMER:-EPOCHREALTIME})) || echo 0 )";
# UPST Implement this properly in home-manager
};
extraUpdatePS1 = ''unset __TIMER'';
};
# neovim = {
# enable = true;

View file

@ -23,7 +23,6 @@ alias dmesg='dmesg --ctime'
alias wget='wget --hsts-file $HOME/.cache/wget-hsts'
# [ -f ~/.local/bin/colorSchemeApplyFzf ] && . ~/.local/bin/colorSchemeApplyFzf # Only applies RGB colors...
POWERLINE_GO_DEFAULT_OPTS=(-colorize-hostname -max-width 25 -cwd-max-dir-size 10 -modules 'user,host,venv,cwd,perms,git' -modules-right 'jobs,exit,duration,load') # For reading by shell profiles
FZF_DEFAULT_OPTS="--height 40% --layout=default"
FZF_CTRL_T_OPTS="--preview '[[ -d {} ]] && ls -l --color=always {} || [[ \$(file --mime {}) =~ binary ]] && file --brief {} || (highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null | head -500'"
FZF_COMPLETION_OPTS="${FZF_CTRL_T_OPTS}"

View file

@ -5,79 +5,7 @@
#
# TODO Learn `setopt extendedglob`
# TODO Add asdf (oh-my-zsh plugin is air, git clone is the way (aur package outdated))
# Approximate RGB colors by terminal colors
[[ "$COLORTERM" == (24bit|truecolor) || "${terminfo[colors]}" -eq '16777216' ]] || zmodload zsh/nearcolor
# Plugins
ADOTDIR=~/.cache/antigen
mkdir -p $ADOTDIR
typeset -a ANTIGEN_CHECK_FILES=(~/.config/shell/zshrc)
if [ -f /usr/share/zsh/share/antigen.zsh ]
then
source /usr/share/zsh/share/antigen.zsh
else
[ -f ~/.local/share/zsh/antigen.zsh ] || (mkdir -p ~/.local/share/zsh/ && curl -L git.io/antigen > ~/.local/share/zsh/antigen.zsh)
# TODO If the downloaded file is wrong then we're doomed
source ~/.local/share/zsh/antigen.zsh
fi
# This is better to have them installed as system since we can use them as root
# pacman -S zsh-autosuggestions zsh-history-substring-search zsh-syntax-highlighting zsh-completions --needed
function plugin() {
if [ -d "/usr/share/licenses/$2" ]
then
trysource "/usr/share/zsh/plugins/$2/$2.zsh"
# It's ok if it fails
else
antigen bundle "$1/$2"
fi
}
plugin zsh-users zsh-completions
plugin zsh-users zsh-syntax-highlighting
plugin zsh-users zsh-autosuggestions
plugin zsh-users zsh-history-substring-search
antigen apply
# Prompt customization
zmodload zsh/datetime
function preexec() {
__TIMER=$EPOCHREALTIME
}
if command -v powerline-go > /dev/null
then
function powerline_precmd() {
local __ERRCODE=$?
local __DURATION=0
if [ -n $__TIMER ]; then
local __ERT=$EPOCHREALTIME
__DURATION="$(($__ERT - ${__TIMER:-__ERT}))"
fi
echo -en "\033]0; ${USER}@${HOST} $PWD\007"
# echo -en "… $\r"
eval "$(powerline-go -shell zsh -eval -duration $__DURATION -error $__ERRCODE "${POWERLINE_GO_DEFAULT_OPTS[@]}")"
unset __TIMER
}
function install_powerline_precmd() {
for s in "${precmd_functions[@]}"; do
if [ "$s" = "powerline_precmd" ]; then
return
fi
done
precmd_functions+=(powerline_precmd)
}
install_powerline_precmd
else
export PS1="\[\e]2;\u@\H \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] "
fi
# Cursor based on mode
if [ $TERM = "linux" ]; then