From 8820d5edc4f7bace4a897cbee4c04bdc114d3a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sun, 5 Nov 2023 21:37:36 +0100 Subject: [PATCH] nix: Add powerline-go for zsh --- config/nix/hm/common.nix | 21 ++++++++++++ config/shell/commonrc | 1 - config/shell/zshrc | 72 ---------------------------------------- 3 files changed, 21 insertions(+), 73 deletions(-) diff --git a/config/nix/hm/common.nix b/config/nix/hm/common.nix index e1de2bd..5d54b07 100644 --- a/config/nix/hm/common.nix +++ b/config/nix/hm/common.nix @@ -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; diff --git a/config/shell/commonrc b/config/shell/commonrc index a0bf99e..15331c9 100644 --- a/config/shell/commonrc +++ b/config/shell/commonrc @@ -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}" diff --git a/config/shell/zshrc b/config/shell/zshrc index cc92c3b..96c7e31 100644 --- a/config/shell/zshrc +++ b/config/shell/zshrc @@ -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