Browse Source

use git-prompt.sh in zsh

This has more features than parse_git_branch, though it could use a way
to display the _number_ of untracked / modified files (I'll have to see
if that's available).

I'm not including a copy of git-prompt.sh in the repo.  If it's not
available in the user's home directory, I mock up a function that uses
the old parse_git_branch instead.
master
Brennen Bearnes 1 year ago
parent
commit
9681878409
2 changed files with 82 additions and 49 deletions
  1. +28
    -1
      home/.sh_common
  2. +54
    -48
      home/.zshrc

+ 28
- 1
home/.sh_common View File

@ -57,6 +57,10 @@ export LESS='-FiRSX'
# Configure fzf fuzzyfinder:
export FZF_CTRL_R_OPTS='-e' # exact match by default - see fzf(1)
# For mediawiki/core/docker-compose.yml
export MW_DOCKER_UID=$(id -u)
export MW_DOCKER_GID=$(id -g)
# }}}
# Aliases, various and sundry: {{{
@ -178,8 +182,31 @@ function mcd {
mkdir -p $1 && cd $1
}
# Get some information about a git repo - useful for
# Use official git prompt, if it exists, or fall back to
# parse_git_branch:
if [ -f "$HOME/.git-prompt.sh" ]; then
GIT_PS1_SHOWCOLORHINTS=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUPSTREAM="auto verbose"
# shellcheck source=/home/brennen/.git-prompt.sh
. "$HOME/.git-prompt.sh"
else
# Emulate __git_ps1 interface which takes 2 params - before part
# and after part:
function __git_ps1 {
PS1="$1 $(parse_git_branch)$2"
}
fi
# Get some information about a git repo
function parse_git_branch {
# if [ ! -z "$has_git_prompt" ]; then
# __git_ps1
# return
# fi
# Formerly:
# ref=$(git symbolic-ref HEAD 2> /dev/null) || return
# echo "("${ref#refs/heads/}") "


+ 54
- 48
home/.zshrc View File

@ -1,46 +1,50 @@
# My zsh config file. One day, I may actually learn about zsh instead
# of just haphazardly tossing crap at it.
# Common path, aliases, functions, etc. for both zsh and bash:
source ~/.sh_common
# basic setup / options {{{
autoload -U add-zsh-hook
autoload -Uz compinit
# Common path, aliases, functions, etc. for both zsh and bash:
source ~/.sh_common
export HISTFILE=~/.histfile
export HISTSIZE=15000
export SAVEHIST=9999999
autoload -U add-zsh-hook
autoload -Uz compinit
# vi-style cycling through completions on repeated tab presses:
setopt menu_complete
export HISTFILE=~/.histfile
export HISTSIZE=15000
export SAVEHIST=9999999
# Allow arrow-key selection of completion items from a menu:
zstyle ':completion:*' menu select
# vi-style cycling through completions on repeated tab presses:
setopt menu_complete
# Auto-rehash so that when stuff is installed you can tab-complete it
# immediately (I have no idea what performance penalty this incurs):
zstyle ':completion:*' rehash true
# Allow arrow-key selection of completion items from a menu:
zstyle ':completion:*' menu select
setopt prompt_subst
setopt inc_append_history
setopt hist_ignore_space
setopt hist_ignore_dups
setopt autocd
setopt extendedglob
setopt autopushd pushdminus
setopt printexitvalue
unsetopt beep
bindkey -e
# Auto-rehash so that when stuff is installed you can tab-complete it
# immediately (I have no idea what performance penalty this incurs):
zstyle ':completion:*' rehash true
# Add completion for custom git commands I've written as shell scripts:
# https://stackoverflow.com/questions/38725102/how-to-add-custom-git-command-to-zsh-completion
zstyle ':completion:*:*:git:*' user-commands sel-changed:'select from changed files' \
edit-changed:'edit from selected changed files' \
do:'execute command from top of repo'
setopt prompt_subst
setopt inc_append_history
setopt hist_ignore_space
setopt hist_ignore_dups
setopt autocd
setopt extendedglob
setopt autopushd pushdminus
setopt printexitvalue
unsetopt beep
bindkey -e
zstyle :compinstall filename '/home/brennen/.zshrc'
# Add completion for custom git commands I've written as shell scripts:
# https://stackoverflow.com/questions/38725102/how-to-add-custom-git-command-to-zsh-completion
zstyle ':completion:*:*:git:*' user-commands sel-changed:'select from changed files' \
edit-changed:'edit from selected changed files' \
do:'execute command from top of repo'
compinit
zstyle :compinstall filename '/home/brennen/.zshrc'
compinit
# }}}
# keybindings {{{
@ -192,8 +196,7 @@ compinit
for c in `seq 0 256`; do
colortest="$colortest %K{$c} $c "
done
pr_meta="$colortest
"
pr_meta="$colortest "
}
# Reset the prompt on every command to get that parse_git_branch function to
@ -208,22 +211,23 @@ compinit
;;
esac
pr_time="$PR_TIME_COLOR%*$PR_NO_COLOR"
pr_userhost="$PR_HOST_COLOR%n@%m$PR_NO_COLOR"
pr_path="$PR_PATH_COLOR%~$PR_NO_COLOR"
# A conditional expression - if there're one or more background jobs,
# display [number of jobs]
# http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html
pr_jobs="%1(j.[%j] .)"
# Semi-traditional one-line prompt:
export PS1="$pr_meta$PR_TIME_COLOR%*$PR_NO_COLOR $PR_HOST_COLOR%n@%m$PR_NO_COLOR:$PR_PATH_COLOR%~$PR_NO_COLOR $PR_GIT_COLOR$(parse_git_branch)$PR_NO_COLOR$pr_jobs$PR_SIGIL_COLOR$PR_SIGIL$PR_NO_COLOR "
pr_sigil="$PR_SIGIL_COLOR$PR_SIGIL$PR_NO_COLOR"
# Multi-line with some notions thiefed from:
# https://lobste.rs/s/x5ioqm/what_does_your_shell_prompt_look_like
# export PS1="$pr_meta┌$PR_TIME_COLOR%*$PR_NO_COLOR $PR_HOST_COLOR%n@%m$PR_NO_COLOR:$PR_PATH_COLOR%~$PR_NO_COLOR $PR_GIT_COLOR$(parse_git_branch)$PR_NO_COLOR
#└$PR_SIGIL_COLOR$PR_SIGIL$PR_NO_COLOR "
# __git_ps1 takes 2 parameters: Stuff for before the git prompt and stuff
# for after. See .sh_common - if the git prompt is available, it'll use
# that; otherwise it's a fallback to the much simpler parse_git_branch
# defined there.
# Variant with host/path on second line:
#export PS1="$pr_meta┌$PR_TIME_COLOR%*$PR_NO_COLOR $PR_GIT_COLOR$(parse_git_branch)$PR_NO_COLOR
#└$PR_HOST_COLOR%n@%m$PR_NO_COLOR:$PR_PATH_COLOR%~$PR_NO_COLOR $PR_SIGIL_COLOR$PR_SIGIL$PR_NO_COLOR "
__git_ps1 "$pr_meta$pr_time $pr_userhost:$pr_path" " $pr_jobs$pr_sigil "
}
# This will reset the prompt every so often - it definitely shouldn't happen
@ -254,10 +258,12 @@ compinit
# }}}
# syntax highlighting: {{{
# https://github.com/zsh-users/zsh-syntax-highlighting
# Fish-style syntax highlighting - must be last thing sourced, install with:
# sudo apt-get install zsh-syntax-highlighting
ZSH_SYNTAX_HIGHLIGHTING_PATH=/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
[ -f "$ZSH_SYNTAX_HIGHLIGHTING_PATH" ] && source "$ZSH_SYNTAX_HIGHLIGHTING_PATH"
# syntax highlighting {{{
# https://github.com/zsh-users/zsh-syntax-highlighting
# Fish-style syntax highlighting - must be last thing sourced, install with:
# sudo apt-get install zsh-syntax-highlighting
ZSH_SYNTAX_HIGHLIGHTING_PATH=/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
[ -f "$ZSH_SYNTAX_HIGHLIGHTING_PATH" ] && source "$ZSH_SYNTAX_HIGHLIGHTING_PATH"
# }}}

Loading…
Cancel
Save