rc/functions
lhark 83f91a5034 [zshrc] Switch to builtin vcs_info for the git prompt. Move aliases and prompt to new file
Instead of using hand crafted parsing to get the current git state, we
use the existing vcs_info module, augmented by a few hooks to preserve
previous prompt functionality.

The prompt now also display the vi mode of ZLE on the left of the
username : [I] for insert mode, [N] for normal mode.

A lot of the inspiration for this refactor came from
https://github.com/frioux/dotfiles
For example the tweaks to the keybindings and completion.
2018-02-26 03:18:40 -05:00

87 lines
2.8 KiB
Bash
Executable file

################################################################################
# Debugging #
################################################################################
# Global counter that can be used to diagnose duplicated calls
printf "0" > /dev/shm/debug_counter
debug_counter_inc() {
count="$(cat /dev/shm/debug_counter)"
((count++))
printf "%d" "$count" > /dev/shm/debug_counter
}
debug_counter_print(){
printf "%d" "$(cat /dev/shm/debug_counter)"
}
################################################################################
# Update checking #
################################################################################
check_rc_update () {
# Get rc dir path
RC_PATH=$(dirname "$(readlink -f ${(%):-%x})")
CUR_DIR=`pwd`
cd $RC_PATH
# In case the network is down, don't lock the terminal
timeout 6 git fetch > /dev/null 2>&1
#
# Timeout returns 124 on timeout
if [ "$?" -ge "124" ]; then
echo 'git_network_unreachable' >> /dev/shm/prompt_msg
fi
# Check if the repo is clean
git_st=$(command git status --porcelain -b 2> /dev/null)
if $(echo "$git_st" | grep '^## .*ahead' &> /dev/null); then
echo 'git_unpushed' >> /dev/shm/prompt_msg
elif $(echo "$git_st" | grep '^## .*behind' &> /dev/null); then
echo 'update_rc' >> /dev/shm/prompt_msg
fi
cd $CUR_DIR
}
check_sys_update () {
case $(lsb_release -i | awk -F ':\t' '/Distributor ID/{print $2}') in
Arch)
nb_maj=$(checkupdates | wc -l);;
Debian|Ubuntu)
nb_maj=$(aptitude search '~U' | wc -l);;
VoidLinux)
nb_maj=$(xbps-install -Sun | wc -l);;
esac
if [ $nb_maj -gt 0 ]; then
echo "update_sys $nb_maj" >> /dev/shm/prompt_msg
fi
}
################################################################################
# Commands #
################################################################################
# Do the update
uprc () {
RC_PATH=$(dirname "$(readlink -f ${(%):-%x})")
cd $RC_PATH
git pull --rebase --stat origin master
$RC_PATH/install.sh
cd - &> /dev/null
source $HOME/.zshrc
}
# Syntax coloration for man
man() {
env \
LESS_TERMCAP_mb="$(printf "%s" "$fg_bold[red]")" \
LESS_TERMCAP_md="$(printf "%s" "$fg_bold[red]")" \
LESS_TERMCAP_me="$(printf "%s" "$reset_color")" \
LESS_TERMCAP_se="$(printf "%s" "$reset_color")" \
LESS_TERMCAP_so="$(printf "%s" "$bg[black]$fg[yellow]")" \
LESS_TERMCAP_ue="$(printf "%s" "$reset_color")" \
LESS_TERMCAP_us="$(printf "%s" "$fg_bold[blue]")" \
man "$@"
}
# vim: ft=zsh