diff --git a/zsh/functions.zsh b/zsh/functions.zsh index 1b409bf..2dde17a 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -42,6 +42,34 @@ vfind() { } ### Others ### +pull-dotfiles() { + pushd > /dev/null 2>&1 + echo Pulling dotfiles... + cd ~/.config/dotfiles && git pull + echo Pulling scripts... + cd ~/.scripts && git pull + echo Pulling oh-my-zsh + cd ~/.config/oh-my-zsh && git pull + popd > /dev/null 2>&1 +} + +# Recover a vim backup +recover() { + if [ -f $1 ]; then + echo >&2 Cannot recover an existing file... + exit 1 + fi + + BACKUP_PATH=~/.vim/backups/`echo $PWD/$1 | tr '/' '%'` + + if [ ! -f "$BACKUP_PATH" ]; then + echo >&2 Backup not found... + exit 2 + fi + + cp $BACKUP_PATH $1 +} + # colors for the man pages man() { env LESS_TERMCAP_mb=$(printf "\e[1;31m") \ @@ -74,6 +102,30 @@ makelatex() { # cdg : cd to a git repo if [ -d "$GCLONE_PATH" ]; then + + gclone() { + # Check if cloning via HTTP(S) or SSH + if [[ $1 == http* ]]; then + server=`echo $1 | rev | cut -d '/' -f 3- | rev | cut -d '/' -f 3` + name=`echo $1 | rev | cut -d '/' -f -2 | rev` + else + server=`echo $1 | cut -d ':' -f 1 | cut -d '@' -f 2-` + name=`echo $1 | cut -d ':' -f 2-` + fi + + user=`echo $name | cut -d '/' -f 1` + repo=`echo $name | cut -d '/' -f 2-` + + if [[ $repo == *.git ]]; then + repo=${repo%.*} + fi + + # Final path to the repo + repo_path=$GCLONE_PATH/$server/$user/$repo + mkdir -p $repo_path + git clone $1 $repo_path + } + cdg() { if [ $# -ne 1 ]; then echo "This function expects a single parameter"