2016-10-11 00:27:28 +00:00
|
|
|
################################################################################
|
2018-02-26 08:18:40 +00:00
|
|
|
# Debugging #
|
2016-10-11 00:27:28 +00:00
|
|
|
################################################################################
|
|
|
|
|
2018-02-26 08:18:40 +00:00
|
|
|
# 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
|
2016-10-11 00:27:28 +00:00
|
|
|
}
|
2018-02-26 08:18:40 +00:00
|
|
|
debug_counter_print(){
|
|
|
|
printf "%d" "$(cat /dev/shm/debug_counter)"
|
2016-10-11 00:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
2016-10-27 07:51:43 +00:00
|
|
|
# Update checking #
|
2016-10-11 00:27:28 +00:00
|
|
|
################################################################################
|
2016-10-11 01:54:42 +00:00
|
|
|
|
|
|
|
check_rc_update () {
|
2016-10-11 00:27:28 +00:00
|
|
|
# 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
|
2016-10-11 01:54:42 +00:00
|
|
|
echo 'git_network_unreachable' >> /dev/shm/prompt_msg
|
2016-10-11 00:27:28 +00:00
|
|
|
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
|
2016-10-11 01:54:42 +00:00
|
|
|
echo 'git_unpushed' >> /dev/shm/prompt_msg
|
2016-10-11 00:27:28 +00:00
|
|
|
elif $(echo "$git_st" | grep '^## .*behind' &> /dev/null); then
|
2016-10-11 01:54:42 +00:00
|
|
|
echo 'update_rc' >> /dev/shm/prompt_msg
|
2016-10-11 00:27:28 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd $CUR_DIR
|
|
|
|
}
|
|
|
|
|
2016-10-11 01:54:42 +00:00
|
|
|
check_sys_update () {
|
2017-09-09 05:58:50 +00:00
|
|
|
case $(lsb_release -i | awk -F ':\t' '/Distributor ID/{print $2}') in
|
2016-10-11 01:54:42 +00:00
|
|
|
Arch)
|
|
|
|
nb_maj=$(checkupdates | wc -l);;
|
|
|
|
Debian|Ubuntu)
|
|
|
|
nb_maj=$(aptitude search '~U' | wc -l);;
|
2017-09-09 05:58:50 +00:00
|
|
|
VoidLinux)
|
|
|
|
nb_maj=$(xbps-install -Sun | wc -l);;
|
2016-10-11 01:54:42 +00:00
|
|
|
esac
|
|
|
|
if [ $nb_maj -gt 0 ]; then
|
|
|
|
echo "update_sys $nb_maj" >> /dev/shm/prompt_msg
|
|
|
|
fi
|
|
|
|
}
|
2016-10-27 07:51:43 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# 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 "$@"
|
|
|
|
}
|
|
|
|
|
2018-05-17 13:35:59 +00:00
|
|
|
# Youtube audio search
|
|
|
|
ymsearch() {
|
|
|
|
mpv --ytdl-format=bestaudio ytdl://ytsearch:"$@"
|
|
|
|
}
|
|
|
|
|
2018-02-26 08:18:40 +00:00
|
|
|
# vim: ft=zsh
|