commit 65b13a69ea13400b093f5d4d33b232dd10c97761
parent 5d4a8f638721f0e1e41216ac4bdc041df86ed336
Author: Vincent Demeester <vincent@sbr.pm>
Date: Sat, 6 Jul 2019 12:30:46 +0200
profiles.zsh: use our own simple prompt
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Diffstat:
2 files changed, 106 insertions(+), 29 deletions(-)
diff --git a/modules/profiles/assets/zsh/prompt.zsh b/modules/profiles/assets/zsh/prompt.zsh
@@ -0,0 +1,92 @@
+setopt prompt_subst
+
+autoload colors; colors;
+autoload vcs_info
+
+function user_hostname() {
+ if [[ "$USER" = "root" || -n "$SSH_TTY" ]]; then
+ echo "%n@%m "
+ fi
+}
+
+function prompt_bg_job() {
+ jobs | grep '+' | awk '{print $4 " "}'
+}
+
+function git_stash() {
+ git stash list 2> /dev/null | wc -l | sed -e "s/ *\([0-9]*\)/\+\1 /g" | sed -e "s/+0 //"
+}
+
+function prompt_pwd() {
+ if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
+ local homerepo=${$(git rev-parse --show-toplevel)/#${HOME}/\~}
+ local repopartslen=${#${(s:/:)${homerepo}}}
+ fi
+
+ parts=(${(s:/:)${${PWD}/#${HOME}/\~}})
+
+ i=0
+ while (( i++ < ${#parts} )); do
+ part="$parts[i]"
+ if [[ $i == ${repopartslen} ]]; then
+ parts[i]="%U$part%u"
+ elif [[ $i != ${#parts} ]]; then
+ if [[ $part[1,1] == "." ]]; then
+ parts[i]="$part[1,2]"
+ else
+ parts[i]="$part[1,1]"
+ fi
+ fi
+ done
+
+ local prompt_path="${(j:/:)parts}"
+ if [ "$parts[1]" != "~" ]; then
+ prompt_path="/$prompt_path"
+ fi
+ echo "$prompt_path "
+}
+
+local git_formats="± %b%c%u:%.7i"
+
+zstyle ':vcs_info:git*' enable git
+zstyle ':vcs_info:git*' check-for-changes true
+zstyle ':vcs_info:git*' get-revision true
+zstyle ':vcs_info:git*' stagedstr "+"
+zstyle ':vcs_info:git*' unstagedstr "*"
+zstyle ':vcs_info:git*' formats "$git_formats"
+zstyle ':vcs_info:git*' actionformats "%a $git_formats"
+
+function precmd() {
+ vcs_info
+}
+
+function git_prompt_info() {
+ local info="${vcs_info_msg_0_}"
+ if [[ -n "$info" ]]; then
+ echo "$info "
+ fi
+}
+
+function aws_vault() {
+ [[ -n "$AWS_VAULT" ]] && echo "$AWS_VAULT "
+}
+
+function zle-keymap-select() {
+ zle reset-prompt
+}
+zle -N zle-keymap-select
+
+local char="λ "
+
+local cwd='%{${fg_bold[green]}%}$(prompt_pwd)%{${reset_color}%}'
+local usr='%{${fg[yellow]}%}$(user_hostname)%{${reset_color}%}'
+local colored_char='%(?,%F{cyan}$char,%F{red}$char)%f'
+local usr='%{${fg[yellow]}%}$(user_hostname)%{${reset_color}%}'
+local git='%{${fg_bold[yellow]}%}$(git_prompt_info)%{${reset_color}%}'
+local git_stashes='$(git_stash)'
+local bg_job='%{${fg_bold[black]}%}$(prompt_bg_job)%{${reset_color}%}'
+local aws='%{${fg_bold[black]}%}$(aws_vault)%{${reset_color}%}'
+
+PROMPT="$cwd$usr$bg_job$git_author$git$git_stashes$aws$colored_char"
+PROMPT2=$colored_char
+RPROMPT2='[%_]'
diff --git a/modules/profiles/zsh.nix b/modules/profiles/zsh.nix
@@ -19,7 +19,8 @@ in
home.packages = with pkgs; [
zsh-syntax-highlighting
];
- home.file.".config/zsh/functions/j".source = ./assets/zsh/j;
+ home.file."${config.programs.zsh.dotDir}/prompt.zsh".source = ./assets/zsh/prompt.zsh;
+ home.file."${config.programs.zsh.dotDir}/functions/j".source = ./assets/zsh/j;
programs.zsh = {
enable = true;
dotDir = ".config/zsh";
@@ -67,12 +68,12 @@ in
};
}
{
- name = "pure";
+ name = "zsh-completions";
src = pkgs.fetchFromGitHub {
- owner = "sindresorhus";
- repo = "pure";
- rev = "v1.10.3";
- sha256 = "0zjgnlw01ri0brx108n6miw4y0cxd6al1bh28m8v8ygshm94p1zx";
+ owner = "zsh-users";
+ repo = "zsh-completions";
+ rev = "cf565254e26bb7ce03f51889e9a29953b955b1fb";
+ sha256 = "1yf4rz99acdsiy0y1v3bm65xvs2m0sl92ysz0rnnrlbd5amn283l";
};
}
];
@@ -83,17 +84,6 @@ in
path+="$HOME/${config.programs.zsh.dotDir}/functions"
fpath+="$HOME/${config.programs.zsh.dotDir}/functions"
for func ($HOME/${config.programs.zsh.dotDir}/functions) autoload -U $func/*(x:t)
- IS_SERIAL=0
- case $TTY in
- /dev/ttyS[0-9]*|/dev/ttyUSB[0-9]*)
- IS_SERIAL=1
- ;;
- esac
- IS_CHROOT=0
- if [[ $UID == 0 ]] && [[ $(stat -c %d:%i /) != $(stat -c %d:%i /proc/1/root/.) ]]; then
- IS_CHROOT=1
- fi
- PURE_PROMPT='λ'
autoload -Uz select-word-style; select-word-style bash
if [ -e /home/vincent/.nix-profile/etc/profile.d/nix.sh ]; then . /home/vincent/.nix-profile/etc/profile.d/nix.sh; fi
# make sure navigation using emacs keybindings works on all non-alphanumerics
@@ -102,19 +92,14 @@ in
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('rm -fR *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('rm -fr *' 'fg=white,bold,bg=red')
- # prompt
- PURE_CMD_MAX_EXEC_TIME=10
- zstyle :prompt:pure:path color white
- PURE_PROMPT_SYMBOL='λ'
- if (( IS_CHROOT )); then
- PURE_PROMPT_SYMBOL='(chroot) λ'
- fi
- if (( IS_SERIAL )); then
- # Serial can't handle beautiful symbols or setting the title ;).
- PURE_PROMPT_SYMBOL='>'
- prompt_pure_set_title() {}
- fi
zstyle ':completion:*' menu select
+ compinit
+ source $HOME/${config.programs.zsh.dotDir}/prompt.zsh
+ if [ -n "$INSIDE_EMACS" ]; then
+ chpwd() { print -P "\033AnSiTc %d" }
+ print -P "\033AnSiTu %n"
+ print -P "\033AnSiTc %d"
+ fi
'';
profileExtra = ''
if [ -e /home/vincent/.nix-profile/etc/profile.d/nix.sh ]; then . /home/vincent/.nix-profile/etc/profile.d/nix.sh; fi